Animated Stat Counter
Plain tiles where only the figures move: each value climbs to its target at its own pace and counts again from the displayed figure when data changes.
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
Each .stco-item tile holds a .stco-value and its label. The target lives in data-target, the duration in data-duration (1,500 ms when the attribute is missing): in the demo, the three values stop at 1.2 s, 1.8 s and 2 s. The tiles themselves are in place from the start: nothing pops in, nothing bounces.
The script waits until the grid is half visible, then raises each value, slowing down as it nears the target. The number is written by Intl.NumberFormat in the page language: "48,210" under lang="en", "48 210" under lang="fr". data-prefix and data-suffix add a currency or a unit; a dot in data-target ("9.6") sets the number of decimals.
Changing data-target later restarts the count from the displayed figure, upwards or downwards: a period filter or a slider only has to write the new value into the attribute. A change that lands mid-count takes over without a jump.
The grid lays the tiles out in equal columns at least 110 px wide (auto-fit) within the --stco-max width: three abreast in 380 px, two in 250 px, a single one in a 158 px margin.
Accessibility
- Screen readers: the moving figure is
aria-hidden; a hidden.stco-srtext, added by the script, carries the end value with its prefix and suffix. It is rewritten on everydata-targetchange. - Reduced motion: no climb; the end value is written straight away, including when a value changes.
- Without JavaScript: the text written in the HTML ("48,210") stays displayed as is. Keep the real value there, not a zero.
- Unannounced change: no
aria-liveregion. If a filter changes the figures, leave focus on the button used or announce the change yourself. - Contrast: by default, light violet
#a78bfaon a near-black background. On a light background, change--stco-colorand--stco-muted.
Browser compatibility
CSS grid auto-fit, IntersectionObserver, MutationObserver, Intl.NumberFormat, requestAnimationFrame. Same readings in Chromium 149, Firefox 151 and WebKit 26.5: values at 0 while the grid is off screen, exact landing on 48,210, $126,400 and 18%, and when two blocks share the page, only the one whose data changes counts again.
Without IntersectionObserver, counting starts on page load. Without CSS grid, the tiles stack across the full width. Without JavaScript, the values written in the HTML stay displayed and still.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0247-root">
<div class="stco-grid">
<div class="stco-item">
<div class="stco-value" data-target="48210" data-duration="1800">48,210</div>
<div class="stco-label">Users</div>
</div>
<div class="stco-item">
<div class="stco-value" data-target="126400" data-prefix="$" data-duration="2000">$126,400</div>
<div class="stco-label">Revenue</div>
</div>
<div class="stco-item">
<div class="stco-value" data-target="18" data-suffix="%" data-duration="1200">18%</div>
<div class="stco-label">Growth</div>
</div>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
data-target (HTML) |
48210, 126400, 18 | End value; a decimal point sets how many decimals are shown. Changing it restarts the count. |
data-duration (HTML) |
1800, 2000, 1200 | Climb time in milliseconds, one per value (1,500 without the attribute). |
data-prefix, data-suffix (HTML) |
"$" and "%" in the English demo | Text attached before or after the number: currency, unit, sign. Any space is part of the attribute. |
lang on the page or a parent (HTML) |
browser language | Number format: thousands comma or space, decimal point or comma. |
--stco-color (CSS) |
#a78bfa | Flat colour of the values. |
--stco-item, --stco-border (CSS) |
indigo at 8% and 15% | Tile background and border. |
--stco-muted (CSS) |
white at 50% | Label colour. |
--stco-max (CSS) |
380px | Maximum grid width; together with the 110 px minimum per tile, it decides the number of columns. |
--stco-bg (CSS) |
#0a0a0f | Block background; transparent to use the page's own. |
FAQ
--stco-max, reduce the .stco-value size (1.5rem originally) or shorten the number: data-target="1.26" with data-suffix="M".el.setAttribute('data-target', 2390). The script watches data-target, data-prefix and data-suffix on each value. If the grid has not been seen yet, the figure stays at 0 and will climb to the last target written.