Swapping Text

Only the letters that changed glide to their new spots.

swapping-text.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/swapping-text.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/swapping-text.json

3

Turn on the motion

npx @prequelui/cli@latest animate swapping-text

The CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

swapping-text.tsx
import { SwappingText } from "@/components/prequelui/swapping-text";

export default function Demo() {
  return (
    <SwappingText
      text={["handcrafted", "handwritten", "handtuned"]}
      duration={2000}
      direction="up"
      className="text-4xl font-medium"
    />
  );
}
import { SwappingText } from "@/components/prequelui/swapping-text";

export function Variant() {
  return (
    <SwappingText tempo={1.2}>
      …
    </SwappingText>
  );
}

Animation

Only the characters that differ move. Unchanged slots stay still, changed slots lift their old glyph out while the new one rises into place, and the slot width glides from the measured old advance to the measured new one.

  • Character tween: 200 ms with a fill curve.
  • Stagger: 40 ms between changed slots.
  • Old glyph exits with a 2 px blur and 0.5 em of travel; the new glyph mirrors it.
  • Reduced motion changes the string without slot animation.
200 ms fillstagger 40 msblur 2 pxwidth glide

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

SwappingText

PropTypeDefault
textstring | string[]—
durationnumber2000
delaynumber0
direction"up" | "down""up"
staggernumber0.04

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026