AI CSS Animations

Countdown Number Animation

Counts down from 10 to 0 with a punch on every tick, then GO! bursts in and stays. The tick length is one variable; the number is a registered integer stepped with steps().

Also known as: countdown animation css, 10 to 0 countdown, launch countdown text.

HTML

<div class="txt-countdown-to-go" aria-label="Countdown to go"></div>

CSS

@property --txt-countdown-to-go-n {
  syntax: "<integer>";
  initial-value: 10;
  inherits: false;
}
.txt-countdown-to-go {
  --c: var(--txt-color, #3b82f6);
  font-size: calc(var(--txt-size, 32px) * 2.2);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  display: inline-grid;
  place-items: center;
  line-height: 1;
  color: var(--c);
  font-variant-numeric: tabular-nums;
  --tick: 0.4s;
  counter-reset: txt-countdown-to-go-v var(--txt-countdown-to-go-n);
  animation: txt-countdown-to-go-count calc(var(--tick) * 11) steps(11) forwards;}
.txt-countdown-to-go::before,
.txt-countdown-to-go::after {
  grid-area: 1 / 1;
}
.txt-countdown-to-go::before {
  content: counter(txt-countdown-to-go-v);
  animation:
    txt-countdown-to-go-tick var(--tick) cubic-bezier(0.2, 0.9, 0.3, 1) 11,
    txt-countdown-to-go-hide 0.15s calc(var(--tick) * 11) forwards;
}
.txt-countdown-to-go::after {
  content: "GO!";
  opacity: 0;
  animation: txt-countdown-to-go-go 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) calc(var(--tick) * 11) forwards;
}
@keyframes txt-countdown-to-go-count {
  from { --txt-countdown-to-go-n: 10; }
  to   { --txt-countdown-to-go-n: -1; }
}
@keyframes txt-countdown-to-go-tick {
  from { transform: scale(1.35); opacity: 0.35; }
  40%  { opacity: 1; }
  to   { transform: scale(1); opacity: 1; }
}
@keyframes txt-countdown-to-go-hide {
  to { opacity: 0; transform: scale(0.6); }
}
@keyframes txt-countdown-to-go-go {
  from { opacity: 0; transform: scale(0.3) rotate(-8deg); }
  to   { opacity: 1; transform: scale(1) rotate(0); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-countdown-to-go, .txt-countdown-to-go *, .txt-countdown-to-go::before, .txt-countdown-to-go::after, .txt-countdown-to-go *::before, .txt-countdown-to-go *::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