SkillsMar 29, 2026·1 min read

Remotion Rule: Measuring Dom Nodes

Remotion skill rule: Measuring DOM element dimensions in Remotion. Part of the official Remotion Agent Skill for programmatic video in React.

TL;DR
Use useCurrentScale() to get accurate DOM measurements in Remotion, compensating for the scale transform.
§01

What it is

This is a Remotion skill rule that teaches AI coding assistants how to correctly measure DOM element dimensions inside Remotion video projects. Remotion applies a scale() CSS transform to the video container, which means raw getBoundingClientRect() values are inaccurate unless you divide by the current scale factor.

This rule is part of the official Remotion Agent Skill collection, designed for developers using Claude Code, Cursor, or OpenAI Codex to build programmatic videos in React.

§02

How it saves time or tokens

Without this rule, an AI assistant will generate measurement code that uses getBoundingClientRect() directly, producing incorrect dimensions. Developers then spend time debugging why layout calculations are off by a fractional multiplier. The rule injects the correct pattern (dividing by useCurrentScale()) into the assistant's context automatically, eliminating a common source of visual bugs in Remotion projects.

§03

How to use

  1. Install the Remotion skills collection:
npx skills add remotion-dev/skills
  1. The rule activates automatically when your AI assistant detects DOM measurement work in a Remotion project.
  1. When you need element dimensions, the assistant will generate code using useCurrentScale() to compensate for the container transform.
§04

Example

import { useCurrentScale } from 'remotion';
import { useRef, useEffect, useState } from 'react';

export const MeasuredComponent = () => {
  const ref = useRef<HTMLDivElement>(null);
  const scale = useCurrentScale();
  const [dimensions, setDimensions] = useState({ width: 0, height: 0 });

  useEffect(() => {
    if (!ref.current) return;
    const rect = ref.current.getBoundingClientRect();
    setDimensions({
      width: rect.width / scale,
      height: rect.height / scale,
    });
  }, [scale]);

  return (
    <div ref={ref}>
      <p>Width: {dimensions.width}px</p>
      <p>Height: {dimensions.height}px</p>
    </div>
  );
};
§05

Related on TokRepo

This tool integrates with standard development workflows and requires minimal configuration to get started. It is available as open-source software with documentation and community support through the official repository. The project follows semantic versioning for stable releases.

For teams evaluating this tool, the key advantage is reducing manual work in repetitive tasks. The automation provided by the built-in features means less custom code to maintain and fewer integration points to manage. This translates directly to lower maintenance costs and faster iteration cycles.

§06

Common pitfalls

  • Forgetting to divide by the scale factor is the most common mistake; raw getBoundingClientRect() values will be scaled proportionally to the video container size.
  • The scale value changes when the preview window is resized, so always read it reactively via the useCurrentScale() hook rather than caching a static value.
  • This rule only applies to Remotion projects; in standard React apps without a scale transform, getBoundingClientRect() works as expected without correction.

Frequently Asked Questions

Why are my getBoundingClientRect values wrong in Remotion?+

Remotion applies a scale() CSS transform to the video container to fit it into the preview window. This transform affects all values returned by getBoundingClientRect(), making them proportionally larger or smaller than the actual composition dimensions. Divide by useCurrentScale() to get correct values.

What is useCurrentScale in Remotion?+

useCurrentScale() is a Remotion hook that returns the current scale factor applied to the video container. When the preview is at 50% zoom, it returns 0.5. Use this value to convert browser-reported dimensions back to composition-space coordinates.

Do I need to install anything extra for this rule?+

Run npx skills add remotion-dev/skills to install the full Remotion skill collection. The measuring DOM nodes rule activates automatically when your AI assistant detects relevant code patterns in a Remotion project.

Does this affect Remotion rendering output?+

During final rendering (not preview), the scale is 1:1, so getBoundingClientRect returns accurate values. The correction via useCurrentScale() is still safe to use because the hook returns 1.0 during rendering, making the division a no-op.

Which AI coding tools support this rule?+

The Remotion Agent Skill works with Claude Code, OpenAI Codex, and Cursor. Any tool that supports the skills protocol can load and activate these rules automatically during coding sessions.

Citations (3)
🙏

Source & Thanks

Created by Remotion. Licensed under MIT. remotion-dev/skills — Rule: measuring-dom-nodes

Part of the Remotion AI Skill collection on TokRepo.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets