This is a CSS glitch button hover effect that doesn't look like every other one: instead of the usual red and cyan slices, the button falls apart into bigger and bigger pixels โ 3, 5, 8, 12 px โ and gathers back, while bright red, green and blue specks of noise flash over the word. It's CSS plus four tiny SVG filters, no JavaScript. It works on a real <button> or a link and plays on hover and on keyboard focus. Below: how the pixelate filter works, the settings, and the traps.
Why this effect
I've seen hundreds of glitch buttons, and they're all the same two coloured slices sliding sideways. This one comes from my lab page: a picture that drops its resolution, like a video stream on a bad connection. It reads as "broken signal" instantly, but it's a different kind of broken โ chunky and digital, not torn. The colour specks are what sell it: on a screen with dead pixels, the noise is never grey.
What you'll build
A dark button with a light word and a thin border. Hover it, or tab to it with the keyboard, and for three quarters of a second it pixelates: fine cells first, then coarse blocks where the letters barely survive, then back to sharp. Pure R, G and B specks flash over the button at the same time, cover the word in places and turn into blocks along with it.
How the glitch button works
1. A pixelate filter in five SVG steps
CSS has no filter: pixelate(), but SVG filters can be used from CSS with filter: url(#id). One filter makes one cell size:
<filter id="gb-px8" x="0" y="0" width="1" height="1">
<feFlood x="4" y="4" width="1" height="1"/>
<feComposite width="8" height="8"/>
<feTile result="grid"/>
<feComposite in="SourceGraphic" in2="grid" operator="in"/>
<feMorphology operator="dilate" radius="4"/>
</filter>
Step by step:
feFloodpaints a single 1ร1 px dot in the middle of an 8ร8 cell.feCompositewithwidth="8" height="8"cuts out that one cell โ dot plus empty space.feTilerepeats the cell over the whole button: a grid of dots, one per cell.feComposite operator="in"keeps the button's pixels only where there is a dot โ one sample per cell.feMorphology dilategrows each sample into a square of the cell's size.
The result: every 8ร8 block takes the colour of its centre pixel. That's exactly what a low-resolution picture looks like.
2. Switching cell sizes with keyframes
There are four filters โ 3, 5, 8 and 12 px โ and the keyframes switch between them. filter: url() can't be blended, so every step is a hard switch; the rhythm does the work: the cells grow quickly and gather back a little slower.
.gb-btn:hover {
animation: gb-pixel 0.75s 1;
}
@keyframes gb-pixel {
0%, 100% { filter: none; }
10% { filter: url(#gb-px3); }
20% { filter: url(#gb-px5); }
30% { filter: url(#gb-px8); }
43% { filter: url(#gb-px12); }
60% { filter: url(#gb-px8); }
73% { filter: url(#gb-px5); }
87% { filter: url(#gb-px3); }
}
Bigger than 12 px doesn't work well: the single sample in the middle of a cell starts missing the thin strokes of the letters, and the button simply disappears.
3. Colour noise from feTurbulence
The specks are an SVG file used as a background โ noise.svg. Inside it, feTurbulence makes random noise, and two colour matrices push the contrast so hard that every speck is pure red, green, blue or a bright mix of them, and everything darker becomes transparent:
<feTurbulence type="fractalNoise" baseFrequency=".3" numOctaves="2" seed="7"/>
<feColorMatrix values="30 0 0 0 -20 0 30 0 0 -20 0 0 30 0 -20 0 0 0 0 1"/>
<feColorMatrix values="3 0 0 0 0 0 3 0 0 0 0 0 3 0 0 20 20 20 0 -6"/>
The noise sits on the button's ::after, on top of the word. During the glitch it flashes and jumps to a new background-position a few times โ one noise image looks like many. Because the pixel filter is on the button, the specks get pixelated together with the word.
4. Plays on hover and on keyboard focus
The animation runs on :hover and on :focus-visible, so keyboard users see the same glitch when they tab to the button. animation-iteration-count comes from --gb-repeat: 1 is right for a real button โ one glitch each time you point at it; a bigger number keeps it glitching while the cursor stays.
.gb-btn:hover,
.gb-btn:focus-visible {
animation: gb-pixel calc(var(--gb-glitch) * 1s) var(--gb-repeat);
}
Make it yours
| Variable | What it does |
|---|---|
--gb-glitch |
Seconds one glitch takes. 0.4 s is a twitch, 1.5 s is a slow collapse. |
--gb-repeat |
Glitches per hover. Keep 1 on a real page. |
--gb-noise |
Strength of the colour specks; 0 leaves only the pixels. |
--gb-size |
Text size; padding and corners follow it. |
--gb-color, --gb-bg |
Text and border, background. |
Spacing: padding is the space between the word and the border (in em, so it grows with the text); margin: 0 is the space around the button on your page โ set your own.
The cell sizes live in the SVG (width, height, x, y and radius), not in CSS: for a 6 px cell, put the dot at 3, cut a 6ร6 cell and dilate by 3.
Gotchas
- The SVG must be on the page.
filter: url(#gb-px8)looks for the filter by id in the same document. Put the<svg>once anywhere in the<body>(it's 0ร0 and invisible). noise.svgnext to the CSS.url(noise.svg)is relative to the CSS file. Inline it as a data URI if you prefer one file.- Thin fonts vanish. At 12 px cells, a hairline font loses whole letters. Bold text survives much better.
- Safari supports these filters, but pixel sizes are in CSS pixels โ on a retina screen the cells look half as coarse. That's fine; it still reads as pixelation.
Accessibility
It's a real <button> (or <a>): focusable, works with the keyboard, read as its text. The glitch is decoration and lasts under a second. With prefers-reduced-motion: reduce there is no pixelation and no noise โ the button just shows a soft outline on hover.
Variations
- Glitch on a picture instead of a button: Glitch Image โ real RGB channel split and torn strips.
- The classic torn glitch on text: Glitch Text.
- A button that glows instead of breaking: Neon Border.
FAQ
How do I make a glitch button hover effect in CSS?
Pick the kind of glitch first. For torn slices, stack copies of the text and shift them with clip-path. For pixelation like here, use SVG filters (feTile + feMorphology) from CSS with filter: url(#id) and switch them in a :hover animation. Neither needs JavaScript.
How do I pixelate an element in CSS?
There's no CSS function for it, but an SVG filter does it: sample one pixel per cell with feFlood + feTile + feComposite, then grow each sample into a square with feMorphology dilate. Apply it with filter: url(#your-filter). It works on text, buttons, images โ any element.
Can I make the glitch run all the time, not just on hover?
Yes: move the animation from .gb-btn:hover to .gb-btn and set the iteration count to infinite. Keep it rare on a real page โ a button that never stops glitching is tiring.
Why does my pixel glitch make the button disappear?
The cells are too big for the strokes: one sample per cell misses thin lines. Stay at 12 px or smaller, and use a bold font.