Skip to content
Hazine

Animated Counter

Number that counts from a start value to its final value the first time it scrolls into view, formatted with Intl. The server render and screen readers get the final value only.

How it differs. Interpolates the whole value on an animation frame loop. The moving node is hidden from assistive technology and a visually hidden sibling carries the final value.

Install

pnpm dlx shadcn@latest add @hazine/animated-counter

Adds 1 file.

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": "https://api.hazine.dev/r/{name}.json"
  }
}

Needed once per project. Items resolve each other through the @hazine namespace.

Props7

valuerequired
number
Final value. The server render and assistive technology only ever see this.
from
number = 0
Value the count starts from.
duration
number = MAX_DURATION
Milliseconds, capped at 500.
locale
string = "en-US"
formatOptions
Intl.NumberFormatOptions
Passed to Intl.NumberFormat, for example { style: "currency", currency: "USD" }.
prefix
string = ""
suffix
string = ""

Also accepts every prop of Omit<React.ComponentProps<"span">, "ref">.

Accessibility

Pattern
Landmarks and headings
Keyboard
Nothing to operate. The item has no focusable parts.
Screen reader

The animated span is aria-hidden. A visually hidden sibling holds the final formatted value, so intermediate numbers are never read.

Reduced motion
The final value is shown at once and nothing counts.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies0

None. The item is one self-contained file.

Tokens shipped0

None. The item is styled by the tokens your theme already has.

More in Media and Motion