Pixelate Effect
On hover, keyboard focus or tap, your image is redrawn in big squares of colour, then turns sharp again when you leave it.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Distortion has 31 effects, including 5 free. Explore the category →
3 usage examples



How it works
Each .pxz-frame holds your .pxz-img image and a <canvas> laid exactly over it. When the effect switches on, the script shrinks the image into a small hidden canvas (one cell per block), then scales it up into the visible canvas with smoothing turned off: every cell becomes a crisp square of a single colour. The crop matches object-fit: cover, so the pixelated version lines up with the photo.
The block size grows from 1 to 12 px (data-pxz-size attribute) over 300 ms (data-pxz-duration), one whole step at a time: you see the picture break apart square by square. On leave, the same path runs backwards and the canvas is cleared as soon as blocks are back to 1 px: what you see is the real, sharp image again. Each animation frame is capped at 50 ms, and nothing runs at rest.
The canvas is sized to the frame's real size times devicePixelRatio (Retina screens), and a ResizeObserver recomputes it when the frame changes size. One root can hold several frames (a gallery, a list of avatars): they share the root's settings and each reacts on its own.
Accessibility
- Keyboard: the frame has
tabindex="0"and an outline (--pxz-ring); keyboard focus triggers the same pixelation as hover. If the frame is a link or contains one, remove thetabindex: the link's focus is what counts. - Touch: one tap switches the pixelation on, the next one switches it off (measured in Chromium, Firefox and WebKit with an emulated touch screen). Mouse hover and touch are told apart with Pointer Events.
- Screen readers: only your image's
alttext is read; the canvas hasaria-hidden="true". Write analtthat describes the picture itself, not the effect. - Reduced motion: with
prefers-reduced-motion: reduce, the image jumps straight to the pixelated state and straight back to sharp, without the gradual growth of the blocks. The feature stays complete. - Readability: the pixelated version wipes out detail. Don't put essential information (a price, a legal notice) in an image that pixelates.
Browser compatibility
2D canvas and 3.6 KB of JavaScript, no dependency. Measured in Chromium 151, Firefox 153 and Playwright's WebKit 26.5: 0 errors, two independent copies, hover, Tab, touch, 390 px and reduced motion. Minimum versions from @mdn/browser-compat-data: aspect-ratio (Chrome 88, Firefox 89, Safari 15) sets the floor; Pointer Events and ResizeObserver are older.
Without aspect-ratio, the frame takes the image's proportions (thanks to its width and height attributes). Without :focus-visible (before Safari 15.4), a mouse click on the frame also switches the pixelation on. Without JavaScript, the image stays sharp and nothing happens.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0253-root" data-pxz-size="12" data-pxz-duration="300">
<div class="pxz-frame" tabindex="0">
<img class="pxz-img" width="400" height="400" alt="…" src="…">
<canvas class="pxz-canvas" aria-hidden="true"></canvas>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
data-pxz-size (on the root) |
12 |
Final block size in CSS pixels (2 minimum). 6 keeps the image recognisable, 20 and above gives an abstract mosaic. |
data-pxz-duration (on the root) |
300 |
Duration in milliseconds of the blocks' growth, and of their return. 0 for an instant switch. |
.pxz-img image |
Bundled SVG illustration | Replace src and alt with your image (JPG, PNG, WebP, SVG, even hosted on another domain). Keep its width and height attributes. |
--pxz-w and --pxz-ratio |
200px and 1/1 |
Frame width (never wider than its container) and width/height ratio, for example 4/3 or 5/6. |
--pxz-radius |
0px |
Corner rounding of the frame (and so of the image and the blocks). |
--pxz-gap |
16px |
Gap between several frames placed in the same root. |
--pxz-ring |
#d946ef |
Colour of the outline shown on keyboard focus. |
--pxz-bg and --pxz-min-h |
#0a0a0f and 300px |
Root background and minimum height; transparent and 0 to drop it into your layout. |
FAQ
load event..pxz-frame elements (each with its <img> and <canvas>) in a single root: they share data-pxz-size and data-pxz-duration. For different settings, use one root per group.