How it works
A glitch is a few frames of broken picture between normal ones. Here it's built from copies of the text stacked on top of each other:
<span class="glitch">
<span class="glitch__rgb glitch__rgb--a" aria-hidden="true">GLITCH</span>
<span class="glitch__rgb glitch__rgb--b" aria-hidden="true">GLITCH</span>
<span class="glitch__text">GLITCH</span>
<span class="glitch__slices" aria-hidden="true">
<span>GLITCH</span>
<span>GLITCH</span>
<!-- one per slice -->
</span>
</span>- Tearing. Each slice is a full copy clipped to one horizontal band with
clip-path: inset(top 0 bottom 0). In a glitch frame every band moves sideways by its own amount, so the letters look cut. While it plays, the real text hides and the slices stand in for it. - RGB split. Two colored copies sit behind the text and move apart, the way a misaligned screen splits colors.
- Skew and flicker act on the whole element: it leans with
skewX()or fades for a frame.
Why steps() and not easing
A glitch has no in-between positions: a band is either here or there. Every animation uses steps(1, end), which holds each keyframe until the next one instead of sliding between them. That's also why the rhythm matters more than the effect. Two short tears with a tiny pause read as a glitch, while one long tear reads as a broken layout.
The timeline sets that rhythm. Glitch frames tear the text, pause frames show it whole, and the frame lengths become keyframe percentages. Click a frame to freeze the preview on it, and slow the preview down to see frames that last 60ms.
Offsets live in custom properties
Each slice gets one variable per glitch frame, and one shared @keyframes reads them:
.glitch__slices > :nth-child(2) {
clip-path: inset(18% 0 61% 0);
--g1: 6px; --g2: -4px;
}
@keyframes glitch-tear {
0% { opacity: 1; transform: translateX(var(--g1)); }
38% { opacity: 1; transform: none; }
54% { opacity: 1; transform: translateX(var(--g2)); }
100% { opacity: 0; }
}Without the variables you'd need a separate @keyframes block for every slice. Shuffle picks new band heights and offsets. They come from a seed, so a shared link shows exactly the same glitch.
Triggers
- Hover is plain CSS:
.glitch:hoverstarts the animation. - Loop is plain CSS too. The still time between runs is part of the animation, held as the last keyframe, so there's no JavaScript timer.
- Click needs a few lines of JavaScript that add a class and remove it on
animationend. Removing the class and forcing a reflow before adding it back restarts the effect on every click.
Accessibility
- Screen readers read the text once. Every copy has
aria-hidden="true", so only the real text is announced and indexed. - Reduced motion switches it off. The CSS ends with a
prefers-reduced-motionrule that removes the animation. - Keep flashes rare. WCAG 2.3.1 says content shouldn't flash more than three times in any second, because fast flashing can trigger seizures. The tool warns you when a loop goes over that.
- Don't glitch what people need to read. It works for a logo, a heading or a 404 page, not for body text or buttons whose label must be clear.