Craft›Number Ticker

Number Ticker

A number whose digits roll to their new value like an odometer, each column a beat after its right-hand neighbour; Intl formatting (currency, compact…) stays put and the full value is announced.

Copy a ready prompt for Claude Code, Codex or Cursor

Seen on

Original to Copia

Dependencies

reacttailwindcssmotion

Interaction type

spring

Install via CLI

pnpm dlx shadcn@latest add @copia/number-ticker

Without the namespace: npx shadcn@latest add https://copia-ui.vercel.app/r/number-ticker.json

How to use

demo.tsx
"use client"

import { useEffect, useState } from "react"
import { NumberTicker, type NumberTickerProps } from "./number-ticker"

/** A balance that keeps changing, plus a counter that only goes up. */
export default function Demo({ stagger = 0.04 }: Pick<NumberTickerProps, "stagger">) {
  const [balance, setBalance] = useState(12480.5)
  const [visits, setVisits] = useState(982)

  useEffect(() => {
    if (matchMedia("(prefers-reduced-motion: reduce)").matches) return
    const id = setInterval(() => {
      setBalance((b) => Math.max(0, Math.round((b + (Math.random() - 0.4) * 3200) * 100) / 100))
      setVisits((v) => v + Math.ceil(Math.random() * 40))
    }, 1100)
    return () => clearInterval(id)
  }, [])

  return (
    <div className="grid flex-1 place-items-center p-6">
      <div className="flex flex-col items-center gap-6 text-center">
        <div className="flex flex-col gap-1">
          <span className="font-mono text-[11px] tracking-[0.14em] text-muted-foreground uppercase">Balance</span>
          <NumberTicker value={balance} format={{ style: "currency", currency: "USD" }} locale="en-US" stagger={stagger} className="text-5xl font-medium tracking-tight" />
        </div>
        <div className="flex flex-col gap-1">
          <span className="font-mono text-[11px] tracking-[0.14em] text-muted-foreground uppercase">Visits today</span>
          <NumberTicker value={visits} locale="en-US" stagger={stagger} className="text-2xl text-muted-foreground" />
        </div>
      </div>
    </div>
  )
}

Customization

Use the sliders button at the top right of the preview to tweak stagger live and copy the generated JSX.

Props

PropTypeDefaultDescription
valuenumber-The number to show.
formatIntl.NumberFormatOptions-Currency, decimals, compact notation…
localestringbrowserFormatting locale.
staggernumber0.04Seconds between neighbouring columns starting to roll.

Attribution

Original component. Recreated by Copia.

Read how it was reverse engineered

Source code

number-ticker.tsx
"use client"

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

export type NumberTickerProps = {
  value: number
  /** Intl.NumberFormat options (currency, decimals, compact…). */
  format?: Intl.NumberFormatOptions
  locale?: string
  /** Seconds between neighbouring digits starting to roll, right to left. */
  stagger?: number
  className?: string
}

const ROLL = { type: "spring", bounce: 0.15, duration: 0.7 } as const
const DIGITS = "0123456789"

/** One column: a strip of 0–9 that rolls to the digit, like an odometer. */
function Digit({ digit, delay, reduced }: { digit: number; delay: number; reduced: boolean }) {
  return (
    <span className="relative inline-block h-[1lh] overflow-hidden">
      {/* Invisible copy of the widest digit keeps the column width stable. */}
      <span className="invisible">0</span>
      <motion.span
        className="absolute inset-x-0 top-0 flex flex-col"
        initial={false}
        animate={{ y: `${-digit * 10}%` }}
        transition={reduced ? { duration: 0 } : { ...ROLL, delay }}
      >
        {DIGITS.split("").map((d) => (
          <span key={d} className="h-[1lh]">
            {d}
          </span>
        ))}
      </motion.span>
    </span>
  )
}

/**
 * A number whose digits roll to their new value instead of jumping, each
 * column a little after its right-hand neighbour. Separators, currency and
 * signs from Intl formatting stay put; the full value is announced.
 */
export function NumberTicker({ value, format, locale, stagger = 0.04, className }: NumberTickerProps) {
  const reduced = !!useReducedMotion()
  const text = new Intl.NumberFormat(locale, format).format(value)
  const chars = text.split("")
  // Key columns from the right, so a new leading digit slides in without reshuffling the rest.
  let fromRight = 0
  const keyed = chars
    .map((char) => char)
    .reverse()
    .map((char) => ({ char, slot: /\d/.test(char) ? fromRight++ : -1 }))
    .reverse()

  return (
    <span className={cn("inline-flex tabular-nums", className)} aria-label={text} role="img">
      {keyed.map(({ char, slot }, i) =>
        slot >= 0 ? (
          <Digit key={`d${slot}`} digit={Number(char)} delay={slot * stagger} reduced={reduced} />
        ) : (
          <span key={`s${i}-${char}`} aria-hidden>
            {char}
          </span>
        ),
      )}
    </span>
  )
}

Keep in mind

Most components here are recreations of the best interfaces out there. We don't claim to be the original creators: this is our attempt to reverse engineer, replicate and often add a few features. We credit everyone we can; if we missed someone, let us know.

Contact

Found a bug or a missing credit? Open an issue

License & usage

  • — Free to use and modify in personal and commercial projects (MIT).
  • — No attribution required, but a link back to Copia is appreciated.
  • — Demo images are not part of the license; replace them with your own.
PreviousInverted Perspective CarouselNext Segmented Control
Balance$0012345678900123456789,001234567890012345678900123456789.0012345678900123456789
Visits today001234567890012345678900123456789