Skip to content

Components

Morph Text

Text that morphs from the old value to the new one when it changes.

Animates a label when its text changes. Characters the old and new text share slide to their new place, and the rest fade. Built on torph.

Click the button to step through a transaction’s labels.

Terminal window
npx shadcn@latest add @0xui/morph-text
import { MorphText } from "@/components/morph-text";
<Button>
<MorphText>{isPending ? "Pending…" : "Send"}</MorphText>
</Button>;

Keep one MorphText mounted and change its text. Swapping between two MorphText elements replaces the label without a morph.

Digits roll by place value, so only the places that changed move. Use tabular-nums on the parent to stop the width from shifting.

21,345,678
<span className="tabular-nums">
<MorphText>{blockNumber.toLocaleString()}</MorphText>
</span>
Component What morphs
Transaction Button, Batch Transaction, Sign Message, Add Token The button label, across phases. This covers Approve Button, Send and Swap too.
Contract Form “Read” and “Reading…”.
Chain Selector The current chain’s name.
Block Number, Gas Price The live value.
Balance, Token Input The balance and the fiat value.
Swap, Portfolio The rate, price impact and total value.

Token Amount only morphs with animate, so long lists don’t pay for it.

Case What happens
Text and numbers, alone or mixed like Approve {symbol} Joined into one label and morphed.
Children that hold an element Rendered as-is, with no animation.
Screen readers Read the plain text once. The animated characters are hidden from them.
prefers-reduced-motion The text changes without animating.
No Web Animations API, as in jsdom Plain text in a span, so tests can query the label.

The text never wraps: torph sets white-space: nowrap. Use it for short labels and values, not sentences.

torph adds one <style> element to the page. Under a strict Content Security Policy, allow it or set disabled.

Also accepts torph’s options, such as ease, scale, numbers, decimals, locale and onAnimationComplete.

Prop Type Default Description
children ReactNode — Text to show.
duration number 400 Length of the morph, in ms.
disabled boolean false Change the text without animating.
className string — Class for the wrapping span.