Glass Shatter & Reform
A glass panel that bursts into eleven pieces on click: they scatter at random and stay put, until the next click glues everything back.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Glassmorphism has 47 effects, including 6 free. Explore the category →
3 usage examples



How it works
The clickable block is .lg-shatter-scene, 200 × 150 px. It holds an indigo, violet and fuchsia gradient pad that sticks out by 5 px (.lg-shatter-bg, at z-index: -1, which isolation: isolate keeps above your page background), then the .lg-shatter-panel: 8% white, backdrop-filter: blur(12px), an 18% white rim, a radial highlight in the top-left corner and your text. On load, the script adds eleven .lg-shard elements to it. Each shard is the size of the whole panel and shows only a piece of it, cut out by clip-path: polygon(var(--clip)); the eleven polygons, with four or five points given as percentages, tile the panel with no gap — three along the top, four in the middle, four at the bottom. At rest they are transparent and catch no clicks.
A click sets the .lg-shattered class: the panel fades out in 0.3 s and the shards appear. At the same moment the script draws a random destination for each of them — up to half the scene's width either way, ±100 px here, and a rotation of ±60° — and writes it into its transform. The transition lasts 0.8 s on the cubic-bezier(.34, 1.56, .64, 1) curve, which overshoots the target before coming back to it: each piece leaves, goes a little too far, settles. Then nothing moves: the eleven shards stay strewn over the pad for as long as nobody touches anything.
The next click sets .lg-reforming: the shards return to their place while fading out, the panel reappears, and after 800 ms the script removes both classes. If the panel is broken again before the return is over, the timer is cancelled — measured: shatter, reform, shatter again 200 ms later does leave eleven visible, displaced shards. The draw is redone every time, so you never see the same break twice. Each scene on the page has its own shards and its own state: breaking one leaves its neighbour alone.
Accessibility
- Keyboard: the scene carries
role="button"andtabindex="0". Measured in Chromium, Firefox and WebKit: Tab reaches it (a 2 px lavender#c4b5fdoutline, 8 px off the block), Enter shatters it, Space reforms it, andaria-pressedgoes fromfalsetotrueand back. Thearia-labelis in English: adapt it to your page. - Reduced motion: under
prefers-reduced-motion: reduce, the shards' transition covers opacity only (0.3 s). They appear straight where they land — measured 150 ms after the click: all eleven already in place — and fade out on the spot on the way back. “Broken” or “whole” still shows, with no flight and no bounce. - Touch: a tap counts as a click. Measured in touch emulation in Chromium and WebKit: the first tap shatters, the next one reforms.
- Contrast: the panel text, 12 px solid white with a shadow, measures between 3.2:1 and 3.5:1 on the glass in front of the violet pad (shadow not counted) — below the 4.5:1 threshold. For text that must be read, darken the panel (
background: rgba(20, 16, 60, .35)) or make it larger. - Screen readers: with
role="button", thearia-labelis what gets read, not the panel's content. If the panel carries information (a note, a price), removerole,tabindexandaria-pressedfrom the scene and trigger it from a real<button>next to it withscene.click(); the script only updatesaria-pressedwhen it finds it.
Browser compatibility
Checked with Chromium 149, Firefox 151 and WebKit 26.5: eleven shards per scene, all displaced after the click, full return, keyboard, touch, two independent copies, no name added to window, no horizontal scroll at 320 px (the root clips shards that fly out). The frosting of the panel and shards could only be looked at in Chromium: over a striped background, the Firefox and WebKit test engines do not paint backdrop-filter in automated captures — real browsers not verified. Floors per MDN: inset (Chrome 87, Edge 87, Firefox 66, Safari 14.1), clip-path: polygon() (Chrome 55, Firefox 54, Safari 9.1), backdrop-filter (Chrome 76, Firefox 103, Safari 18 or 9 with -webkit-, written in the code).
Without JavaScript you get a fixed glass panel on its pad: no shard is created and clicking does nothing. Without backdrop-filter, panel and shards are plain 8% white veils and the break works the same. Without clip-path the eleven shards would be eleven whole rectangles: do not target browsers older than those listed.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0330-root">
<div class="lg-shatter-scene" data-shatter-scene role="button" tabindex="0" aria-pressed="false" aria-label="…">
<div class="lg-shatter-bg"></div>
<div class="lg-shatter-panel">
<span class="lg-shatter-text">…</span>
</div>
<div class="lg-shatter-hint">…</div>
<!-- the 11 .lg-shard pieces are added here by the script -->
</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 |
|---|---|---|
Shard travel (JS — var spread = scene.offsetWidth) |
half the scene's width either way: ±100 px for 200 px | Multiply by 0.5 for a break that stays near the panel, by 2 for an explosion. The root has overflow: hidden, so whatever leaves it is cut off: enlarge it, or drop that rule if the shards should fly over the rest of the page. |
Rotation (JS — var ROTATION = 120) |
±60° per shard | 360 sends the pieces spinning; 20 gives a cracked pane whose parts barely slip. |
Cut (JS — the SHARDS array) |
11 polygons of 4 or 5 points, in percentages | Each line is the point list of a polygon(). Add or remove lines freely; for the panel to be fully covered at the moment it breaks, the polygons must meet edge to edge. |
Duration and bounce (CSS — .lg-shard { transition }, JS — var RETURN = 800) |
0.8 s, cubic-bezier(.34, 1.56, .64, 1) curve |
Bring 1.56 down to 1 to remove the overshoot. If you change the duration, give RETURN the same value (in milliseconds), otherwise the classes are removed before or after the return ends. |
Glass (CSS — .lg-shatter-panel and .lg-shard) |
8% white, 12 px blur (panel) and 6 px (shards) | Give the shards a denser fill (rgba(255, 255, 255, .2)) if they must show on a plain dark background. Always edit both blur lines, prefixed and unprefixed. |
Pad (CSS — .lg-shatter-bg) |
#6366f1 → #8b5cf6 → #d946ef gradient, 5 px overhang |
This is what stays visible while the panel is broken. Put an image in it, or hide it to lay the glass over an element of your page. |
Size (CSS — .lg-shatter-scene { width; height }) |
200 × 150 px | The polygons being percentages, the cut follows any size and any format; the shards' travel follows the width. |
FAQ
scene.click() on the [data-shatter-scene] element: the script only listens to the scene's click and keyboard, and a click sent by code goes down the same path. To know where it stands, read its classes: lg-shattered without lg-reforming means broken. If the scene should no longer respond by itself, give it pointer-events: none and remove role and tabindex.event.stopPropagation() on that link, or move the action out of the panel. On the keyboard, Enter and Space only break the glass when the scene itself has focus.