Counter Animation CSS
A number that climbs from 0 to its value with no script: the stylesheet does the counting, using an animated integer variable and a CSS counter.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Data has 28 effects, including 1 free. Explore the category →
3 usage examples



How it works
The number is not written anywhere in the page: .ccss-num is empty and its ::after shows counter(ccss). That CSS counter is fed at every instant by --ccss-n, a variable registered with @property as an <integer>. Because it has a type, the browser knows how to move it from 0 to the target one unit at a time; the ccss-count animation is a single line, from { --ccss-n: 0 }.
The target is set in the HTML with style="--ccss-to: 617", the duration with --ccss-duration (3 s, ease curve: brisk start, slower finish). Several numbers on one page each keep their own target, duration and size.
The script that ships with it computes no digit at all. It adds the ccss-waiting class, which pauses the animation, then removes it once the number is half visible. Without it, counting simply starts when the page loads.
A useful side effect: when a block hidden with display: none is shown again (tab, panel, form step), the browser restarts the animation and the number counts again from 0, with nothing to call. Inside a <details>, however, it only counts the first time it is opened.
Accessibility
- Screen readers: CSS-generated content is not read reliably. The drawn number is therefore
aria-hiddenand the value is repeated as plain text in.ccss-sr, invisible to the eye. That text is not tied to--ccss-to: always edit both together. - Reduced motion: the
animation: nonerule applies and the final value is shown from the start. - Stable width:
tabular-numsgives every digit the same width; the number does not jitter while counting, it only widens when it gains a digit (99 → 100). - Selection: like all generated content, the displayed number cannot be selected with the mouse or copied.
- Keyboard: nothing to activate, the number is plain text and never takes focus.
Browser compatibility
@property (animatable integer variable), CSS counters, calc() inside counter-reset; IntersectionObserver for the wait. Reading taken 1.5 s into a count towards 48210: between 38,000 and 39,000 in Chromium 149, Firefox 151 and WebKit 26.5. WebKit used to give the variable a fractional value and leave "0" until the end; the sold code now rounds with calc().
Without @property the variable cannot advance step by step: the number stays at 0 and then jumps to its value partway through (simulated by removing the declaration, not checked on an old browser). Without JavaScript everything works; counting starts on page load instead of waiting for the number to be visible.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0233-root">
<div class="ccss-num" style="--ccss-to: 100" aria-hidden="true"></div>
<span class="ccss-sr">100</span>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
--ccss-to on .ccss-num (HTML) |
100 | End value. Integers only: no decimals, no thousands separator. |
Text of .ccss-sr (HTML) |
100 | Value read by screen readers; keep it identical to --ccss-to. |
--ccss-duration (CSS) |
3s | Counting time, from 0 to the value. |
--ccss-size (CSS) |
3rem | Size of the number. |
--ccss-color (CSS) |
#6366f1 | Colour of the number. |
--ccss-bg (CSS) |
#0a0a0f | Block background; transparent to sit the number on your page. |
Root min-height and display (CSS) |
300px, flex | The root is a block that centres the number. Switch to min-height:0; display:inline-flex; width:auto to slip it into a sentence or a table row. |
threshold (JS) |
0.5 | Share of the number that must be visible to start counting. Remove the whole script to count on page load. |
FAQ
<span>kg</span>). To build it into the number itself, extend the rule: .ccss-num::after { content: counter(ccss) "\a0kg" }. The counter style changes the same way: counter(ccss, decimal-leading-zero) shows 07 instead of 7.--ccss-to once counting is over shows the new value at once: the animation does not replay. To count again, hide the block and show it again (display: none, then back): the CSS animation restarts from 0 towards the value in place.