Count Up Animation on Scroll
Numbers that count up with an ease-out when the stat row enters the viewport, using IntersectionObserver.

A count up animation rolls a number from zero to its real value. Teams, pricing pages, and launch posts use it for one reason: a static “128k” is a fact, and a number that arrives is a fact you notice. The search around this pattern is “count up on scroll”, because firing the animation on page load wastes it when the stats sit below the hero.
This snippet starts the count when the stat row intersects the viewport. An ease-out cubic makes the last part of the count slow down, which is when the eye checks the final digit. Suffixes (k, ms, %) and one decimal place stay attached to the number so “99.9%” never flashes as “99.900%” or “100”.
Use the scroll progress indicator when you are measuring the page, and the circular progress bar when a single percent should be a ring. The count up is for a row of unlike units.
HTML
Each figure stores its target on the element that will change. The label is a separate element and does not get rewritten.
<section id="stats">
<p class="num"><span data-count="128" data-suffix="k">0</span></p>
<p class="label">readers / month</p>
<p class="num"><span data-count="4.9" data-decimals="1">0</span></p>
<p class="label">average rating</p>
<p class="num"><span data-count="99.9" data-decimals="1" data-suffix="%">0</span></p>
<p class="label">uptime</p>
</section>
Put the final meaning in the label. “128k” without “readers / month” is a count up that fails the sentence.
The observer and the ease
function format(el, value) {
const decimals = Number(el.dataset.decimals || 0);
el.textContent = value.toFixed(decimals) + (el.dataset.suffix || "");
}
function run() {
const start = performance.now();
function frame(now) {
const t = Math.min(1, (now - start) / 1400);
const eased = 1 - Math.pow(1 - t, 3);
nodes.forEach((el) => format(el, Number(el.dataset.count) * eased));
if (t < 1) requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
}
const io = new IntersectionObserver((entries) => {
if (entries.some((entry) => entry.isIntersecting)) {
run();
io.disconnect();
}
}, { threshold: 0.4 });
io.observe(document.getElementById("stats"));
threshold: 0.4 waits until a real portion of the row is visible. A threshold of 0 fires when one pixel peeks in, and the count finishes before the reader looks. Disconnect after the first run so scrolling back up does not restart the numbers while someone is trying to read them. The demo’s “Count again” button calls run() on purpose.
font-variant-numeric: tabular-nums keeps the digits from wobbling as 1 becomes 8. That single declaration is most of the polish.
What to count, and what to leave alone
Count a number a person came to see: revenue, customers, a latency you are proud of, a score. Do not count a phone number, a year, a version, or an identifier. “Version 2” ticking through 0 and 1 looks broken.
Round to the precision you would print in a table. A count that ends at 4.873 when the label says “4.9” teaches the reader not to trust the last frame. Store 4.9 and data-decimals="1".
Accessibility
Honor prefers-reduced-motion by setting duration to 0 and painting the final value. The information is the number, not the trip from zero.
The spans are normal text, updated in place. That is acceptable for a short animation. Do not also wrap them in a live region or the screen reader will speak every frame. After the animation, the text is the final value, which is what should be read on demand.
Keep the big figures and the page background at 4.5:1. The demo uses #f3f7f4 on #07110e.
Questions about count up animations
How do I trigger a count up when the user scrolls?
Observe the stat block with IntersectionObserver. When isIntersecting is true and at least about 40% of the block is visible, start a requestAnimationFrame loop from 0 to 1 and multiply each target by an ease-out curve. Disconnect the observer so it runs once.
Why do my counting numbers jitter?
Proportional digits have different widths. Set font-variant-numeric: tabular-nums on the figure. Also format with a fixed number of decimals so “4.9” does not become “4.90” halfway through.
Should a count up repeat every time I scroll to it?
Once is enough. Replaying on every intersection makes the number look unreliable. Offer a replay control if the motion itself is the lesson, as this demo does.