Text Morph
Text Morph
Animate changing text with shared letters that move into place, soft arrivals, and a smoothly resizing width.
Dependencies
Interaction states
- Shared letters — Matching glyphs move between their previous and new positions.
- New and leaving letters — New characters enter; removed characters blur and fade away.
- Unrelated labels — Labels with little overlap transition as whole groups.
- Reduced motion — Text updates immediately without spatial animation.
Installation
Add this component with your preferred package manager.
pnpm dlx shadcn@4.21.5 add @cavemio/text-morphFirst install? Configure @cavemio once
Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.
{
"registries": {
"@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
}
}Where it’s used
Button labels
Move between Save, Saving and Saved in the same button.
Hero headlines
Change one word while keeping the rest of a sentence anchored.
Status labels
Let a badge explain a change without a sudden text swap.
Plan names
Update a selected plan or billing label in place.
What it handles
- Shared letters keep their place — Matching characters stay mounted and move to their next position.
- A soft entrance and exit — New letters arrive with a short stagger; outgoing characters lift and fade.
- The width follows the words — The surrounding inline box resizes as the label changes.
- Readable without motion — A real text layer remains available, with a static reduced-motion presentation.
Usage
Demo values are local; no network requests.
import { TextMorph } from "@/components/text-morph";
<TextMorph>{saved ? "Saved" : "Save"}</TextMorph>Props
| Prop | Type | Description |
|---|---|---|
| children | string | The current label. Change it to start a morph. |
| duration | number · 460 | Duration in milliseconds. |
| direction | "up" | "down" | The direction new characters enter from. Defaults to up. |
| animateWidth | boolean · true | Animate the inline width; disable for multi-line text. |
Accessibility & motion
The readable text stays available to assistive technology while decorative glyphs are hidden. Reduced motion swaps the label in place and clears outgoing glyphs. Use animateWidth={false} for wrapping text.
pnpm dlx shadcn@4.21.5 add @cavemio/text-morph