Final value in the HTML
You render 12,480; the script counts to it. Search engines, screen readers and visitors without JavaScript always get the real number.
Add data-counter to a number and it counts up when it scrolls into view, formatted for the language of the page.
Install it, watch the live preview, then read the full reference.
npm install @samline/counterFrom 7 KB gzipZero dependenciesMIT licensed
ONE SMALL SCRIPT. RIGHT AT HOME IN YOUR STACK.
You render 12,480; the script counts to it. Search engines, screen readers and visitors without JavaScript always get the real number.
With prefers-reduced-motion, numbers never move: the rendered value stays, and turning it on mid-count jumps to the end.
Intl.NumberFormat with the closest lang attribute: 1.234,5 in German, 12,34,567 in India, currencies and compact notation.
data-counter="99.95" counts with two decimals all the way; a target written with no decimals counts in whole numbers.
Counts by elapsed time, not frames, so it lasts the same on every screen, with ease-out, ease-in-out, linear or your own curve.
Start from any value to count down, and data-counter-repeat counts again every time the number comes back.
Configure with attributes or options; animateNumber works without the DOM.
Package
counter, autoCounter and animateNumber as ESM or CommonJS.
Elements
Count a selector, element or list; returns a cleanup.
Whole page
Every [data-counter], including content added later.
HTML / CDN
A classic script that starts on its own.
Any number
The eased tween behind it, for charts, canvas or your own UI.
Parsing
Read 1.234,5 or $1,234.50 back into a number.
Count a statistic up when it scrolls into view.
Read the installation guideInstall
npm
npm install @samline/counterpnpm
pnpm add @samline/counteryarn
yarn add @samline/counterbun
bun add @samline/counterHTML / CDN
<script src="https://cdn.jsdelivr.net/npm/@samline/counter@1.14.0/dist/browser/counter.global.js" defer></script>Mark the number
Render the final value and put the plain number in data-counter.
<p>
<span data-counter="12480">12,480</span> customers
</p>Start counting
import { autoCounter } from '@samline/counter'
autoCounter()Continue with every attribute, option and formatting choice.
Explore the optionsThree common jobs, without writing an animation loop.
counter('.price', {
locale: 'es-MX',
format: { style: 'currency', currency: 'MXN' },
})<span data-counter="0" data-counter-from="10" data-counter-easing="linear">0</span>animateNumber({
to: 72,
duration: 800,
onUpdate: value => gauge.style.setProperty('--value', value),
})Try the examples or follow the first steps.
Guides, the complete API and release notes, in one place.
Read the documentation