GlassmorphismPremium

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.

JSClickShatter

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

The tempered glass breaks so the screen doesn't — product page of a phone screen protector — Glass Shatter & Reform example 1

① The tempered glass breaks so the screen doesn't — product page of a phone screen protector

WhenProduct page for a tempered-glass film: a drawn phone on the left, the pitch and the price on the right. The visitor taps the phone to simulate a drop; “Fit a new film” puts an intact sheet back.
WhyThe product's selling point is exactly what the effect does: the film bursts, and underneath the home screen is still there, unharmed, between the pieces. The shards stay where they are until the film is “changed”, like a real cracked protector you keep for a few days.
SettingsScene enlarged to 164 × 294 px over the phone screen (shard travel follows: ±82 px); pad hidden; blur removed from the panel and cut to 3 px on the shards, since a protector is clear; shards lightened (rgba(255, 255, 255, .24), 75% rim); the “Fit a new film” button calls scene.click() when the glass is broken.
Sticky note deleted, “Undo” glues it back — a flat-share's shared board — Glass Shatter & Reform example 2

② Sticky note deleted, “Undo” glues it back — a flat-share's shared board

WhenFour coloured sticky notes on the flat-share board. A note's cross makes it burst; a “Note removed · Undo” banner appears on the right, and “Undo” glues the card back together.
WhyA deletion that can still be undone needs a visible in-between state: the pieces left on the board say “not lost yet”, and their return shows the undo really worked. A plain fade would say neither.
SettingsOne root per note (150 × 110 px), with no role or tabindex and with pointer-events: none: the cross, a real button of the page, calls scene.click(), and so does “Undo”; pad turned into coloured paper that fades with the panel; shards in the note's colour, no blur, at 72% opacity.
Three glass lives — capitals quiz on a revision website — Glass Shatter & Reform example 3

③ Three glass lives — capitals quiz on a revision website

WhenQuestion 7 of 20: four answers, and at the top right three small heart tiles. Each wrong answer breaks a life.
WhyA lost life does not vanish: its debris stays next to the lives still whole, and the player sees at a glance how many are gone and how many are left. The shards' little bounce is enough to mark the mistake without interrupting the question.
SettingsThree 48 × 38 px roots (shard travel: ±24 px), not clickable; red gradient pad dropping to 14% opacity once the life is broken; pink shards with no blur; the quiz script calls scene.click() on the last whole life at each wrong answer.

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" and tabindex="0". Measured in Chromium, Firefox and WebKit: Tab reaches it (a 2 px lavender #c4b5fd outline, 8 px off the block), Enter shatters it, Space reforms it, and aria-pressed goes from false to true and back. The aria-label is 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", the aria-label is what gets read, not the panel's content. If the panel carries information (a note, a price), remove role, tabindex and aria-pressed from the scene and trigger it from a real <button> next to it with scene.click(); the script only updates aria-pressed when 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).

Chrome 87+✓ Full (measured, frosting seen)
Firefox 103+✓ Break, return and keyboard measured; frosting not verified
Safari 14.1+✓ Not verified on a real Safari (break and keyboard measured in WebKit)
Edge 87+✓ Not verified (same engine as Chrome)
Mobile iOS 14.5+✓ Not verified
Android Chrome 87+✓ Measured in emulation: one tap shatters, the next reforms

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

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

Glass Shatter Reveal is a curtain: its glass hides some content, its six triangular shards follow paths written in the CSS, fly off in 3D and vanish to show what lies behind. Here nothing is hidden and nothing vanishes: eleven irregular pieces, drawn at random each time, stay spread out in front of you until someone glues them back. Take the other to unveil a piece of information; this one to show that something is broken, deleted or lost — and that you can still go back.
Call 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.
The shards do not catch clicks, so a link placed in the panel stays clickable — but its click bubbles up to the scene and breaks it too. Stop it with 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.