data-ticker
Animated number count-up on scroll. Add data-ticker to any <data> element for smooth number animation using easeOutExpo easing.
Overview
The data-ticker attribute turns a static <data> element into an animated counter. Numbers count up from zero (or a custom start) to the value attribute when the element enters the viewport. The original text content serves as the no-JS fallback.
How It Works
- An
IntersectionObserverwatches for the element to enter the viewport (10% threshold) - When visible, a
requestAnimationFrameloop animates from start to end value - Each frame applies
easeOutExpoeasing for a fast-start, decelerating finish - Intermediate values are formatted with
Intl.NumberFormatmatching anydata-format-numberoptions - At completion, sets
data-format-number-initto prevent double-formatting
The animation runs at 60fps using requestAnimationFrame and respects prefers-reduced-motion.
Attributes
| Attribute | Type | Description |
|---|---|---|
data-ticker |
string | Animation duration in ms. Empty or omitted defaults to 1000. |
value |
string | The target numeric value. Standard HTML value attribute on <data>. |
data-ticker-start |
string | Start value for the animation. Defaults to "0". |
data-ticker-decimals |
string | Decimal places during animation. Auto-detected from value if omitted (e.g., "99.99" = 2). |
data-locale |
string | Optional locale override (e.g., "de-DE"). Shared with data-format-number. |
data-ticker-init |
boolean | Set automatically to prevent double-binding. Do not set manually. |
Duration
Control animation speed with the data-ticker value. The value is duration in milliseconds:
Start Value
By default, the ticker counts from 0. Use data-ticker-start to begin from a different value:
Decimal Precision
Decimal places are auto-detected from the value attribute. Use data-ticker-decimals to override:
With Format Number
Combine with data-format-number for locale-aware formatting during the animation. The ticker reads the format style and applies matching Intl.NumberFormat options to intermediate values:
At animation completion, the ticker sets data-format-number-init to prevent the format-number observer from re-processing the element.
Easing
The animation uses easeOutExpo easing, which starts fast and decelerates toward the end. This creates the classic "ticker" feel where numbers roll quickly then settle on the final value.
Reduced Motion
The ticker respects the user's motion preference. When reduced motion is detected, the animation is skipped entirely and the original text content is preserved:
- Checks
prefers-reduced-motion: reduce(OS setting) - Checks
data-motion-reducedattribute on<html> - If either is true, the ticker does nothing — text stays as-is
data-format-numberstill runs normally for formatting
Stats Pattern Integration
The ticker pairs naturally with the Stats pattern. Add data-ticker to stat values for animated reveals:
Dynamic Elements
Elements added to the DOM after page load are automatically observed via a MutationObserver. No manual initialization is needed.
Accessibility
- The original text content serves as a no-JS fallback
- The semantic
<data>element withvalueattribute provides machine-readable data at all times prefers-reduced-motionis respected — no animation when the user requests itfont-variant-numeric: tabular-numsprevents layout shift during animation- No wrapper element — the
<data>is the enhanced element - Screen readers see the final value via the
valueattribute, not the animated intermediate values