GLITCH LAB v1.0 ezolab.dev / lab instrument SYS: READY โœฆ Holiday cards

Effects/ Glitch Image [FX_05]/ Calibrated

Glitch Image

Copies a link to this page with your text and settings โ€” whoever opens it sees the same effect. Send it to a friend, a colleague or save it for later.
Pure CSS Light ยท zero deps #animation#glitch#image#rgb

CSS glitch image hover effect: the photo splits into real red, green and blue channels and tears into strips, then settles with inertia. Any picture, no JS.

Live viewport Hover the previewTap the preview
LIVE FEED 60.0 FPS | FRAME: 16.7ms RES: โ€” [ + calibrated ]
Your image photo.jpg Try the effect on any picture from your computer: it stays in your browser, nothing is uploaded. The code you copy and the .zip keep the file name from the CSS variable (photo.jpg) โ€” put your picture next to the page under that name, or change the variable.

How it works // breakdown

Spec-FX_05

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;
}
Only the green channel of the photo is left

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; }
Three channels added back: it looks like the plain photo

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.

Red to the right, blue to the left: real fringes on the 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: hidden on the picture.
  • The path in url() is relative to the CSS file, not to the page. If your styles live in css/style.css and the photo in img/, write url(../img/photo.jpg).
  • Browser support: sin() inside calc() and @property work in current Chrome, Edge, Safari (16.4+) and Firefox (128+). In older browsers the picture simply stays still.
  • Performance: only transform is 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 animation to .gi-photo:active or :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 animation line from .gi-photo:hover to .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.

Get the code โ€” copy or download
Copy HTML: the markup with your text โ€” paste it where the effect should be. Copy CSS: the styles with your slider settings โ€” paste into your stylesheet. Any text element works: give it the class and a data-text equal to its text.
or
โ†“ Download .zip Both files in one archive โ€” index.html and style.css โ€” with your text and settings. Unzip and open index.html in a browser.
/* Glitch Image โ€” RGB split and torn strips on hover, pure CSS.
   Works on any picture: set --gi-img to your file.
   The red, green and blue channels of the photo are real: the picture is
   split into three layers and added back with screen, so at rest it looks
   exactly like the original.
   Settings: change the variables below. */
.gi-photo {
  --gi-img: url(photo.jpg);
  --gi-width: 240px;  /* picture width; the height follows --gi-ratio */
  --gi-ratio: 1;      /* width / height: 1 = square, 0.8 = 4:5 portrait, 1.5 = landscape */
  --gi-shift: 20px;   /* how far the red and blue channels swing */
  --gi-tear: 72px;    /* how far the strips jump sideways */
  --gi-glitch: 0.6;   /* seconds one glitch lasts */
  --gi-pause: 1.9;    /* seconds of calm while the cursor stays on */
  --gi-red: #ff0000;
  --gi-green: #00ff00;
  --gi-blue: #0000ff;

  position: relative;
  isolation: isolate;
  width: var(--gi-width);
  max-width: 100%;
  aspect-ratio: var(--gi-ratio);
  margin: 0;          /* margin: space around the picture on your page */
  /* The picture itself is only its green channel */
  background: var(--gi-img) center / cover, var(--gi-green);
  background-blend-mode: multiply;
}

/* Hover starts a clock: --gi-t runs 0 โ†’ 1 once per glitch + pause */
.gi-photo:hover {
  animation: gi-clock calc((var(--gi-glitch) + var(--gi-pause)) * 1s) linear infinite;
}

/* --gi-p: progress of the glitch, 0 โ†’ 1, then it stays 1 for the pause */
.gi-photo::before,
.gi-photo::after,
.gi-photo i {
  --gi-p: clamp(0, var(--gi-t) * (var(--gi-glitch) + var(--gi-pause)) / var(--gi-glitch), 1);
}

/* Red and blue copies of the picture. Screen adds light:
   red + green + blue = the original photo. */
.gi-photo::before,
.gi-photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: inherit;
  background-blend-mode: multiply;
  mix-blend-mode: screen;
  /* A damped swing: two back-and-forths that lose strength */
  transform: translateX(calc(
    var(--gi-dir) * var(--gi-shift) * 1.14 * (1 - var(--gi-p)) * sin(var(--gi-p) * 720deg)
  ));
}
.gi-photo::before { --gi-dir: 1; background-color: var(--gi-red); }
.gi-photo::after { --gi-dir: -1; background-color: var(--gi-blue); }

/* Strips: full copies of the photo, cut to thin bands, on top.
   Each one starts a little later (--gi-d) and swings on its own. */
.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-q: clamp(0, (var(--gi-p) - var(--gi-d)) / (1 - var(--gi-d)), 1);
  transform: translateX(calc(
    var(--gi-k) * var(--gi-tear) * (1 - var(--gi-q)) * sin(var(--gi-q) * 540deg)
  ));
}

@property --gi-t {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
@keyframes gi-clock {
  to { --gi-t: 1; }
}

/* Less motion: the picture stays still. */
@media (prefers-reduced-motion: reduce) {
  .gi-photo:hover { animation: none; }
}