Text Morph
text-morphA short label that morphs into the next in place: shared letters glide, new ones sharpen in, removed ones blur away, and the width follows on a spring so the layout around it never jumps. Letters are split as a reader sees them, so emoji and accents move whole.
"use client";
import { useEffect, useState } from "react";
import { Button } from "@/components/forme/button/button";
import { TextMorph } from "@/components/forme/text-morph/text-morph";
type Stage = "idle" | "working" | "done";
const publishLabel = { idle: "Publish", working: "Publishing", done: "Published" } as const;
export function TextMorphDemo() {
const [stage, setStage] = useState<Stage>("idle");
const [following, setFollowing] = useState(false);
// A stand-in for the request: working for a moment, then done, then ready
// to go again so the demo can be replayed.
useEffect(() => {
if (stage === "idle") return;
const next = window.setTimeout(
() => setStage(stage === "working" ? "done" : "idle"),
stage === "working" ? 1400 : 2000,
);
return () => window.clearTimeout(next);
}, [stage]);
return (
<div className="flex flex-col items-start gap-6">
<div className="flex flex-wrap items-center gap-3">
<Button
aria-busy={stage === "working" || undefined}
onClick={() => stage === "idle" && setStage("working")}
>
<TextMorph>{publishLabel[stage]}</TextMorph>
</Button>
<Button
variant="secondary"
aria-pressed={following}
onClick={() => setFollowing((value) => !value)}
>
<TextMorph>{following ? "Following" : "Follow"}</TextMorph>
</Button>
</div>
<p className="text-body-regular text-muted-foreground">
Status:{" "}
<TextMorph aria-live="polite" className="text-foreground">
{stage === "idle" ? "Draft" : stage === "working" ? "Uploading" : "Live"}
</TextMorph>
</p>
</div>
);
}Install
Adds the component, its registry dependencies, and the token stylesheet you import once.
Usage
import { TextMorph } from "@/components/forme/text-morph/text-morph";
<Button onClick={publish}>
<TextMorph>{publishing ? "Publishing" : "Publish"}</TextMorph>
</Button>When to use
Reach for it
- A status word or button label that changes a few letters at a time: Publish, Publishing, Published; Follow, Following.
Use something else
- Sentences or labels that wrap: it stays on one line, and a long morph is motion people wait for.
- Numbers that tick;
NumberFlowrolls digits in place instead.
API reference
Read from the source, so it is the API of the file you install. A prop marked * is required.
TextMorph
Morphs one short label into the next in place.
| Prop | Type | Default | Description |
|---|---|---|---|
children* | string | — | Plain text: a short label. It stays on one line. |
as | "span" | "div" | "p" | "strong" | "h1" | "h2" | "h3" | "span" | The element to render. |
Also takes every prop of Omit<HTMLAttributes<HTMLElement>, "children">.
Accessibility
- The plain text is in the accessibility tree and the animated letters are hidden from it.
- Pass
aria-live="polite"when the change itself should be announced, as for a save status.
Motion
- Shared letters glide on
spring.snappy; new letters fade, rise and sharpen in over 200ms, 30ms apart and capped at six; leaving letters clear in 150ms on the exit curve. - Reduced motion swaps the label and the width on the frame.
Responsive behaviour
- A web font arriving or a responsive font size resizes the frame directly, without replaying a morph.
Related


Confirm Button
A destructive button that grows into its own confirmation on a spring, so the question appears where you are looking. Focus lands on Cancel, Esc or clicking away disarms it, and the confirm button shows a spinner while the action runs.
motion

Dynamic Island
A black pill that morphs on a spring to fit whatever it is showing: a timer, a call, a song or a notification. Content swaps through a short blur crossfade, the corners never stretch mid-morph, and each change is announced politely.
motion

Marquee
A seamless, endlessly scrolling row for logos, photos or testimonials. It pauses on hover and focus, screen readers hear the content once, and reduced motion turns it into a row you scroll by hand. Pure CSS.
motion