Counting Number

A number that counts to its target on a heavily damped spring.

counting-number.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/counting-number.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/counting-number.json

3

Turn on the motion

npx @prequelui/cli@latest animate counting-number

The CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

counting-number.tsx
import { CountingNumber } from "@/components/prequelui/counting-number";

export default function Demo() {
  return (
    <CountingNumber
      number={12840}
      fromNumber={0}
      thousandSeparator=","
      className="text-5xl font-medium"
    />
  );
}
import { CountingNumber } from "@/components/prequelui/counting-number";

export function Variant() {
  return (
    <CountingNumber tempo={1.2}>
      …
    </CountingNumber>
  );
}

Animation

The value is animated as a number, never as a string. Intermediate frames are written straight into the visual span outside React, so the digits update at frame rate while the component itself does not re-render.

  • Spring: stiffness 90, damping 50, restDelta 0.001, restSpeed 0.01.
  • The final value is exposed once to assistive technology in a visually hidden span.
  • Digits use tabular numerals, so the width never shifts while counting.
  • Reduced motion writes the target value immediately without intermediate frames.
spring 90 / 50restDelta 0.001tabular-numsdirect DOM write

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

CountingNumber

PropTypeDefault
numbernumber0
fromNumbernumber0
inViewbooleanfalse
inViewOncebooleantrue
delaynumber0
decimalPlacesnumber0
decimalSeparatorstring"."
thousandSeparatorstring | undefined—
padStartbooleanfalse
initiallyStablebooleanfalse
onCompleted() => void—
transitionTransitioncomponent spring
classNamestring—

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026