AI CSS Animations

Squiggly Underline Animation

A wavy line under one word flows sideways forever, like a playful link or a spelling mark with personality. The SVG wave is wider than the word and slides by exactly one period.

Also known as: wavy underline css, animated wavy line, squiggle underline text.

Make it matter

HTML

<div class="txt-squiggly-underline">Make it <span class="txt-squiggly-underline-word">matter<span class="txt-squiggly-underline-line" aria-hidden="true"><svg viewBox="0 0 200 12"><path d="M0 6 q 5 -6 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0 t 10 0" /></svg></span></span></div>

CSS

.txt-squiggly-underline {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;}
.txt-squiggly-underline-word {
  position: relative;
  display: inline-block;
  color: var(--c);
}
.txt-squiggly-underline-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.12em;
  height: 0.3em;
  overflow: hidden;
}
.txt-squiggly-underline-line svg {
  display: block;
  width: 5em;
  height: 0.3em;
  fill: none;
  stroke: var(--c);
  stroke-width: 2.4;
  stroke-linecap: round;
  animation: txt-squiggly-underline-flow 0.9s linear infinite;
}
/* one period is 20 of the 200 viewBox units: 10% of the svg */
@keyframes txt-squiggly-underline-flow {
  to { transform: translateX(-10%); }
}

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