Distortion✨ Premium

Glitch Blocks

Coloured rectangles that pop up at random inside a block and die out in jolts, like a corrupted digital signal; crisp text on top.

CSSJSGlitch

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Distortion has 31 effects, including 5 free. Explore the category →

3 usage examples

Sector map while recovering deleted photos (Vestrabe) — Glitch Blocks example 1

① Sector map while recovering deleted photos (Vestrabe)

WhenIn the Vestrabe software, you pick the SD card formatted by mistake and click “Scan”: on the sector grid, orange rectangles light up in unexpected places while the bar moves on and the count of recovered photos climbs.
WhyRectangles lighting up at random on a grid suggest damaged sectors being read: you can see the tool at work, where a bar alone would look stuck.
SettingsFull-width 178 px block: --gbk-w: 100%, --gbk-h: 178px, --gbk-root-h: 0, --gbk-root-bg: transparent, --gbk-bg = 12 px grid on #121820; data-hue="18", data-spread="34" (orange to yellow), data-rate="60". The block is in the page from load, hidden; the page shows it on a click on “Scan” and hides it again at 100% (without a click it restarts the scan in a loop).
Background of a digital arts festival banner — Glitch Blocks example 2

② Background of a digital arts festival banner

WhenThe Pixendre festival banner takes up the whole top of the page: huge name, dates, venue and a “Get tickets” button set on a night background where blue and violet rectangles keep popping up.
WhyFor a digital festival the glitch becomes décor: the background never stops moving yet never crosses the text.
Settings--gbk-w: 100%, --gbk-h: 100%, --gbk-root-h: 100%, --gbk-bg = midnight radial gradient; default hues (220–280°); data-rate="70" to fill a large surface. Drop shadow on the text.
Offline camera in a construction-site monitoring app — Glitch Blocks example 3

③ Offline camera in a construction-site monitoring app

WhenIn the Torvaux app, three tiles show the site live; the fourth, “Crane cab”, shows “OFFLINE” and the time of the last frame over jumping cyan rectangles.
WhyA black tile looks like slow loading; a tile that “crackles” says at once that the feed is broken, with no icon or caption.
Settings256×146 px tile: --gbk-w: 100%, --gbk-h: 100%, --gbk-bg: #161a24; data-hue="190", data-spread="40", data-rate="150".

How it works

The .gbk-box block (250×150 px, #1a1a2e background) holds your .gbk-text (“ERROR” by default). Every 200 ms the script adds a .gbk-block rectangle, 10 to 90 px wide and 5 to 35 px tall, dropped at a random spot, with a hue between 220° and 280° (blue to violet), 70% saturation and 60% lightness.

Each rectangle gets a random animation delay between 0 and 2 s. During that delay it is shown solid; when the gbk-flash animation starts it vanishes, then lights up again briefly (about 0.16 s) at the end of its 2 s cycle if it still exists. It is removed from the DOM after 3 s. The result: three to five rectangles visible at any moment, appearing and dying out with no steady rhythm.

The text sits above the rectangles (z-index: 1). Each block has its own timer, read from its data-hue, data-spread and data-rate attributes: two copies on a page run independently, each with its own colours. The timer stops when the block leaves the screen or the tab is hidden, and resumes on return (measured: 0 rectangles added in 2 s off screen).

Measured in Chromium 151, Firefox 153 and WebKit 26.5: no errors, nothing on window, the second copy fills up like the first. A block hidden with display: none creates nothing until it is shown.

Accessibility

  • Reduced motion: under prefers-reduced-motion: reduce, no rectangle appears or flashes. The script lays down a fixed set of rectangles once (6 in the default block, more in a large one) at 70% opacity: the “corrupted signal” look stays, with no movement at all. A preference change during the visit is followed.
  • Photosensitivity: rectangles switch on abruptly. Frame-by-frame measurement: each rectangle switches on and off once every 2 s: at most 1 flash per second on any one area, below the 3 flashes per second threshold (WCAG 2.3.1), even with data-rate="40" on an 800 × 400 px block. With a light block background, run the check again.
  • Screen readers: the rectangles are empty divs, nothing is read. Only the .gbk-text text is. For an error message, put role="alert" on the container you reveal.
  • Legibility: the rectangles are light; white text over one of them loses contrast for an instant. A drop shadow on .gbk-text (text-shadow: 0 1px 3px #000) solves it.
  • Keyboard and touch: nothing to activate, the effect is automatic. The rectangles have pointer-events: none and do not block links placed in the text.

Browser compatibility

CSS (variables, @keyframes) and 2 KB of JavaScript. Minimum versions from MDN data: NodeList.forEach (Chrome 51, Firefox 50, Safari 10). The off-screen pause uses IntersectionObserver (Safari 12.1+); on older browsers the effect runs without pausing. Measured in Chromium 151, Firefox 153 and WebKit 26.5.

Chrome 51+✓ Full (measured)
Firefox 50+✓ Full (measured)
Safari 10+✓ Full (measured in WebKit)
Edge 79+✓ Full (Chromium engine)
Mobile iOS 10+✓ Full
Android Chrome 51+✓ Full

Without JavaScript, the block and its text show up with no rectangles. Without CSS variables, the block loses its size.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0258-root">
  <div class="gbk-box" data-hue="220" data-spread="60" data-rate="200">
    <span class="gbk-text">…</span>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
--gbk-w / --gbk-h 250px / 150px Block size. 100% fills the container (then give the root a height with --gbk-root-h).
--gbk-bg #1a1a2e Block background: colour, gradient or image.
--gbk-root-bg / --gbk-root-h #0a0a0f / 300px Background and minimum height of the root. transparent and 0 make the root hug the block.
data-hue (on .gbk-box) 220 Starting hue of the rectangles, in degrees (0 red, 120 green, 200 cyan, 220 blue).
data-spread 60 Random hue range added above data-hue. 0 for a single colour.
data-rate 200 (ms, minimum 40) Interval between two new rectangles. Lower means more rectangles on screen: 60–80 for a large surface.
Rectangle size (JS — 10 + Math.random() * 80, 5 + Math.random() * 30) 10–90 × 5–35 px Widen these bounds for a full-screen block, narrow them for a thumbnail.
Text (HTML — .gbk-text) “ERROR” Replace it with your message; it may hold several lines and links.

FAQ

Put the block in the page from the start, inside a hidden container (hidden), and reveal it when the error occurs. While hidden it creates no rectangles; it starts as soon as it becomes visible. The script only picks up blocks present at load time: a block inserted later is not animated.
No: .gbk-text has z-index: 1 and the rectangles have none. If your text lives in another element, give it position: relative; z-index: 1.
At the default setting, 5 per second, each removed after 3 s: about fifteen at most in the DOM at any moment. With data-rate="60", about fifty. Off screen or with the tab hidden, none.