AI CSS Animations

Earthquake Text Effect

Every few seconds the letters rumble, each one jolting and tilting in its own direction, then the ground goes still. Per-letter custom properties flip the direction, so one keyframe drives them all.

Also known as: trembling text, shaking letters loop, rumble text animation.

HTML

<div class="txt-earthquake-text" aria-label="Aftershock"><span aria-hidden="true"><span style="--i: 0">A</span><span style="--i: 1">f</span><span style="--i: 2">t</span><span style="--i: 3">e</span><span style="--i: 4">r</span><span style="--i: 5">s</span><span style="--i: 6">h</span><span style="--i: 7">o</span><span style="--i: 8">c</span><span style="--i: 9">k</span></span></div>

CSS

.txt-earthquake-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-earthquake-text span span {
  --x: 1;
  display: inline-block;
  animation: txt-earthquake-text-rumble 2.6s linear infinite;
}
.txt-earthquake-text span span:nth-child(2n) { --x: -1; }
.txt-earthquake-text span span:nth-child(3n) { --x: 0.6; }
@keyframes txt-earthquake-text-rumble {
  0%, 36%, 100% { transform: translate(0, 0) rotate(0deg); }
  3%  { transform: translate(calc(var(--x) * 0.07em), -0.06em) rotate(calc(var(--x) * 5deg)); }
  6%  { transform: translate(calc(var(--x) * -0.08em), 0.04em) rotate(calc(var(--x) * -5deg)); }
  9%  { transform: translate(calc(var(--x) * 0.06em), 0.06em) rotate(calc(var(--x) * 4deg)); }
  12% { transform: translate(calc(var(--x) * -0.07em), -0.05em) rotate(calc(var(--x) * -4deg)); }
  15% { transform: translate(calc(var(--x) * 0.08em), 0.03em) rotate(calc(var(--x) * 3deg)); }
  18% { transform: translate(calc(var(--x) * -0.05em), -0.05em) rotate(calc(var(--x) * -2.5deg)); }
  22% { transform: translate(calc(var(--x) * 0.04em), 0.03em) rotate(calc(var(--x) * 1.5deg)); }
  26% { transform: translate(calc(var(--x) * -0.02em), -0.02em) rotate(calc(var(--x) * -1deg)); }
  31% { transform: translate(calc(var(--x) * 0.01em), 0) rotate(0deg); }
}

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