Code

<!-- roll-counter.free.js: download it from the Install section below and host it with your site -->
<script src="/roll-counter.free.js" defer></script>

<roll-counter id="total" value="12480" decimals="0" theme="light"></roll-counter>

<script>
  // rolls from 0 when it scrolls into view, then on every change
  const total = document.getElementById('total');
  total.value = 12936;
  total.addEventListener('settle', (e) => console.log(e.detail.value));
</script>

In context

per month
A price that switches plans
Requests today
Mint, a live stat Pro

Install · Free Web Component

One file, no dependencies. Aurora preset, every other option included. Host it yourself so your visitors never load anything from our servers.

1. Install with one command — or download the file
shadcn CLI · React
npx shadcn@latest add https://www.ui-design.co/r/roll-counter.json
2. Load it and use the element
HTML
<!-- roll-counter.free.js: download it from the Install section below and host it with your site -->
<script src="/roll-counter.free.js" defer></script>

<roll-counter id="total" value="1299" format="currency" currency="USD" decimals="0" theme="light"></roll-counter>

<script>
  // rolls from 0 when it scrolls into view, then on every change
  const total = document.getElementById('total');
  total.value = 1349.5;
  total.addEventListener('settle', (e) => console.log(e.detail.value));
</script>
3. React + TypeScript (optional)

The shadcn command adds a typed React wrapper for you. Using the file directly? Custom elements work in React as-is; for type checking add:

TypeScript
// roll-counter.d.ts
declare namespace JSX {
  interface IntrinsicElements {
    'roll-counter': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
      value?: number | string;
      from?: number | string;
      duration?: number | string;
      locale?: string;
      format?: 'decimal' | 'currency' | 'percent' | 'compact';
      currency?: string;
      decimals?: number | string;
      prefix?: string;
      suffix?: string;
      size?: number | string;
      theme?: 'light' | 'dark';
    };
  }
}

Pro · React + TypeScript Pro

One payment of $4.99, yours forever. Use it in unlimited personal and commercial projects; no resale.

  • React component with TypeScript types and the full source
  • Sunset, Mint and Mono tints for the glint, plus custom tints from Brand Fit
  • The vanilla Web Component with every tint, a demo page, README and license

Attributes & props

NameTypeDefaultDescription
value number0The number to show. Change the attribute (or el.value) and the drums roll to it — up when it grows, down when it shrinks.
from number0The value it shows before it first scrolls into view, and rolls from.
duration number (ms)1200Roughly how long a roll takes, the stagger between digits included.
format 'decimal' | 'currency' | 'percent' | 'compact''decimal'How the number is written. percent follows Intl: 0.42 reads 42%. compact gives 1.3M.
currency ISO 4217 code'USD'Currency for format="currency"; the symbol and its position come from the locale.
decimals numberautoA fixed number of decimal places. By default the format decides (2 for most currencies).
locale BCP 47 tagbrowserGrouping, decimal mark, currency position and the digits themselves, e.g. "de-DE" or "ar-EG".
prefix / suffix string—Plain text before or after the number, e.g. suffix=" members". It does not roll.
size number (px)inheritsFont size. Without it the counter takes the size, weight and font of the text around it.
theme 'light' | 'dark''light'Ink colour.
tint Pro'aurora' | 'sunset' | 'mint' | 'mono' | object'aurora'Colours of the glint that crosses the number as it settles, or a custom tint. Free build ships Aurora only.

It sits on the text baseline, so it can live inside a sentence. Formatting goes through Intl.NumberFormat: separators, currency symbols and units are ordinary characters and only the digits are drums. A number that gains a digit makes room by growing, so nothing jumps. Screen readers get the formatted value as a label and never the spinning drums; it is aria-live="off" unless you set aria-live="polite" for a total that should be announced. It fires settle with detail.value. With reduced motion the number simply changes. Numerals are tabular where the font has them.

More components