Caret Swap

Gradient text cursor swells into a block that eats the current phrase, shrinks back and types a new one. A typewriter replace effect for editor and AI-tool videos. A free, MIT-licensed Remotion text animation.

In Remotion, Caret Swap animates a gradient text cursor that swells into a block, eats the existing phrase, shrinks back to a caret and then types a different phrase. Use it to replace one line with another mid-scene in editor, dev-tool or AI-product videos, without cutting to an empty frame.

Installation
$ pnpm dlx shadcn@latest add @remocn/caret-swap

How to build this in Remotion

You don't need a string-slicing typewriter plus a separate cursor. Install the component and pass both phrases:

bash
npx shadcn@latest add @remocn/caret-swap

It is one component driven by the schedule in timeline.ts: the caret stretches and collapses with interpolate() over Easing curves, then the new phrase types out with a slightly accelerating rhythm. No @remotion/layout-utils or TransitionSeries is involved.

Good to know

  • Length: 67 frames of motion at 30 fps (134 at 60 fps) with the default props. The demo composition plays 100 frames, which adds a hold. The typing part depends on the length of toText: each next character comes a little sooner than the last. The Usage example below is a 60 fps composition, so the numbers it hands to Remotion are doubled, see Frame rate.
  • Installs: remotion from npm, plus the remocn helpers frame-rate, timeline. The shadcn CLI copies the source into your project.
  • Timings are counted on a 30 fps scene clock through the remocn frame-rate helper, so the swap takes the same number of seconds at 30 or 60 fps. swapAt and typeSpeed are in 30 fps frames.
  • Font: Geist Sans through the --font-geist-sans CSS variable with a system sans fallback, set inline. There is no fontFamily prop: change the font in the copied file (a className font does not override an inline style).
  • Colors are props: color (default #171717) for the text, and caretColor (#FF4DAA) to caretColorEnd (#8A5CF6) for the caret gradient. On a dark background, pass a light color.

Usage

The first text sits still until swapAt. Seven frames earlier the caret pops in after the last character; at swapAt it swells leftward into a full block with a sharp acceleration, consuming the text right to left in six frames. The block then dissolves its gradient tail to the right — the left edge holds still and what remains is the caret line at the start of the row. After a beat it types the second text — typeSpeed frames for the first character with every following gap shrinking, one accelerando to the finish — growing rightward from the anchor while drifting left to end centered. After the last character the caret blinks. All timings measured frame-by-frame from the reference footage.

tsx
// src/Root.tsx
import { Composition } from "remotion";
import { CaretSwap } from "@/components/remocn/caret-swap";
 
const CaretSwapScene = () => (
  <CaretSwap
    fromText="Executing it?"
    toText="That's where everyone quits"
  />
);
 
export const RemotionRoot = () => (
  <Composition
    id="CaretSwap"
    component={CaretSwapScene}
    durationInFrames={200}
    fps={60}
    width={1280}
    height={720}
  />
);

With Backdrop

The component renders transparent — supply the background via Backdrop. It ships single-theme; edit the copied file to re-theme colors.

tsx
import { Composition } from "remotion";
import { CaretSwap } from "@/components/remocn/caret-swap";
import { Backdrop } from "@/components/remocn/backdrop";
 
const CaretSwapScene = () => (
  <Backdrop fill={{ type: "color", value: "#fdf6f0" }}>
    <CaretSwap
      fromText="Executing it?"
      toText="That's where everyone quits"
    />
  </Backdrop>
);
 
export const RemotionRoot = () => (
  <Composition
    id="CaretSwap"
    component={CaretSwapScene}
    durationInFrames={200}
    fps={60}
    width={1280}
    height={720}
  />
);

Syncing

The exported caretSwapLength(toText, swapAt, typeSpeed) helper returns the frame on which the last character lands — use it as the lower bound of the Sequence, plus whatever hold you want for the blinking caret.

Props10

PropTypeDefault
fromTextrequired
string—

The phrase shown first and consumed by the caret block

toTextrequired
string—

The phrase typed out after the swap

fontSize
number72

Font size in pixels; caret and block scale with it

swapAt
number20

Frame at which the caret starts expanding into the block; the caret itself appears seven frames earlier

typeSpeed
number1

Frames for the first typed character; every next gap shrinks by a fixed ratio so the typing accelerates toward the end

color
string"#171717"

Text color (any valid CSS color)

caretColor
string"#FF4DAA"

Top color of the caret gradient

caretColorEnd
string"#8A5CF6"

Bottom color of the caret gradient

fontWeight
number400

CSS font-weight

className
string—

Optional className passed to the underlying span

  • fromTextrequiredstring

    The phrase shown first and consumed by the caret block

  • toTextrequiredstring

    The phrase typed out after the swap

  • fontSizenumber

    Font size in pixels; caret and block scale with it

    Default72

  • swapAtnumber

    Frame at which the caret starts expanding into the block; the caret itself appears seven frames earlier

    Default20

  • typeSpeednumber

    Frames for the first typed character; every next gap shrinks by a fixed ratio so the typing accelerates toward the end

    Default1

  • colorstring

    Text color (any valid CSS color)

    Default"#171717"

  • caretColorstring

    Top color of the caret gradient

    Default"#FF4DAA"

  • caretColorEndstring

    Bottom color of the caret gradient

    Default"#8A5CF6"

  • fontWeightnumber

    CSS font-weight

    Default400

  • classNamestring

    Optional className passed to the underlying span

Common questions

How do I animate a gradient cursor that eats a phrase and types a new one?

Install Caret Swap with npx shadcn@latest add @remocn/caret-swap and pass fromText and toText. The caret grows over the first phrase at swapAt, collapses and types the second.

Does the timing change with the frame rate?

No. The component counts on a 30 fps clock, so at 60 fps it lasts the same time; double only the numbers you hand to Remotion, such as durationInFrames.

Can I change the font?

Not through a prop. The font is set inline in the copied file, so edit it there.