AI CSS Animations

Karaoke Lyrics Line Fill

Lyrics on a dark screen fill with color word by word as they are sung, then the next line scrolls up to take its place. Each line clips a gradient with a moving stop, timed to the scroll.

Also known as: karaoke text animation, karaoke-animation, lyrics highlight animation, karaoke lyrics css.

HTML

<div class="txt-karaoke-lyrics-text" aria-label="Lyrics: City lights are calling, we run until the morning, and sing it out loud">
  <span class="txt-karaoke-lyrics-text-head" aria-hidden="true"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 12.5V3.2l7-1.4v8.7" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/><circle cx="4.3" cy="12.5" r="1.9" fill="currentColor"/><circle cx="11.3" cy="10.5" r="1.9" fill="currentColor"/></svg>Now singing</span>
  <span class="txt-karaoke-lyrics-text-window" aria-hidden="true"><span class="txt-karaoke-lyrics-text-roll"><span style="--i: 0">City lights are calling</span><span style="--i: 1">we run until the morning</span><span style="--i: 2">and sing it out loud</span><span style="--i: 3">City lights are calling</span></span></span>
</div>

CSS

@property --txt-karaoke-lyrics-text-p {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}
@property --txt-karaoke-lyrics-text-ink {
  syntax: "<color>";
  inherits: false;
  initial-value: rgba(255, 255, 255, 0.36);
}
.txt-karaoke-lyrics-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;
  display: inline-flex;
  flex-direction: column;
  gap: 0.5em;
  padding: 0.8em 1.15em 0.75em;
  border-radius: 0.8em;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: color-mix(in srgb, var(--c) 14%, #0c0c12);
  box-shadow: 0 0.6em 1.4em -0.6em rgba(0, 0, 0, 0.5);}
.txt-karaoke-lyrics-text-head {
  display: flex;
  align-items: center;
  gap: 0.45em;
  font-size: 0.48em;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}
.txt-karaoke-lyrics-text-head svg {
  width: 1.2em;
  height: 1.2em;
  color: color-mix(in srgb, var(--c) 70%, #fff);
}
.txt-karaoke-lyrics-text-window {
  display: block;
  height: 2.7em;
  overflow: hidden;
  font-size: 0.86em;
  -webkit-mask-image: linear-gradient(transparent, #000 0.3em, #000);
  mask-image: linear-gradient(transparent, #000 0.3em, #000);
}
.txt-karaoke-lyrics-text-roll {
  display: block;
  animation: txt-karaoke-lyrics-text-roll 9s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
.txt-karaoke-lyrics-text-roll span {
  display: block;
  width: max-content;
  line-height: 1.35em;
  white-space: nowrap;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--c) 72%, #fff) var(--txt-karaoke-lyrics-text-p),
    var(--txt-karaoke-lyrics-text-ink) var(--txt-karaoke-lyrics-text-p));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: txt-karaoke-lyrics-text-sing 9s linear infinite;
  /* line i is sung during seconds 3i to 3i + 3 of the loop */
  animation-delay: calc(var(--i) * 3s - 9s);
}
@keyframes txt-karaoke-lyrics-text-roll {
  0%, 30%         { translate: 0 0; }
  33.33%, 63.33%  { translate: 0 -1.35em; }
  66.67%, 96.67%  { translate: 0 -2.7em; }
  100%            { translate: 0 -4.05em; }
}
@keyframes txt-karaoke-lyrics-text-sing {
  0%, 3%    { --txt-karaoke-lyrics-text-p: 0%; --txt-karaoke-lyrics-text-ink: rgba(255, 255, 255, 0.94); }
  28%, 36%  { --txt-karaoke-lyrics-text-p: 100%; --txt-karaoke-lyrics-text-ink: rgba(255, 255, 255, 0.94); }
  37%, 96.67% { --txt-karaoke-lyrics-text-p: 0%; --txt-karaoke-lyrics-text-ink: rgba(255, 255, 255, 0.36); }
  100%      { --txt-karaoke-lyrics-text-p: 0%; --txt-karaoke-lyrics-text-ink: rgba(255, 255, 255, 0.94); }
}
@media (prefers-reduced-motion: reduce) {
  .txt-karaoke-lyrics-text-roll,
  .txt-karaoke-lyrics-text-roll span { animation: none; }
  .txt-karaoke-lyrics-text-roll span:first-child { --txt-karaoke-lyrics-text-p: 55%; --txt-karaoke-lyrics-text-ink: rgba(255, 255, 255, 0.94); }
}

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