Animated Number

A number that counts up to its value when it scrolls into view.

Preview

"use client";

import { AnimatedNumber } from "@/components/motion/animated-number";

export function AnimatedNumberPreview() {
  return (
    <div className="flex flex-col items-center gap-3">
      <p className="text-xs text-muted-foreground">Monthly recurring revenue</p>
      <div className="text-4xl font-semibold tracking-tight text-foreground tabular-nums">
        <AnimatedNumber value={129480} format={(n) => `$${Math.round(n).toLocaleString()}`} />
      </div>
      <p className="text-xs text-(--color-success)">+12.4% vs last month</p>
    </div>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/animated-number

API Reference

value
number

Number to count to. Changes count from the last shown value.

Default—
duration?
number

Length of each count, in seconds. Default: 1.2

Default1.2
format?
((n: number) => string)

Formats each frame's number. Defaults to a rounded, locale-grouped integer.

Default(n) => Math.round(n).toLocaleString()
className?
string

Classes merged onto the root element.

Default—
startOnView?
boolean

Wait until the number scrolls into view before counting. Default: true

Defaulttrue
Also on React Native. Rolling tickers and count-ups.

More in Number Animation

Updated