Counter animation: a number counter in plain JavaScript
A counter animation makes a number climb from zero to its final value. You build it with requestAnimationFrame, an easing curve and a number formatter, and the starter below runs as one HTML file.
Free skills to start. Pro is $79 a year for every skill, or $9.99 a month for 10. See pricing
What is a counter animation?
A counter animation, also called a number counter or count-up, shows a figure rising to its real value instead of appearing at once. It is used for stats bands, pricing pages and hero sections, where one large number carries the message. The motion draws the eye to the figure for about two seconds, then it stops.
The effect is only a number being rewritten many times. The interesting part is doing it well: tying progress to time rather than to frame count, keeping the digits from jittering sideways, and not forcing a screen reader to hear every intermediate value.
Two details separate a solid counter from a quick demo. The timestamp that requestAnimationFrame passes to your callback is the same for every callback in a frame, and the browser pauses those calls in background tabs. So a counter driven by that timestamp finishes on schedule rather than speeding up on a fast display. And the number needs digits of equal width, which is a font feature that not every font provides.
How the effect works
Each frame, the script works out how much of the duration has passed. It takes the timestamp the browser hands to the requestAnimationFrame callback and subtracts the timestamp of the first frame. MDN says calls generally match the display refresh rate, and warns that code which counts frames instead of elapsed time runs faster on high refresh-rate screens. Dividing elapsed time by the duration gives progress from 0 to 1, so the counter lasts the same time on a 60 Hz and a 144 Hz display.
Progress goes through an easing function, here ease-out cubic, so the number rises quickly and settles slowly. The eased value is multiplied by the target and passed to Intl.NumberFormat, which writes the digits using the grouping rules of the chosen locale. MDN shows the same number printed as 123.456,789 for de-DE and 1,23,456.789 for en-IN, so one call handles separators for different readers.
The count starts when the number is visible. An IntersectionObserver reports when a target crosses a threshold, so the script waits until the figure is on screen and then starts the loop once. If the user has asked for reduced motion, the script skips the loop and writes the final number.
01
Put the final value in the markup
Store the target in a data attribute and print the final number as the fallback text. Without JavaScript the page still shows the true figure.
02
Compute progress from elapsed time
Save the timestamp of the first frame, subtract it from each later timestamp and divide by the duration. Clamp the result to 1.
03
Ease and format the value
Pass progress through an easing curve, multiply by the target, round to the number of decimals you want and format it with Intl.NumberFormat.
04
Start on view and honour reduced motion
Observe each counter with an IntersectionObserver and unobserve it after the first run. If the prefers-reduced-motion query matches reduce, write the final value and stop.
HTML
Number counter that counts up when it scrolls into view
Plain JavaScript, no library. Change data-to, data-decimals and data-suffix on each number. With reduced motion on, the final values appear at once.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Counter animation</title>
<style>
body { margin: 0; min-height: 100vh; display: grid; place-items: center;
background: #101418; color: #f2efe8; font-family: system-ui, sans-serif; }
.stats { display: flex; gap: 72px; flex-wrap: wrap; justify-content: center; padding: 32px; }
.stat { text-align: center; }
.num { display: block; font-size: 88px; font-weight: 700; line-height: 1;
font-variant-numeric: tabular-nums; color: #ffb454; }
.label { display: block; margin-top: 12px; font-size: 18px; color: #b8b4aa; }
</style>
</head>
<body>
<div class="stats">
<div class="stat">
<span class="num" data-to="12480">12,480</span>
<span class="label">Pages rendered</span>
</div>
<div class="stat">
<span class="num" data-to="98.6" data-decimals="1" data-suffix="%">98.6%</span>
<span class="label">Checks passed</span>
</div>
<div class="stat">
<span class="num" data-to="264">264</span>
<span class="label">Skills in the catalog</span>
</div>
</div>
<script>
(function () {
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var DURATION = 1800;
var ease = function (t) { return 1 - Math.pow(1 - t, 3); };
function show(el, value) {
var d = Number(el.dataset.decimals || 0);
var fmt = new Intl.NumberFormat('en-US', {
minimumFractionDigits: d,
maximumFractionDigits: d
});
el.textContent = fmt.format(value) + (el.dataset.suffix || '');
}
function run(el) {
var target = Number(el.dataset.to);
if (reduce) { show(el, target); return; }
var start = null;
function frame(ts) {
if (start === null) start = ts;
var p = Math.min((ts - start) / DURATION, 1);
show(el, target * ease(p));
if (p < 1) requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
}
var nums = document.querySelectorAll('.num');
if (!('IntersectionObserver' in window)) { nums.forEach(run); return; }
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (e) {
if (e.intersectionRatio > 0) { run(e.target); io.unobserve(e.target); }
});
}, { threshold: 0.5 });
nums.forEach(function (n) { io.observe(n); });
})();
</script>
</body>
</html>A starting point written for this page, free to use in your own projects. The skills below build the finished version with checks, fallbacks and a recorded video.
What to get right on a real page
01
Use tabular figures
Add font-variant-numeric: tabular-nums. It switches on the font's tnum feature, which gives every digit the same width, so the number does not shift sideways as digits change. It only works if the font ships tabular figures, so check the font you use.
02
Drive it from the frame timestamp
Do not add a fixed step per frame. The requestAnimationFrame callback runs in step with the display refresh rate, so a fixed step makes the count finish sooner on a 144 Hz screen. Elapsed time divided by duration gives the same length everywhere.
03
Respect reduced motion
The prefers-reduced-motion query reports whether the user turned on a system setting that minimizes non-essential motion. Windows 11, macOS, iOS and Android each have one. When it reads reduce, show the final number and skip the loop.
04
Keep screen readers quiet
A live region announces changes to its content. MDN advises that for rapidly changing content such as scores or tickers you usually do not want every change announced, and suggests aria-live set to off. Keep the counter out of a live region, and make sure the final figure is in the page text.
05
Start once, when it is seen
A counter that finishes before the visitor scrolls to it wastes the effect. Observe it with IntersectionObserver, run it on the first crossing and unobserve it. The threshold is a ratio of the target's area that must be visible.
06
Count only real numbers
The animation makes a figure feel important, so the figure must be true. Print the real value in the markup, and animate toward that same value.
Skills that build a counter animation
These two Lookbk skills build heroes where a figure counts up as part of a larger scene. You give them your own numbers, and they render on your machine.
- Sunrise Pitch HeroClaude CodeCodexCursor+3 more agents
Motion Heroes · Pro
Sunrise Pitch Hero
HTML hero + embed · 2D canvas · MP4 1080p
It builds an animated website hero where a small pitch deck plays beside the headline, and one slide holds a figure that counts up beside bars. It comes as one self-contained HTML page plus a paste-in embed, checked at four widths, with a still picture for reduced motion.
Worth knowing: The deck is part of the hero, with five or six slides at most and no keyboard navigation, so it is not a slide-deck tool. Every number must come from you.
Needs: Node.js 18+, Chrome (or Chromium/Edge) and ffmpeg; no npm installs
See what Sunrise Pitch Hero makes - Scroll Route HeroClaude CodeCodexCursor+3 more agents
Motion Heroes · Pro
Scroll Route Hero
One HTML page + embed · MP4 + poster
It pins a hero while a route draws station by station as the visitor scrolls, with a ticket stub whose counters (kilometres, hours, stops) run up. It builds one self-contained page plus a paste-in embed and checks it at four widths.
Worth knowing: You can give it up to three numbers to count on the stub, and the map is a stylised poster map, not a geographic one. Every figure in the copy must come from you.
Needs: Node.js 18+, Chrome for the checks and recording, ffmpeg for the video
See what Scroll Route Hero makes
Install
Build a counter animation with your agent
Each skill is a SKILL.md folder, so it installs the same way in Claude Code, Codex, Cursor and other agents. The example below uses Sunrise Pitch Hero; each skill page has its own prompt.
1. Paste the install prompt
Your agent runs the installer. The first time, it shows a sign-in link so you can approve it in the browser.
Install the "Sunrise Pitch Hero" skill from Lookbk (https://lookbk.dev/skills/sunrise-pitch-hero). 1. Run: curl -fsSL https://lookbk.dev/cli.js | node - add sunrise-pitch-hero 2. If it prints a sign-in link, show it to me. When I say I approved it, run the same command again. 3. When the install finishes, read the SKILL.md it installed and tell me what you need from me to make the first result.
Or run it in a terminal
curl -fsSL https://lookbk.dev/cli.js | node - add sunrise-pitch-hero2. Start a new session
Agents load skills when a session starts. The installer writes the folder where your agent looks:
- Claude Code
- ~/.claude/skills/sunrise-pitch-hero
- Codex
- ~/.agents/skills/sunrise-pitch-hero
- Cursor
- ~/.agents/skills/sunrise-pitch-hero
3. Ask for the result
Describe it in plain words, for example:
Make a sunrise pitch hero for our Series A page: headline "Bring the dawn indoors.", a five-slide deck beside it (title, the problem, 41% fewer snoozes vs phone alarm 5.8 / clock radio 4.9 / us 3.4, three rules, contact), cream-to-rose sky, cobalt accent, Inter. Then record the video for LinkedIn.
Another agent? Install a skill in any agent
FAQ
Questions
Still stuck? The guides cover installing, agents and licensing in more detail.
Read the guidesHow do I make a number count up when it scrolls into view?
Observe the number with an IntersectionObserver. When it crosses its threshold, start a requestAnimationFrame loop that rewrites the text, then unobserve it so it runs once. The starter on this page does exactly that.
Why does my counter finish at different speeds on different screens?
The loop probably adds a fixed amount per frame. The browser calls requestAnimationFrame callbacks to match the display refresh rate, so more frames per second means a faster count. Use the timestamp argument and divide elapsed time by the duration.
How do I format a counting number with commas or decimals?
Use Intl.NumberFormat. Its locale argument sets the separators, so the same number prints as 123.456,789 for de-DE and 1,23,456.789 for en-IN. Set the same minimum and maximum fraction digits so the decimal count stays fixed while it counts.
Does a counter animation need a library?
No. The starter uses only browser APIs: requestAnimationFrame, IntersectionObserver and Intl.NumberFormat. A library only saves typing if you already use it on the page.
How should a counter behave when the user prefers reduced motion?
Check the prefers-reduced-motion media query. When it matches reduce, write the final number straight into the page and do not start the loop.

