How it works
Slices from a one-pixel-wide image
A broken video signal loses sync line by line: some lines start too early, some too late, and the color channels drift apart. An SVG filter can do the same to any HTML with a generated displacement map that is a single pixel wide.
The pipeline
The component applies a regular filter: url(#id) to its content. On every glitch
frame the filter does three things:
- Load the row offsets with
feImage, from a tiny PNG generated for the frame. - Split the channels with
feColorMatrixandfeOffset, like the chromatic aberration page. - Shift the slices of each channel with
feDisplacementMap, then screen the three channels back together withfeBlend.
Between bursts the map is left out, and only the static channel split remains.
1. The slice map
feDisplacementMap moves every pixel by scale × (channel − ½), reading the channel from a second image. A slice is a
run of rows that all move by the same amount, so the map only needs one value per row: a PNG
that is one pixel wide and exactly as tall as the element, in px. Red holds the offset
around 128; green is 128 everywhere, so nothing moves vertically. The bands are drawn from a
seeded random generator (mulberry32, shared with the aurora), so a seed always gives the same layouts:
for each of the slices:
height = sliceHeight × (1/6 … 1) // seeded
top = 0 … H − height // seeded
offset = ±(0.2 … 1) // seeded
rows[top … top + height] = offset
red = 128 + offset × 127 // one pixel per row feImage stretches the map over the filter region with preserveAspectRatio="none". Stretching sideways changes nothing, since every
row is one color. Vertically the map has one pixel per CSS px, so the cuts between slices
stay hard. A map stretched from fewer rows would be smoothed by the browser, and the slices
would bend into each other instead of breaking. The PNG is encoded in plain TypeScript with
the same small encoder as the CRT's barrel map, without a
canvas: a 600 px tall element gives a map of about 2 KB.
2. Channel split and fringe
Each channel is isolated and moved on its own. The Channel split moves red right
and blue left all the time; a glitch frame adds the Burst split. The slices then
move with a different scale per channel: red by 1 + fringe, blue by 1
− fringe of the shift. Inside a displaced slice the channels land at different places,
so the cut edges tear into red and blue while the untouched rows keep only the small static split.
The filter region uses filterUnits="userSpaceOnUse" and is padded sideways by
the furthest red can travel, currently 58 px. Slices only move horizontally, so there is no vertical padding. The filter for a glitch
frame with your settings:
<svg width="0" height="0" aria-hidden="true">
<!-- W × H: the element's size in px -->
<filter id="glitch" filterUnits="userSpaceOnUse" primitiveUnits="userSpaceOnUse"
x="-58" y="0" width="W + 116" height="H"
color-interpolation-filters="sRGB">
<!-- 1 × H px PNG: red = row offset around 128, green = 128 -->
<feImage href="data:image/png;base64,…" x="-58" y="0"
width="W + 116" height="H" preserveAspectRatio="none" result="map" />
<feColorMatrix in="SourceGraphic" type="matrix" values="1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0" />
<feOffset dx="6.5" dy="0" />
<feDisplacementMap in2="map" scale="97.58"
xChannelSelector="R" yChannelSelector="G" result="r" />
<feColorMatrix in="SourceGraphic" type="matrix" values="0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0" />
<feOffset dx="0" dy="0" />
<feDisplacementMap in2="map" scale="72.28"
xChannelSelector="R" yChannelSelector="G" result="g" />
<feColorMatrix in="SourceGraphic" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0" />
<feOffset dx="-6.5" dy="0" />
<feDisplacementMap in2="map" scale="46.98"
xChannelSelector="R" yChannelSelector="G" result="b" />
<feBlend in="r" in2="g" mode="screen" result="rg" />
<feBlend in="rg" in2="b" mode="screen" />
</filter>
</svg> 3. Bursts on a CSS clock
The bursts are timed by a hidden element running a CSS animation that repeats every 250 ms. Every animationiteration event advances a tick counter, and a
pure function turns the tick into a frame: time is cut into periods of the Burst interval (currently 2.5 s), and each period holds one burst of Burst frames consecutive ticks
at a seeded moment. The first tick of a period is always calm, so bursts never merge.
Using a CSS animation as the clock means the browser stops it in the same places it stops
every other animation: under prefers-reduced-motion, inside a data-motion="paused" region (the pause button in the panel), off screen and in background
tabs. Pausing freezes the frame that is showing.
Photosensitivity
Glitches are a classic seizure trigger: big, sudden changes, often in bright colors. WCAG 2.3.1 allows at most three flashes in any second, where a flash is a pair of opposing changes in luminance. A glitch frame can move bright content over dark content anywhere in the element, so the effect does not try to estimate how strong a change is. It limits how often the picture may change at all: only on a tick, 4 times per second. That is at most 4 changes, so at most 2 flashes per second even if every change were a full-contrast flash. A unit test checks this for every second of a long sequence. The bursts are also short and rare by default, and the page has a pause button (WCAG 2.2.2).
With reduced motion, no burst ever plays. Still image picks what shows instead: by default only the static channel split, or one frozen glitch frame, or nothing at all.
Readability
During a burst the text is hard to read; that is the point, but keep it to short, decorative type. The static split is small by default (1.5 px). The caption under the poster is outside the filter. The text inside stays real text: screen readers and selection are unaffected.
Browser support and performance
SVG filters on HTML, including feImage with a data URL and feDisplacementMap, are Baseline widely available (web-features 3.44.0). Checked
in Chromium; other engines are untested.
- On static content the filtered result is cached. A burst changes the map, which reruns the filter over the whole element, at most four times a second. Animated content (try Animate image) reruns it every frame.
- The filter isolates three channels and displaces each, so it costs about three times a single displacement. On a large, high-DPI area keep the element as small as the design allows.
- Generating a map is a loop over the rows and a few kilobytes of PNG, so it is negligible next to the filter itself.