Components
Data & Charts

Number Roll

An odometer-style animated number for React. Each digit scrolls to its value, perfect for counters and stats.

Want to understand how it works? Read the guide.

012345678901234567890123456789
Plays on its own. Click to take over.

Install

Copies the source into components/ui/number-roll.tsx and installs what it needs.

$ pnpm dlx shadcn@latest add https://makeui.xyz/r/number-roll.json

Usage

app/page.tsx
import { NumberRoll } from "@/components/ui/number-roll"

export default function Example() {
  return <NumberRoll value={3614} className="text-5xl font-semibold" />
}

Source

Prefer to copy by hand? It's one file. Requires motion and the shadcn cn helper.

components/ui/number-roll.tsx
"use client"

import { motion } from "motion/react"
import { cn } from "@/lib/utils"

const digits = Array.from({ length: 10 }, (_, i) => i)

function Digit({ d }: { d: number }) {
  return (
    <span className="relative inline-block h-[1em] w-[0.62em] overflow-hidden leading-none">
      <motion.span
        className="flex flex-col"
        initial={false}
        animate={{ y: `${-d * 10}%` }}
        transition={{ type: "spring", stiffness: 260, damping: 28 }}
      >
        {digits.map((n) => (
          <span key={n} className="grid h-[1em] place-items-center">
            {n}
          </span>
        ))}
      </motion.span>
    </span>
  )
}

/** Odometer-style number. Every digit is a column that scrolls to its value. */
export function NumberRoll({ value, className }: { value: number; className?: string }) {
  const chars = value.toLocaleString("en-US").split("")
  return (
    <span aria-label={String(value)} className={cn("inline-flex items-center tabular-nums leading-none", className)}>
      {chars.map((c, i) =>
        /\d/.test(c) ? <Digit key={chars.length - i} d={Number(c)} /> : <span key={chars.length - i}>{c}</span>
      )}
    </span>
  )
}