Number Count Up
Key figures count up from zero with easing when they come into view, and can be replayed.
AI prompt
Create three metric cards in a row (stacking under 360px): "Patterns" 500+, "Uptime" 99.9% and "Revenue" $4.2M, each with a 26px semibold tabular number and a 12px label. The real final value is written in the markup as text. When a card enters the viewport (IntersectionObserver, threshold 0.4) run a requestAnimationFrame count from 0 to the target over 1200ms with an ease-out cubic curve (1 - (1-t)^3), preserving the prefix, suffix and decimal places of each figure and formatting thousands with toLocaleString. Mark the numbers aria-hidden while counting and expose the final text through a visually hidden span so assistive technology never reads intermediate values. A Replay button re-runs the animation. Under prefers-reduced-motion show the final values immediately and hide nothing.About this pattern
Definition
Headline numbers animate from 0 to their final value over about a second, with deceleration, so the eye follows the growth and lands on the final figure.
Purpose & UX principles
- Draws attention to key figures and conveys scale.
- The final value is in the markup from the start (and is what assistive technology reads), so the animation never hides data.
- Runs once when the figure becomes visible; a Replay button allows seeing it again.
Interaction states
- Before (not yet visible), counting, final, replay.
Motion specification
- 1200ms with an ease-out cubic curve, computed per frame; decimals and prefixes keep their format throughout.
- Reduced motion: the final figures are shown immediately.
Responsive behaviour
- Figures use tabular numerals so the width does not jitter while counting.
- Cards stack on narrow widths.
Code
<div class="box">
<div class="kp" id="kp">
<div class="k"><b data-to="500" data-suf="+">500+</b><small>Patterns</small></div>
<div class="k"><b data-to="99.9" data-dec="1" data-suf="%">99.9%</b><small>Uptime</small></div>
<div class="k"><b data-to="4.2" data-dec="1" data-pre="$" data-suf="M">$4.2M</b><small>Revenue</small></div>
</div>
<button id="re" type="button">Replay</button>
</div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.box{display:grid;gap:12px;justify-items:center}
.kp{display:flex;gap:8px;width:min(320px,100%)}
.k{flex:1;padding:14px 8px;text-align:center;background:var(--surface);border:1px solid var(--line);border-radius:12px}
.k b{display:block;font-size:22px;font-weight:600;font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.k small{font-size:11.5px;color:var(--muted)}
#re{height:28px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:12px;cursor:pointer}
#re:hover{border-color:var(--accent)}
#re:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (max-width:360px){.kp{flex-direction:column}}const reduce=matchMedia('(prefers-reduced-motion: reduce)').matches,nums=[...document.querySelectorAll('.k b')];
const fmt=(el,v)=>{const dec=+(el.dataset.dec||0);return (el.dataset.pre||'')+v.toLocaleString('en',{minimumFractionDigits:dec,maximumFractionDigits:dec})+(el.dataset.suf||'');};
nums.forEach(n=>{n.dataset.final=n.textContent;});
function run(el){const to=+el.dataset.to;if(reduce){el.textContent=el.dataset.final;return;}
const t0=performance.now();el.setAttribute('aria-hidden','true');
const f=t=>{const p=Math.min(1,(t-t0)/1200),e=1-Math.pow(1-p,3);el.textContent=fmt(el,to*e);if(p<1)requestAnimationFrame(f);else{el.textContent=el.dataset.final;el.removeAttribute('aria-hidden');}};requestAnimationFrame(f);}
if('IntersectionObserver' in window&&!reduce){const io=new IntersectionObserver(es=>es.forEach(en=>{if(en.isIntersecting){run(en.target);io.unobserve(en.target);}}),{threshold:.4});nums.forEach(n=>{n.textContent=fmt(n,0);io.observe(n);});}
document.getElementById('re').addEventListener('click',()=>nums.forEach(run));One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Number Count Up — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.box{display:grid;gap:12px;justify-items:center}
.kp{display:flex;gap:8px;width:min(320px,100%)}
.k{flex:1;padding:14px 8px;text-align:center;background:var(--surface);border:1px solid var(--line);border-radius:12px}
.k b{display:block;font-size:22px;font-weight:600;font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.k small{font-size:11.5px;color:var(--muted)}
#re{height:28px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:12px;cursor:pointer}
#re:hover{border-color:var(--accent)}
#re:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (max-width:360px){.kp{flex-direction:column}}
</style></head>
<body><div class="stage">
<div class="box">
<div class="kp" id="kp">
<div class="k"><b data-to="500" data-suf="+">500+</b><small>Patterns</small></div>
<div class="k"><b data-to="99.9" data-dec="1" data-suf="%">99.9%</b><small>Uptime</small></div>
<div class="k"><b data-to="4.2" data-dec="1" data-pre="$" data-suf="M">$4.2M</b><small>Revenue</small></div>
</div>
<button id="re" type="button">Replay</button>
</div>
</div>
<script>
const reduce=matchMedia('(prefers-reduced-motion: reduce)').matches,nums=[...document.querySelectorAll('.k b')];
const fmt=(el,v)=>{const dec=+(el.dataset.dec||0);return (el.dataset.pre||'')+v.toLocaleString('en',{minimumFractionDigits:dec,maximumFractionDigits:dec})+(el.dataset.suf||'');};
nums.forEach(n=>{n.dataset.final=n.textContent;});
function run(el){const to=+el.dataset.to;if(reduce){el.textContent=el.dataset.final;return;}
const t0=performance.now();el.setAttribute('aria-hidden','true');
const f=t=>{const p=Math.min(1,(t-t0)/1200),e=1-Math.pow(1-p,3);el.textContent=fmt(el,to*e);if(p<1)requestAnimationFrame(f);else{el.textContent=el.dataset.final;el.removeAttribute('aria-hidden');}};requestAnimationFrame(f);}
if('IntersectionObserver' in window&&!reduce){const io=new IntersectionObserver(es=>es.forEach(en=>{if(en.isIntersecting){run(en.target);io.unobserve(en.target);}}),{threshold:.4});nums.forEach(n=>{n.textContent=fmt(n,0);io.observe(n);});}
document.getElementById('re').addEventListener('click',()=>nums.forEach(run));
</script>
</body></html>