AI CSS Animations

Glitch Rotating Text

Each word cuts in hard with a short glitch burst: tinted copies jump through clip-path slices and the letters jitter, then everything locks steady. steps() timing keeps the burst crisp.

Also known as: glitch word swap, glitch text transition, channel switch text.

System booting online secure

HTML

<div class="txt-glitch-rotating-text">System
  <span class="txt-glitch-rotating-text-words">
    <span style="--i: 0" data-text="booting">booting</span>
    <span style="--i: 1" data-text="online">online</span>
    <span style="--i: 2" data-text="secure">secure</span>
  </span>
</div>

CSS

.txt-glitch-rotating-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: flex;
  align-items: baseline;
  gap: 0.28em;
  white-space: nowrap;}
.txt-glitch-rotating-text-words {
  display: inline-grid;
  color: var(--c);
}
.txt-glitch-rotating-text-words span {
  grid-area: 1 / 1;
  justify-self: start;
  position: relative;
  /* 3 words x 2.2s = 6.6s; each word cuts in, glitches for 0.26s, then holds */
  animation: txt-glitch-rotating-text-cut 6.6s steps(1, end) infinite;
  animation-delay: calc(var(--i) * 2.2s - 7.1s);
}
.txt-glitch-rotating-text-words span:not(:first-child) {
  opacity: 0;
}
.txt-glitch-rotating-text-words span::before,
.txt-glitch-rotating-text-words span::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  clip-path: inset(50% 0 50% 0);
  animation: 6.6s steps(1, end) infinite;
  animation-delay: inherit;
}
.txt-glitch-rotating-text-words span::before {
  color: color-mix(in srgb, var(--c) 45%, #ec4899);
  animation-name: txt-glitch-rotating-text-slice-a;
}
.txt-glitch-rotating-text-words span::after {
  color: color-mix(in srgb, var(--c) 45%, #22d3ee);
  animation-name: txt-glitch-rotating-text-slice-b;
}
@keyframes txt-glitch-rotating-text-cut {
  0%     { opacity: 1; transform: translateX(0.06em) skewX(-10deg); }
  0.91%  { opacity: 1; transform: translateX(-0.05em) skewX(8deg); }
  1.82%  { opacity: 1; transform: translateX(0.03em) skewX(-3deg); }
  2.73%  { opacity: 1; transform: translateX(-0.02em) skewX(0); }
  3.94%  { opacity: 1; transform: none; }
  33.33%, 100% { opacity: 0; transform: none; }
}
@keyframes txt-glitch-rotating-text-slice-a {
  0%     { clip-path: inset(8% 0 58% 0); transform: translateX(-0.1em); }
  0.91%  { clip-path: inset(62% 0 12% 0); transform: translateX(0.12em); }
  1.82%  { clip-path: inset(30% 0 44% 0); transform: translateX(-0.06em); }
  2.73%  { clip-path: inset(78% 0 4% 0); transform: translateX(0.08em); }
  3.94%, 100% { clip-path: inset(50% 0 50% 0); transform: none; }
}
@keyframes txt-glitch-rotating-text-slice-b {
  0%     { clip-path: inset(55% 0 20% 0); transform: translateX(0.1em); }
  0.91%  { clip-path: inset(12% 0 70% 0); transform: translateX(-0.08em); }
  1.82%  { clip-path: inset(70% 0 8% 0); transform: translateX(0.05em); }
  2.73%  { clip-path: inset(20% 0 60% 0); transform: translateX(-0.1em); }
  3.94%, 100% { clip-path: inset(50% 0 50% 0); transform: none; }
}

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