AI CSS Animations

Equalizer Text Animation

Letters stretch up from the baseline like the bars of a music equalizer, each at its own tempo, brightening as they peak. Uneven per-letter durations mean the bars never fall into step.

Also known as: audio equalizer text, music visualizer text, stretching letters css.

HTML

<div class="txt-equalizer-text" aria-label="Now playing"><span aria-hidden="true"><span style="--i: 0; --t: 0.9s">N</span><span style="--i: 1; --t: 1.2s">o</span><span style="--i: 2; --t: 0.8s">w</span><span style="--i: 3; --t: 1s">&nbsp;</span><span style="--i: 4; --t: 1.1s">p</span><span style="--i: 5; --t: 0.75s">l</span><span style="--i: 6; --t: 1.3s">a</span><span style="--i: 7; --t: 0.95s">y</span><span style="--i: 8; --t: 1.05s">i</span><span style="--i: 9; --t: 0.85s">n</span><span style="--i: 10; --t: 1.15s">g</span></span></div>

CSS

.txt-equalizer-text {
  --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);}
.txt-equalizer-text span span {
  display: inline-block;
  /* scale from the baseline, not the middle of the line box */
  transform-origin: 50% 80%;
  animation: txt-equalizer-text-level var(--t) ease-in-out infinite alternate;
  animation-delay: calc(var(--i) * -0.37s);
}
@keyframes txt-equalizer-text-level {
  0%   { transform: scaleY(0.75); color: color-mix(in srgb, var(--c) 55%, transparent); }
  40%  { transform: scaleY(1.45); color: var(--c); }
  70%  { transform: scaleY(1.05); color: color-mix(in srgb, var(--c) 80%, transparent); }
  100% { transform: scaleY(1.3); color: var(--c); }
}

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