# Odometer

> Every digit rolls on its own wheel to the new value, like a mileage counter, rather than counting up.

Category: Charts · Free · Updated 2026-11-14 · Live demo: https://www.motionkitui.com/components/odometer

## When to use it

Live counters, pricing that changes with a slider, stock levels and any number that updates in place.

## How it works

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.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/odometer.json
```

Or copy `components/motionkit/odometer.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| 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. |

## Accessibility

- **Keyboard: Not applicable.** Text only, nothing to focus.
- **Screen readers: Pass.** Screen readers hear the formatted value once, never the rolling digits.
- **Reduced motion: Pass.** With reduced motion on, digits change instantly.
- **Colour contrast: Not applicable.** Uses whatever text colour you pass in className.

## Source

```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>
  );
}
```
