A headline number that counts up beside a sparkline that draws itself, with a change badge and hover readout.
A React odometer component that rolls each digit on its own wheel to the new value, like a mileage counter, instead of counting through every number in between. Use it for live counters, prices and stats that change in place.
Customize
Usage
import { Odometer } from "@/components/motionkit/odometer";
<Odometer value={48210} prefix="$" />Motion
The exact curves this component runs, plotted with Motion's own maths.
Wheel roll
Scrolls into view, or the value changes
Live counters, pricing that changes with a slider, stock levels and any number that updates in place.
Every digit is its own window onto a wheel of 0 to 9, and changing the value slides each wheel to its new digit. The wheels are keyed from the right, so the ones wheel stays the ones wheel when the number gains a digit. Higher places turn a touch later, as a real counter's wheels catch each other.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/odometer.jsonnpm install motionSave as components/motionkit/odometer.tsx.
"use client";
import { useRef } from "react";
import { motion, useInView, useReducedMotion } from "motion/react";
type OdometerProps = {
value: number;
decimals?: number;
prefix?: string;
suffix?: string;
/** BCP 47 locale used for separators. */
locale?: string;
/** Seconds for a wheel to settle. */
duration?: number;
className?: string;
};
const DIGITS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
export function Odometer({
value,
decimals = 0,
prefix = "",
suffix = "",
locale = "en-US",
duration = 1.2,
className = "",
}: OdometerProps) {
const ref = useRef<HTMLSpanElement>(null);
const inView = useInView(ref, { once: true, amount: "all" });
const reduceMotion = useReducedMotion();
const formatted = value.toLocaleString(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals });
const characters = Array.from(formatted);
// every wheel sits on 0 until the number scrolls into view, then rolls to its digit
const rolling = inView || reduceMotion;
return (
<span ref={ref} className={`inline-flex items-baseline tabular-nums ${className}`}>
<span className="sr-only">{`${prefix}${formatted}${suffix}`}</span>
<span aria-hidden className="inline-flex items-baseline">
{prefix}
{characters.map((char, i) => {
// keyed from the right, so the ones wheel stays the ones wheel when the number grows a digit
const place = characters.length - i;
if (!/\d/.test(char)) return <span key={`sep-${place}`}>{char}</span>;
const digit = rolling ? Number(char) : 0;
return (
<span key={`digit-${place}`} className="relative inline-block h-[1em] overflow-hidden leading-none">
{/* an invisible digit sizes the window; the wheel of 0 to 9 slides behind it */}
<span className="invisible">0</span>
<motion.span
className="absolute inset-x-0 top-0 flex flex-col"
initial={false}
animate={{ y: `${-digit * 10}%` }}
// higher places turn a touch later, as a real counter's wheels catch each other
transition={reduceMotion ? { duration: 0 } : { type: "spring", bounce: 0.15, duration, delay: (place - 1) * 0.04 }}
>
{DIGITS.map((n) => (
<span key={n} className="block h-[1em] text-center">
{n}
</span>
))}
</motion.span>
</span>
);
})}
{suffix}
</span>
</span>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | — | The number to show. Change it and the wheels roll. |
| decimals | number | 0 | Fixed decimal places. |
| prefix / suffix | string | "" | Text before and after. |
| locale | string | "en-US" | Locale used for separators. |
| duration | number | 1.2 | Seconds for a wheel to settle. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Only the motion package, beside React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/odometer.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, digits change instantly.
A headline number that counts up beside a sparkline that draws itself, with a change badge and hover readout.
Counts up to a value with an eased finish when it scrolls into view.
Segments draw themselves in on scroll; hover, tap or tab to one to lift it and read its value and share in the middle.