This is a CSS glitch image hover effect: hover a photo and it tears into horizontal strips while its red, green and blue channels swing apart โ then everything settles back with a little inertia. No JavaScript, no canvas, no extra copies of the file: one <div>, one picture, and real colour channels split out of it with blend modes.
Why this effect
I tried it on my own logo first and couldn't stop hovering. Most image glitches fake the RGB split with tinted copies and the picture turns muddy; splitting out the real channels keeps the photo clean, so the glitch looks like a lens or a signal failing for a moment, not a filter. I like it on cards and avatars: still most of the time, and a little alive when you touch it.
What you'll build
A picture that looks completely normal at rest. When the cursor lands on it, the colour channels drift apart in a damped wave and three thin strips jump sideways, each a moment after the other. While the cursor stays, the glitch repeats after a calm pause.
How the CSS image glitch works
1. Split the photo into real colour channels
Most glitch tutorials fake the RGB split with tinted, half-transparent copies, and the picture turns muddy. Here the split is real. background-blend-mode: multiply mixes the photo with a flat colour layer: multiplying by pure green keeps only the green channel.
.gi-photo {
background: var(--gi-img) center / cover, #00ff00;
background-blend-mode: multiply;
}
2. Add red and blue back with screen
::before and ::after inherit the same background and swap the colour for red and blue. mix-blend-mode: screen adds light, so red + green + blue rebuild the original photo exactly. isolation: isolate keeps the blending inside the picture, away from the page behind it.
.gi-photo::before,
.gi-photo::after {
content: "";
position: absolute;
inset: 0;
background: inherit;
background-blend-mode: multiply;
mix-blend-mode: screen;
}
.gi-photo::before { background-color: #ff0000; }
.gi-photo::after { background-color: #0000ff; }
Why not hue-rotate copies? Many image glitch tutorials stack two extra copies of the photo with filter: hue-rotate() or a coloured overlay at half opacity. Those copies aren't channels โ each one is the whole picture in a different tint, so wherever they overlap the colours turn grey and dirty, and the photo never looks right even at rest. Real channels add up to the original pixel for pixel.
Move the red layer one way and the blue one the other, and you get true chromatic aberration: coloured fringes appear only where the picture has edges.
3. Tear strips out of the picture
The strips are three empty <i> elements on top. Each one shows the full photo, but clip-path: inset() cuts away everything except a thin band. At rest a strip sits exactly over the same part of the picture, so it is invisible; moved sideways, it looks like a torn line of the image.
.gi-photo i {
position: absolute;
inset: 0;
z-index: 1;
background: var(--gi-img) center / cover;
clip-path: inset(var(--gi-y) 0 var(--gi-b) 0);
}
--gi-y cuts from the top and --gi-b from the bottom, so --gi-y: 42%; --gi-b: 48% leaves a band 10% tall. Each strip sets its own values in the HTML.
4. Hover glitch with a real pause
A glitch that never stops gets annoying fast. So the effect runs on a clock: @property registers --gi-t as a number, and on hover a linear animation moves it from 0 to 1 once per glitch plus pause. Off hover there is no animation, so the clock stays at 0 and the picture is still.
@property --gi-t {
syntax: "<number>";
inherits: true;
initial-value: 0;
}
@keyframes gi-clock { to { --gi-t: 1; } }
.gi-photo:hover {
animation: gi-clock calc((var(--gi-glitch) + var(--gi-pause)) * 1s) linear infinite;
}
From the clock comes the progress of one glitch, --gi-p: it runs 0 โ 1 during the glitch, then clamp() holds it at 1 for the rest of the cycle โ that is the pause.
--gi-p: clamp(0, var(--gi-t) * (var(--gi-glitch) + var(--gi-pause)) / var(--gi-glitch), 1);
5. Inertia: a damped swing
Instead of jerky keyframes, the offset is a formula. sin() swings back and forth, (1 - p) takes strength away, so the movement starts hard and fades out smoothly โ like something heavy settling.
transform: translateX(calc(
var(--gi-dir) * var(--gi-shift) * 1.14 * (1 - var(--gi-p)) * sin(var(--gi-p) * 720deg)
));
The strips use the same idea with their own start (--gi-d), strength and direction (--gi-k), so they jump one after another rather than all at once.
Make it yours
| Variable | What it does |
|---|---|
--gi-img |
Your picture: url(my-photo.jpg). Any size; cover crops it to the box. |
--gi-width |
Width of the picture. The height follows --gi-ratio. |
--gi-ratio |
Width รท height: 0.8 is a 4:5 portrait, 1 a square, 1.78 is 16:9. |
--gi-shift |
How far the red and blue channels swing. 6โ10px is subtle, 30px+ is loud. |
--gi-tear |
How far the strips jump. Set it to 0 for a pure RGB split without tears. |
--gi-glitch |
How long one glitch lasts, in seconds. Shorter feels sharper. |
--gi-pause |
Seconds of calm between glitches while the cursor stays on the picture. |
--gi-red, --gi-green, --gi-blue |
The three channels. Keep pure #f00 / #0f0 / #00f to see the real photo at rest; other colours tint it. |
Spacing: the effect sets margin: 0 on the picture โ put your own margin there (the space around it on your page). There is no padding: the photo fills the box edge to edge.
More or fewer strips: copy an <i> line and give it its own --gi-y, --gi-b, --gi-k and --gi-d.
Gotchas
- The strips stick out of the picture while they jump. That is part of the look; if your layout needs clean edges, put
overflow: hiddenon the picture. - The path in
url()is relative to the CSS file, not to the page. If your styles live incss/style.cssand the photo inimg/, writeurl(../img/photo.jpg). - Browser support:
sin()insidecalc()and@propertywork in current Chrome, Edge, Safari (16.4+) and Firefox (128+). In older browsers the picture simply stays still. - Performance: only
transformis animated, and only while the cursor is on the picture. A dozen of these on a page is fine. - Touch screens have no hover: the picture just shows normally. To glitch on tap, add the same
animationto.gi-photo:activeor:focus-visible.
Accessibility
The picture is a div with role="img" and an aria-label โ write a real description of your photo there, just like an alt. For people who ask their system for less motion (prefers-reduced-motion: reduce), the hover animation is switched off and the picture stays still.
Variations
- The same channel trick on text: Chromatic Wave โ a word that splits into red, green and blue.
- Strips that tear a word apart: Glitch Text.
- Run it on its own instead of on hover: move the
animationline from.gi-photo:hoverto.gi-photo, and the pause keeps it calm.
FAQ
How do I make an image have a glitch effect in CSS?
Split the picture into colour channels with background-blend-mode: multiply (the photo times pure red, green or blue), stack the three layers and add them back with mix-blend-mode: screen. Move the red and blue layers apart for the RGB split, and cut thin copies of the photo with clip-path: inset() for the torn strips. Everything above is plain CSS โ no canvas, no script.
How do I make the glitch play on hover only?
Put the animation on .gi-photo:hover. Without the hover there is no animation, the clock --gi-t stays at 0 and the picture is still. While the cursor stays, the glitch repeats after --gi-pause seconds. For touch screens add the same line to :active or :focus-visible.
Why does my glitched image look muddy or tinted?
Usually the RGB split is faked with half-transparent coloured copies. Here the three layers are the real channels of the photo, so at rest they add up to the original exactly. If it still looks tinted, check that --gi-red, --gi-green and --gi-blue are pure #ff0000, #00ff00 and #0000ff, and that the picture has isolation: isolate.
Can I use it on a background image or a card?
Yes. The picture is just a div with a background, so any card, avatar or hero block works: give it the class, the three <i> strips and your file in --gi-img. Keep overflow: hidden on the card if the strips should not stick out.
Can I try it on my own picture and copy the code?
Yes. "Your image" puts your own file into the preview (it stays in your browser, nothing is uploaded). Set the shift, tear and pause with the sliders, then copy the HTML and CSS with the buttons at the top of the page, or download a .zip with the sample photo next to the CSS.