All components
Chewypixel component

Animated Number

A number that counts to its new value when it changes.

Revenue today

$12,480

Installation

npx shadcn@latest add https://chewypixel.io/r/animated-number.json

Usage

"use client";

import { useState } from "react";
import { AnimatedNumber } from "@/components/ui/animated-number";
import { Button } from "@/components/ui/button";

export function Revenue() {
  const [revenue, setRevenue] = useState(12480);

  return (
    <div className="flex items-center gap-4">
      <AnimatedNumber
        value={revenue}
        format={(value) => `$${Math.round(value).toLocaleString("en-US")}`}
        className="text-3xl font-bold tabular-nums"
      />
      <Button variant="outline" onClick={() => setRevenue(revenue + 1250)}>
        Add a sale
      </Button>
    </div>
  );
}

Props

value

The number to show.

number

format

Formats the value on each frame. Defaults to a rounded number with thousands separators.

(value: number) => string

duration

How long the count takes, in seconds.

number = 0.8

className

Classes for the wrapping span.

string

Released under the MIT License.

More components

See them in a real app

These components come from Mochi, our admin dashboard template built with Next.js, shadcn/ui and Motion.