Counting Number

A number that counts up to its value, written straight to the DOM.

2025
"use client"

import * as React from "react"
import { CountingNumber } from "@animate-ui/react/primitives/texts/counting-number"
import { RefreshIcon } from "@hugeicons/core-free-icons"
import { HugeiconsIcon } from "@hugeicons/react"

import { Button } from "@/components/ui/button"

export default function CountingNumberDemo({
  number = 2025,
  fromNumber = 0,
  padStart = false,
  decimalSeparator = ".",
  decimalPlaces = 0,
  delay = 0,
}: {
  number?: number
  fromNumber?: number
  padStart?: boolean
  decimalSeparator?: string
  decimalPlaces?: number
  delay?: number
}) {
  const [run, setRun] = React.useState(0)
  const key = [run, number, fromNumber, padStart, decimalSeparator, decimalPlaces, delay].join()

  return (
    <div className="flex flex-col items-center gap-6">
      <CountingNumber
        key={key}
        number={number}
        fromNumber={fromNumber}
        padStart={padStart}
        decimalSeparator={decimalSeparator}
        decimalPlaces={decimalPlaces}
        delay={delay}
        className="text-4xl font-semibold tabular-nums"
      />
      <Button variant="outline" size="sm" onClick={() => setRun((n) => n + 1)}>
        <HugeiconsIcon icon={RefreshIcon} strokeWidth={2} data-icon="inline-start" />
        Replay
      </Button>
    </div>
  )
}

Installation

npm install @animate-ui/react motion
pnpm add @animate-ui/react motion
yarn add @animate-ui/react motion
bun add @animate-ui/react motion

Usage

import { CountingNumber } from '@animate-ui/react/primitives/texts/counting-number';

export function Stat() {
  return <CountingNumber number={2025} inView />;
}

A new number springs on from where the count is instead of restarting it.

Animation

  • Counts from fromNumber to number on a spring (stiffness: 90, damping: 50): most of the range goes by in the first second, then the last units tick in slowly (2025 lands after about 4.5s).
  • The ticking value is written to the DOM directly, without a React render per frame.
  • transition takes other spring options, or any Motion transition with a type or an ease.
  • <AnimateUIProvider tempo> paces the default spring.
  • Under reduced motion, the number shows its target right away.
  • Screen readers read the target value once, never the ticking values.

API Reference

CountingNumber

PropTypeDefault
number
number-
fromNumber?
number0
padStart?
booleanfalse
decimalSeparator?
string'.'
thousandSeparator?
string-
decimalPlaces?
number0
transition?
SpringOptions | Transition{ stiffness: 90, damping: 50 }
delay?
number0
initiallyStable?
booleanfalse
inView?
booleanfalse
inViewMargin?
string'0px'
inViewOnce?
booleantrue
...props?
Omit<React.ComponentProps<'span'>, 'children'>-

Built by Skyleen. The source code is available on GitHub.

Last updated: 10/18/2026

On this page