CSS Counter Animation

Baseline 2024 Reference ↗

Creates an animated number counter that counts from 0 to 100 over 2 seconds.

@property --num {
  syntax: "<integer>";
  initial-value: 0;
  inherits: false;
}

@keyframes count {
  to {
    --num: 100;
  }
}

.stat {
  counter-reset: n var(--num);
  animation: count 2s forwards;
}

.stat::after {
  content: counter(n);
}