AI CSS Animations

Waving Flag Text

A banner on a pole ripples in the wind: each letter is a strip of the flag that rises, falls and shades a beat after its neighbor, with more swing toward the free end. Pure CSS, one keyframe.

Also known as: waving flag animation css, wave text animation, banner wave text.

HTML

<div class="txt-flag-wave-text" aria-label="Launch week"><i aria-hidden="true"></i><span aria-hidden="true"><span style="--i: 0">L</span><span style="--i: 1">A</span><span style="--i: 2">U</span><span style="--i: 3">N</span><span style="--i: 4">C</span><span style="--i: 5">H</span><span style="--i: 6">&nbsp;</span><span style="--i: 7">W</span><span style="--i: 8">E</span><span style="--i: 9">E</span><span style="--i: 10">K</span></span></div>

CSS

.txt-flag-wave-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;
  align-items: flex-start;
  letter-spacing: 0.02em;}
.txt-flag-wave-text i {
  position: relative;
  width: 0.14em;
  height: 3.2em;
  margin-top: -0.1em;
  border-radius: 0.07em;
  background: linear-gradient(90deg, color-mix(in srgb, currentColor 75%, transparent), color-mix(in srgb, currentColor 45%, transparent));
}
.txt-flag-wave-text i::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -0.22em;
  width: 0.3em;
  height: 0.3em;
  border-radius: 50%;
  background: currentColor;
  translate: -50% 0;
}
.txt-flag-wave-text > span {
  display: inline-flex;
  margin-top: 0.1em;
}
.txt-flag-wave-text span span {
  display: inline-block;
  padding: 0.36em 0.06em 0.36em 0.03em;
  margin-right: -0.03em;
  background: var(--c);
  color: #fff;
  /* the tilt runs a quarter cycle ahead, so each strip leans along the wave's slope */
  animation:
    txt-flag-wave-text-ripple 1.7s cubic-bezier(0.45, 0, 0.55, 1) calc(var(--i) * -0.13s) infinite,
    txt-flag-wave-text-tilt 1.7s cubic-bezier(0.45, 0, 0.55, 1) calc(var(--i) * -0.13s - 0.425s) infinite;
}
.txt-flag-wave-text span span:first-child { padding-left: 0.5em; }
.txt-flag-wave-text span span:last-child { padding-right: 0.6em; }
/* the swing grows with distance from the pole */
@keyframes txt-flag-wave-text-ripple {
  0%, 100% { translate: 0 calc(var(--i) * -0.016em); background-color: color-mix(in srgb, var(--c) 82%, #fff); }
  50%      { translate: 0 calc(var(--i) * 0.016em); background-color: color-mix(in srgb, var(--c) 78%, #000); }
}
@keyframes txt-flag-wave-text-tilt {
  0%, 100% { transform: skewY(calc(var(--i) * -0.6deg)); }
  50%      { transform: skewY(calc(var(--i) * 0.6deg)); }
}
@media (prefers-reduced-motion: reduce) {
  .txt-flag-wave-text span span { animation: none; }
}

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