Skip to content
Haze UI

Animated number

A formatted number whose changing digits roll individually, with stable columns, width transitions and reduced-motion support.

pnpm dlx shadcn@latest add @haze/animated-number
Open preview in a new tab
Livesmall script

When to use

  • A metric or count changes in response to an action or a new reading
  • The initial value should be readable immediately

When not to use

  • The number never changes. Use stat.
  • The per-step intermediate values carry meaning.

Installation

Add the Haze registry to components.json once, then install Animated number with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/animated-number
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
valuenumber128Initial number. Set data-value on the rendered wrapper to update it.
localestring"en-US"BCP 47 locale for Intl.NumberFormat.
fractionDigitsnumber0Fixed number of fraction digits, from 0 through 6.
prefixstring""Text before the localized number.
suffixstring""Text after the localized number.
announcebooleanfalseAnnounces the final value after updates. Enable for infrequent changes.
oncebooleanfalseCounts up once from `from` to `value` when the number first scrolls into view (60% visible). The HTML holds the final value, so it is static without JavaScript and instant under reduced motion.
fromnumber0Starting number for the once count-up. Ignored unless once is set.
classstring–Additional classes on the inline number.

Accessibility

  • Assistive technology reads the final value. Animation layers are hidden from its tree.
  • The once count-up leaves the final value in the accessible text from the start.
  • Keep motion off for reduced-motion users and reserve live announcements for user-relevant updates.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Animated number" with `npx shadcn@latest add @haze/animated-number`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AnimatedNumber from "@/components/haze/ui/animated-number.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/animated-number.md

  • Customize with real content

    Adapt the Haze animated-number ui for our product. Replace the demo values of these props with our real content: value, locale, fractionDigits, prefix, suffix, announce, once, from, class. Keep the layout, the heading level rules and these accessibility details: Assistive technology reads the final value. Animation layers are hidden from its tree. The once count-up leaves the final value in the accessible text from the start. Keep motion off for reduced-motion users and reserve live announcements for user-relevant updates. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using animated-number, check it fits: use it when a metric or count changes in response to an action or a new reading; the initial value should be readable immediately. Avoid it when the number never changes. use stat.; the per-step intermediate values carry meaning.. Alternatives: @haze/stat, @haze/sparkline.

Dependencies

  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog