GooseUI

Components

Stat Counter

New

A number that counts up to its value. It is a server component with no client JavaScript: a registered custom property is animated and every digit is printed with a CSS counter. Two triggers: "mount" counts once by time on first paint, "scroll" ties the count to the scroll of the nearest scrollable container. The final value is in the server HTML, so search engines, screen readers and browsers without the needed CSS get it as is.

Browser Support

Scroll-driven animations

Ties the count to scroll (trigger="scroll").

Your browser:
Registered custom properties

Animates the counter value.

Your browser:

Preview

Scroll the window: the counters finish counting as they come into its visible area.

Our numbers

Scroll the window down. The counters below start from zero and finish as they come fully into view.

12,400+
Active users
99.9%
Uptime
4.9
Average rating
12,000+
Downloads

Scroll back up and they count down again: the number follows the scroll position, not the clock.

Installation

npx shadcn@latest add @gooseui/stat-counter
pnpm dlx shadcn@latest add @gooseui/stat-counter
yarn dlx shadcn@latest add @gooseui/stat-counter
bunx --bun shadcn@latest add @gooseui/stat-counter

Usage

import { StatCounter } from "@/components/ui/stat-counter"

export default function Example() {
  return (
    <div className="text-center">
      <StatCounter value={12480} suffix="+" className="text-4xl font-bold" />
      {/* or follow the scroll of the nearest scroll container: */}
      {/* <StatCounter trigger="scroll" value={12480} /> */}
      <p className="text-sm text-muted-foreground">Active users</p>
    </div>
  )
}

Examples

Currency and compact notation

formatOptions goes straight to Intl.NumberFormat, and locale picks separators and symbols. Currency signs, percent and compact suffixes stay as static text around the counting digits. Thousand separators come from the locale in groups of three; formats CSS cannot rebuild (negative numbers, exponents, other grouping schemes) show the final value without a count.

€84,250
Monthly revenue
2.4M
Downloads
<StatCounter
  value={84250}
  locale="de-DE"
  formatOptions={{ style: "currency", currency: "EUR", maximumFractionDigits: 0 }}
/>

<StatCounter
  value={2400000}
  formatOptions={{ notation: "compact", maximumFractionDigits: 1 }}
/>

Count on mount, with replay

trigger="mount" counts once by time and does not depend on scroll. The button remounts the counter with a new key.

1,284
Orders today
const [run, setRun] = useState(0)

<StatCounter key={run} trigger="mount" value={1284} />
<Button onClick={() => setRun((n) => n + 1)}>Replay</Button>

Props

PropTypeDefaultDescription
valuenumber-Final value
fromnumber0Value the count starts from
prefixReactNode-Content before the number
suffixReactNode-Content after the number
decimalsnumber0Digits after the decimal point
localestring"en-US"Locale for Intl.NumberFormat
formatOptionsIntl.NumberFormatOptions-Extra Intl.NumberFormat options
trigger"mount" | "scroll""mount"mount: once by time on first paint. scroll: follows the nearest scrollable container
durationnumber2500Count duration in ms (mount only, default 2500)
scrollRangestring"entry 0% cover 65%"animation-range for scroll, default "entry 0% cover 65%"
classNamestring-Additional CSS classes

Features

  • No JavaScript: works in Server Components, nothing to hydrate
  • SEO friendly: the final value is in the server HTML
  • Stable width: tabular-nums and a hidden copy of the final value hold the width
  • Reduced motion: shows the final value right away
  • Screen readers: hear only the final value, not every frame