Block Swap
Block swap text rewrite for Remotion: solid blocks wipe over each word and morph into the next line, rewriting one statement into another and ending on a highlighted pill word.
In Remotion, Block Swap rewrites one statement into another: a solid block wipes over each word, morphs into the shape of the next line's words and uncovers the new text, finishing with one highlighted word on a gradient pill. Use it for a beat where a problem line is replaced by the answer.
$ pnpm dlx shadcn@latest add @remocn/block-swapHow to build this in Remotion
You don't need to build this from clip-path wipes and measureText. Install the component and pass your lines:
npx shadcn@latest add @remocn/block-swapWords are measured on a canvas before the first frame (held with delayRender), then each block covers, morphs and wipes with interpolate() on Easing.bezier curves; colors cross with interpolateColors(). The swaps are scheduled per line in timeline.ts.
Good to know
- Length: 120 frames of motion at 30 fps (240 at 60 fps) with the default props; the demo plays 150 frames, which adds a hold. The length grows with the number of lines and words and with
hold, the frames between swaps. The Usage example below is a 60 fps composition, so the numbers it hands to Remotion are doubled, see Frame rate. - Installs:
remotion,@remotion/google-fontsfrom npm, plus the remocn helpersglide,frame-rate,timeline. The shadcn CLI copies the source into your project. - Font: loads Space Grotesk itself through
@remotion/google-fonts. PassfontFamilyto use your own face, and load that font in your project. highlightmust match a whole word of the last line. The match ignores case and trailing punctuation; if nothing matches, there is no pill.- The pill gradient runs from
accent(default#3B5BFD) through#2F7BFFto#FF7A3D. Onlyaccentis a prop; the other stops are constants in the copied file.
Usage
// src/Root.tsx
import { Composition } from "remotion";
import { BlockSwap } from "@/components/remocn/block-swap";
const BlockSwapScene = () => (
<BlockSwap
lines={["Pick the beats you need.", "Render the launch."]}
highlight="launch"
accent="#3B5BFD"
/>
);
export const RemotionRoot = () => (
<Composition
id="BlockSwap"
component={BlockSwapScene}
durationInFrames={300}
fps={60}
width={1280}
height={720}
/>
);Each word of the first line is covered by a block that morphs into the next line, then uncovers the new words. The last line keeps highlight on a gradient pill. Pass lines as an array of sentences and highlight as the word to call out; it ships light and dark through theme.
Props12
| Prop | Type | Default |
|---|---|---|
| lines | string[]DEFAULT_LINES Sentences shown in order; each one overwrites the previous | |
| highlight | string"launch" Word in the last line that lands on the gradient pill | |
| accent | string"#3B5BFD" Accent color (any valid CSS color) | |
| ink | string— Text and block color; overrides the theme ink. | |
| background | string— Overrides the theme's stage color | |
| fontFamily | string"Space Grotesk" Typeface for the copy. Space Grotesk loads by default; load any other face in your project first. | |
| hold | number14 Frames each line holds before the blocks cover it. | |
| radius | number0.2 Corner radius of the blocks, in em of the line size. | |
| 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. | |
| speed | number1 Playback speed multiplier | |
| theme | "dark" | "light""dark" Ships light and dark palettes | |
- linesstring[]
Sentences shown in order; each one overwrites the previous
Default
DEFAULT_LINES - highlightstring
Word in the last line that lands on the gradient pill
Default
"launch" - accentstring
Accent color (any valid CSS color)
Default
"#3B5BFD" - inkstring
Text and block color; overrides the theme ink.
- backgroundstring
Overrides the theme's stage color
- fontFamilystring
Typeface for the copy. Space Grotesk loads by default; load any other face in your project first.
Default
"Space Grotesk" - holdnumber
Frames each line holds before the blocks cover it.
Default
14 - radiusnumber
Corner radius of the blocks, in em of the line size.
Default
0.2 - scalenumber
Size of the foreground around the frame's center; the background stays put.
Default
1 - delaynumber
Frames to hold the first frame before anything moves.
Default
0 - speednumber
Playback speed multiplier
Default
1 - theme"dark" | "light"
Ships light and dark palettes
Default
"dark"
Common questions
How can I rewrite one statement into another in Remotion by wiping a solid block over each line?
Install Block Swap with npx shadcn@latest add @remocn/block-swap, pass lines as an array of sentences and highlight as the word on the last line to put on the pill.
Does highlight need to match exactly?
It must be a whole word of the last line; case and trailing punctuation are ignored.
Related effects
- Mask Reveal Up: a single line revealed from a mask.
- Rewrite Bars: bars sweep across a headline and rewrite it.
- Strikethrough Replace: a line struck through and replaced.
- Select Replace: an editor-style selection replaced with new words.