AI CSS Animations

Snake Text Animation

The letters ride a sine wave and tilt to follow its slope, so the word slithers like a snake. Rise and tilt are separate translate and rotate animations, a quarter cycle apart.

Also known as: slithering text, sine wave text, wavy letters with rotation.

HTML

<div class="txt-snake-text" aria-label="Slithering"><span aria-hidden="true"><span style="--i: 0">S</span><span style="--i: 1">l</span><span style="--i: 2">i</span><span style="--i: 3">t</span><span style="--i: 4">h</span><span style="--i: 5">e</span><span style="--i: 6">r</span><span style="--i: 7">i</span><span style="--i: 8">n</span><span style="--i: 9">g</span></span></div>

CSS

.txt-snake-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-snake-text span span {
  display: inline-block;
  animation:
    txt-snake-text-rise 0.8s ease-in-out infinite alternate,
    txt-snake-text-tilt 0.8s ease-in-out infinite alternate;
  /* the tilt leads the rise by a quarter cycle: steepest where the wave crosses the middle */
  animation-delay: calc(var(--i) * 0.16s - 1.6s), calc(var(--i) * 0.16s - 2s);
}
@keyframes txt-snake-text-rise {
  from { translate: 0 -0.2em; }
  to   { translate: 0 0.2em; }
}
@keyframes txt-snake-text-tilt {
  from { rotate: 14deg; }
  to   { rotate: -14deg; }
}

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