AI CSS Animations

Score Counter with +10 Pop

A game score takes five hits: each time a +10 floats up and fades while the total punches up by ten. The score is a registered integer stepped with steps(5, start) in time with the pops.

Also known as: score +1 animation, points popup animation, game score counter css.

Score

HTML

<div class="txt-score-plus-one" aria-label="Score 170">
  <span class="txt-score-plus-one-label">Score</span>
  <span class="txt-score-plus-one-num" aria-hidden="true"><i>+10</i></span>
</div>

CSS

@property --txt-score-plus-one-s {
  syntax: "<integer>";
  initial-value: 0;
  inherits: false;
}
.txt-score-plus-one {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  display: inline-flex;
  align-items: baseline;
  gap: 0.4em;
  --beat: 0.5s;}
.txt-score-plus-one-label {
  font-size: 0.55em;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.7;
}
.txt-score-plus-one-num {
  position: relative;
  display: inline-block;
  font-size: 1.8em;
  line-height: 1;
  color: var(--c);
  font-variant-numeric: tabular-nums;
  --txt-score-plus-one-s: 120;
  counter-reset: txt-score-plus-one-v var(--txt-score-plus-one-s);
  animation:
    txt-score-plus-one-count calc(var(--beat) * 5) steps(5, start) 0.4s forwards,
    txt-score-plus-one-bump var(--beat) cubic-bezier(0.2, 0.9, 0.3, 1.3) 0.4s 5;
}
.txt-score-plus-one-num::after {
  content: counter(txt-score-plus-one-v);
}
.txt-score-plus-one-num i {
  position: absolute;
  left: 100%;
  top: -0.1em;
  margin-left: 0.1em;
  font-size: 0.45em;
  font-style: normal;
  font-weight: 800;
  opacity: 0;
  animation: txt-score-plus-one-rise var(--beat) cubic-bezier(0.2, 0.7, 0.4, 1) 0.4s 5;
}
@keyframes txt-score-plus-one-count {
  from { --txt-score-plus-one-s: 120; }
  to   { --txt-score-plus-one-s: 170; }
}
@keyframes txt-score-plus-one-bump {
  from { transform: scale(1.2); }
  to   { transform: scale(1); }
}
@keyframes txt-score-plus-one-rise {
  0%   { opacity: 0; transform: translateY(0.4em) scale(0.6); }
  20%  { opacity: 1; transform: translateY(0) scale(1.1); }
  100% { opacity: 0; transform: translateY(-1.1em) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-score-plus-one, .txt-score-plus-one *, .txt-score-plus-one::before, .txt-score-plus-one::after, .txt-score-plus-one *::before, .txt-score-plus-one *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --txt-color on the element or a parent. Currently previewing #3b82f6.
  • Font size: set --txt-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 40px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar text animations