When to use
- A number that updates while someone watches: a balance, a price, a live counter, a total that changes as items are added.
- Figures in a stat tile or a dashboard, where a roll shows which way the value moved.
- Any number that needs locale-aware formatting (currency, percent, compact, units) and should animate between values.
When not to use
- A number that never changes after render: plain text is enough.
- A value someone edits: use a Number Field.
- Text that changes, not a number: use Text Swap.
Installation
pnpm dlx shadcn add https://eased.dev/r/number-roll.jsonnpx shadcn add https://eased.dev/r/number-roll.jsonyarn dlx shadcn add https://eased.dev/r/number-roll.jsonbunx --bun shadcn add https://eased.dev/r/number-roll.jsonThe command adds Number Roll, everything it builds on and Eased’s tokens to your project.
Add the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/number-roll/number-roll.tsxTSX "use client";/** * Number Roll: tabular digits that roll in the direction of change, with locale-aware * separators. The engine is the shared `_primitives/number-roll` primitive that Badge, * Progress and the other Eased components roll their numbers with; this entry point is * the public import. * * <NumberRoll value={48210.4} format={{ style: "currency", currency: "USD" }} /> */export { NumberRoll, toRollParts, type NumberRollFormat, type NumberRollProps, type RollDirection, type RollPart,} from "../_primitives/number-roll/number-roll";Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { NumberRoll } from "@/components/eased/number-roll/number-roll";export function Balance({ amount }: { amount: number }) { return ( <p className="text-display-3xl font-semibold"> <NumberRoll value={amount} format={{ style: "currency", currency: "USD" }} /> </p> );}Examples
Other locales
Grouping, the decimal mark and the numerals come from the locale, and localised numerals roll too.
<NumberRoll value={139775.9} locale="hi-IN" format={{ style: "currency", currency: "INR" }} /><NumberRoll value={48210} locale="ar-EG" />Compact and percent
Suffixes and symbols swap while the digits roll, so 980K to 1.2M changes the "K" to an "M".
<NumberRoll value={followers} format={{ notation: "compact", maximumFractionDigits: 1 }} /><NumberRoll value={0.42} format={{ style: "percent" }} />While dragging
Turn the animation off while a slider or a scrub drives the value, so it follows the pointer exactly. The width then changes at once too; otherwise it springs with the digits, so text beside the number glides when it gains or loses a digit.
<NumberRoll value={volume} animated={!dragging} />API reference
NumberRoll
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | The number. | |
locale | Intl.LocalesArgument | runtime locale | Grouping, decimal mark and numerals. locales is a deprecated alias, kept for one release. |
format | Intl.NumberFormatOptions | Currency, percent, compact, units, fixed decimals. | |
formatter | (value: number) => string | Format it yourself; overrides locale and format. Digits roll, everything else swaps. | |
direction | "auto" | "up" | "down" | "auto" | auto rolls up as the number's size grows and down as it shrinks, like an odometer. |
animated | boolean | true | false shows changes at once. |
transition | Motion Transition | snappy | The spring each digit rides. |
aria-hidden | boolean | false | Hide it when something else already announces the value. |
className | string | "" | Appended to the root's classes. |
toRollParts(value, { locale, format, formatter }) is exported too: it splits a formatted number into the keyed digit and symbol parts the component renders.
Accessibility
- The formatted number is read as one string from a visually hidden copy; the rolling faces are hidden from assistive tech.
- It is not a live region. If changes must be announced, announce them from a live region of your own, or set
aria-hiddenand let the surrounding control (a progressbar's value, a label) speak the number.
Motion
Every digit is a ten-face cylinder on the snappy spring that only turns in the direction of change, so a 9 to 0 carry rolls forward instead of rewinding, and a value that changes mid-roll redirects from where the digit is. New places enter from half a digit's height with a 2px blur on the side they roll from, leaving places exit the other way in 100ms, and the rest slide over to make room. Reduced motion: values change at once, with no roll or slide.
Notes for AI
Use NumberRoll for any displayed number that changes in place, and pass formatting through format and locale instead of pre-formatting a string, so separators and numerals match the reader. Reach for formatter only for formats Intl.NumberFormat cannot make.
Do not key it on the value or remount it to restart the animation; pass the new value and it rolls. Set animated={false} while a gesture drives the value, and aria-hidden when the number is already announced elsewhere.
Related components
- Animated Notification Badge: counts in a chip, rolled with this component.
- Animated Progress Bar: a bar whose value rolls.
- Animated Text Swap: animated changes for words.