Skip to content
Component

Animated Number

Numbers that spring to their value in tabular figures, with Intl formatting.

Installation

terminal
npx shadcn@latest add https://ui.thilina.dev/r/animated-number.json

Usage

app/page.tsx
import { AnimatedNumber } from "@/components/animated-number";

export default function Page() {
  return (
    <p className="text-4xl font-semibold">
      <AnimatedNumber
        value={12480}
        format={{ style: "currency", currency: "USD" }}
        startOnView
      />
    </p>
  );
}

The number springs from zero on first render (or first view with startOnView) and glides whenever value changes, which makes it a natural fit for pricing toggles, dashboards, and stat counters. Digits render in tabular figures so the layout never jitters.

Props

PropTypeDefaultDescription
valuenumber-The target value. Changes animate from the current position.
formatIntl.NumberFormatOptions-Formatting, e.g. currency or percent. Applied every frame.
localestring-Locale for the formatter. Defaults to the runtime locale.
startOnViewbooleanfalseStart counting only once the element scrolls into view.
springOptionsSpringOptions-Custom spring physics for the count.

Accessibility

Screen readers get only the final value through aria-label; the animated frames are aria-hidden, so nothing announces sixty intermediate numbers. Under prefers-reduced-motion the value updates instantly.

Command Palette

Search for a command to run...