Width Lock

Rotating word in a fixed-width line for Remotion: one slot in a claim swaps through a list such as trailer, captions, launch video while the sentence keeps the same width.

To make one slot in a sentence swap through a list of words while the line stays the same width in Remotion, use Width Lock: a claim such as "Ship the trailer by tonight." cycles its middle word through trailer, captions, launch video, and the line never grows, shrinks or reflows. Each word is condensed or widened on a variable font's width axis so the whole sentence keeps one measure. Use it for a claim with one slot that cycles through deliverables or use cases.

Installation
$ pnpm dlx shadcn@latest add @remocn/width-lock

How to build this in Remotion

You don't have to measure every word with measureText or fitText from @remotion/layout-utils and juggle font sizes so the layout doesn't jump. Install the component and pass the text around the slot plus the words it cycles through:

bash
npx shadcn@latest add @remocn/width-lock

Before the first frame (held with delayRender) it measures every word at several settings of the font's wdth (width) axis. For each word it then solves the width setting that makes the whole line match one fixed measure, so a long word is condensed and a short one is widened; a word too short even at the widest setting gets extra letter spacing. The schedule in timeline.ts gives each word its start frame, and hold sets how long each one stays.

Good to know

  • Length: 143 frames of motion at 30 fps (286 at 60 fps) with the default props. That is the minimum for its Sequence; add your own hold on top. The Usage example below is a 60 fps composition, so the numbers it hands to Remotion (durationInFrames, Sequence lengths) are doubled. The component's own props counted in frames stay in 30 fps frames at any frame rate, see Frame rate.
  • Installs: remotion, @remotion/google-fonts from npm, plus the remocn helpers glide, frame-rate, timeline. The shadcn CLI copies the source into your project.
  • Font: loads Roboto Flex itself through @remotion/google-fonts. Pass fontFamily to use your own face, and load that font in your project.
  • The swap keeps the line width, not the font size: fontFamily needs a variable font with a width (wdth) axis, like the default Roboto Flex. A face without that axis has nothing to condense or widen.

Usage

tsx
// src/Root.tsx
import { Composition } from "remotion";
import { WidthLock } from "@/components/remocn/width-lock";
 
const WidthLockScene = () => (
  <WidthLock before="Ship the" words={["trailer", "captions", "launch video"]} after="by tonight." />
);
 
export const RemotionRoot = () => (
  <Composition
    id="WidthLock"
    component={WidthLockScene}
    durationInFrames={340}
    fps={60}
    width={1280}
    height={720}
  />
);

The line holds a constant width while the middle word swaps through each entry in words. Pass before, words and after, and set hold for how long each word stays. It ships in light and dark through the theme prop.

Props14

PropTypeDefault
before
string"Ship the"

Text before the swapping word.

words
string[]—

Words swapped in order.

after
string"by tonight."

Text after the swapping word.

hold
number30

Frames each state stays on screen before the next one.

fontWeight
number480

Weight of the lines on the variable weight axis.

accent
string"#3B5BFD"

Accent color override; falls back to the theme accent.

ink
string—

Text color; overrides the theme ink.

background
string—

Background color override; falls back to the theme background.

fontFamily
string"Roboto Flex"

Typeface for the copy. Load the font in your project first.

scale
number1

Size of the foreground around the frame's center; the background stays put.

delay
number0

Frames to hold the first frame before anything moves.

grain
booleantrue

Film grain over the scene.

speed
number1

Playback speed multiplier for the whole timeline.

theme
"dark" | "light""dark"

Ships light and dark; picks the palette.

  • beforestring

    Text before the swapping word.

    Default"Ship the"

  • wordsstring[]

    Words swapped in order.

  • afterstring

    Text after the swapping word.

    Default"by tonight."

  • holdnumber

    Frames each state stays on screen before the next one.

    Default30

  • fontWeightnumber

    Weight of the lines on the variable weight axis.

    Default480

  • accentstring

    Accent color override; falls back to the theme accent.

    Default"#3B5BFD"

  • inkstring

    Text color; overrides the theme ink.

  • backgroundstring

    Background color override; falls back to the theme background.

  • fontFamilystring

    Typeface for the copy. Load the font in your project first.

    Default"Roboto Flex"

  • scalenumber

    Size of the foreground around the frame's center; the background stays put.

    Default1

  • delaynumber

    Frames to hold the first frame before anything moves.

    Default0

  • grainboolean

    Film grain over the scene.

    Defaulttrue

  • speednumber

    Playback speed multiplier for the whole timeline.

    Default1

  • theme"dark" | "light"

    Ships light and dark; picks the palette.

    Default"dark"

Common questions

How do I swap one word in a sentence without the line changing width?

Install Width Lock with npx shadcn@latest add @remocn/width-lock, pass before, words and after, and the slot cycles through words while the line keeps one width. The words are fitted on the font's width axis, so nothing around the slot moves.

Can I use my own font?

Yes, if it is a variable font with a wdth axis. Load it in your project and pass its name as fontFamily.

How long does each word stay?

hold frames each, 30 at 30 fps by default (60 at 60 fps). With the four default words the motion runs 143 frames at 30 fps.

  • Ruby Press: the swapped word is pressed in with annotations.
  • Pinned Word: one word stays put while the rest of the line swaps.
  • Inline Word Roll: a word rolls through options after a fixed lead, without the width lock.
  • Word Ladder: one word changes a letter or two per step.