CSS Animation Example: The Glitch
"The Glitch" is an intense, cyberpunk-inspired visual technique involving erratic chromatic aberration to indicate a digital fracture.
This is arguably the most complex text effect here in this list of CSS animation examples, utilizing several layers of CSS tricks. First, we use a custom HTML data-text attribute to mirror the original string. We then capture that string using the attr() function inside CSS for both the ::before and ::after pseudo-elements, layering them exactly on top.
We subtly offset the pseudo-elements mathematically (e.g., left: 2px vs left: -2px) and apply contrasting text-shadow colors (usually red and blue) to create chromatic aberration.
Finally, the most critical part is the @keyframes using the clip-path property with the inset() function. By haphazardly animating random slicing windows across the text, we simulate video scanline tears.
Here is the code to create The Glitch animation.
Accessibility Considerations
The flashing, erratic frequency of this animation runs a high risk of triggering seizures in photosensitive individuals or causing immense distraction. prefers-reduced-motion is a CSS media feature used to detect if a user has enabled a setting on their device to minimize the amount of non-essential animation or motion. You must respect it here by forcibly turning it off for those who have enabled this setting.
The cleanest way to disable it is to simply purge the pseudo-elements governing the effect by using display: none.
Here's what we used in our example:
@media (prefers-reduced-motion: reduce) {
.glitch::before,
.glitch::after {
/* Removes the tearing glitch elements entirely */
display: none;
}
}