A number counts up from zero to its target, with no JavaScript: a registered integer custom property is animated and rendered through a CSS counter. Ideal for stats sections.
Also known as: number counter animation, animated statistic, count up css.
<div class="txt-count-up" aria-label="500+ customers"></div>
@property --txt-n {
syntax: "<integer>";
initial-value: 0;
inherits: false;
}
.txt-count-up {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
color: var(--c);
font-variant-numeric: tabular-nums;
counter-reset: txt-n var(--txt-n);
animation: txt-count-up-tick 2s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;}
.txt-count-up::after {
content: counter(txt-n) "+";
}
@keyframes txt-count-up-tick {
to { --txt-n: 500; }
}
@media (prefers-reduced-motion: reduce) {
.txt-count-up, .txt-count-up *, .txt-count-up::before, .txt-count-up::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.