Back to Discover
Text EffectsIntermediate
Glitch Text
A CSS-only glitch animation using pseudo-elements and keyframes.
Live Preview
CYBERPUNK
export function GlitchText() {
return (
<div className="flex w-full h-40 items-center justify-center bg-[#0a0a0a] rounded-2xl border border-border overflow-hidden">
<style dangerouslySetInnerHTML={{__html: `
.glitch {
position: relative;
color: white;
}
.glitch::before, .glitch::after {
content: attr(data-text);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #0a0a0a;
}
.glitch::before {
left: 2px;
text-shadow: -1px 0 red;
animation: glitch-anim-1 2s infinite linear alternate-reverse;
}
.glitch::after {
left: -2px;
text-shadow: -1px 0 blue;
animation: glitch-anim-2 3s infinite linear alternate-reverse;
}
@keyframes glitch-anim-1 {
0% { clip-path: inset(20% 0 80% 0); }
20% { clip-path: inset(60% 0 10% 0); }
40% { clip-path: inset(40% 0 50% 0); }
60% { clip-path: inset(80% 0 5% 0); }
80% { clip-path: inset(10% 0 70% 0); }
100% { clip-path: inset(30% 0 20% 0); }
}
@keyframes glitch-anim-2 {
0% { clip-path: inset(10% 0 60% 0); }
20% { clip-path: inset(30% 0 20% 0); }
40% { clip-path: inset(70% 0 10% 0); }
60% { clip-path: inset(20% 0 50% 0); }
80% { clip-path: inset(50% 0 30% 0); }
100% { clip-path: inset(5% 0 80% 0); }
}
`}} />
<h1 className="text-4xl sm:text-5xl font-bold glitch tracking-widest uppercase z-10" data-text="CYBERPUNK">
CYBERPUNK
</h1>
</div>
);
}