DistortionPremium

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.

CSSJSRetro

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

“Once stitched” preview of a cross-stitch chart (Brodavène) — Pixelate Effect example 1

① “Once stitched” preview of a cross-stitch chart (Brodavène)

WhenOn the page of a fox pattern, the large illustration breaks into squares when hovered: the customer sees what the embroidery will look like, cell by cell, before downloading the chart.
WhyA cross-stitch chart is precisely an image reduced to squares of colour; pixelation shows the end result without preparing a second visual.
Settings236 px frame with rounded corners (--pxz-w: 236px, --pxz-radius: 10px), 10 px blocks (data-pxz-size="10"), 300 ms, brick outline (--pxz-ring: #9a3412), transparent root background.
Outfit shop of a pixel-art game (Klavenor) — Pixelate Effect example 2

② Outfit shop of a pixel-art game (Klavenor)

WhenFour outfit thumbnails (cape, armour, tunic, robe): the one under the mouse, or reached with the Tab key, turns into big pixels to show how it looks in the game.
WhyThe shop illustrations are detailed while the game shows low-resolution characters; the preview avoids disappointment after buying.
SettingsA single root for the four frames, which are <a class="pxz-frame"> links (no tabindex), 112 px wide, --pxz-ratio: 5/6, 14 px gap, 8 px blocks in 250 ms.
Avatars in a pixel-art discussion thread (Sprivelle) — Pixelate Effect example 3

③ Avatars in a pixel-art discussion thread (Sprivelle)

WhenIn a thread where members compare their drawings, each 56 px avatar switches to a “sprite version” as the mouse passes over it, then turns sharp again.
WhyA touch of personality that fits the forum's topic without getting in the way of reading: the effect only touches the small hovered image.
SettingsRoot set to display: block around the messages, 56 px frames with 10 px corners, 7 px blocks and a short 150 ms transition (data-pxz-duration="150") for a small size.

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 the tabindex: 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 alt text is read; the canvas has aria-hidden="true". Write an alt that 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.

Chrome 88+✓ Full (measured)
Firefox 89+✓ Full (measured)
Safari 15+✓ Full (measured in Playwright's WebKit)
Edge 88+✓ Full (Chromium engine)
Safari iOS 15+✓ Full, tap to switch on and off (measured in touch WebKit)
Chrome Android 88+✓ Full (Chromium engine)

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):

index.html — structure
<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 / propertyDefaultEffect
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

Yes. The script draws the image into the canvas without ever reading its pixels back, so the browser's origin rules block nothing. The only condition: the image must be loaded; drawing happens on its load event.
Put several .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.
One tap on the image pixelates it, a second tap makes it sharp again. If the frame is a link, the first tap follows the link: keep the effect for mouse screens then, or put the link next to the image.