Nested Glass Stack
Four nested glass panes, blurrier towards the centre: on hover they come forward, and the mouse slides them around.
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 .lg-depth-scene box is 220 × 180 px and carries perspective: 600px. Inside it sit an indigo, violet and fuchsia gradient pad (.lg-depth-bg, 10 px larger all round) and four .lg-depth-pane elements placed with inset at 0, 15, 30 and 45 px from the edge: 220 × 180, 190 × 150, 160 × 120 and 130 × 90 px. Each has its own glass: a backdrop-filter: blur() of 2, 6, 12 then 18 px, a tint sliding from 15% indigo to 30% pink, a 12% white rim. Because the panes lie on top of each other, the centre looks at the backdrop through four sheets: the blurs add up while the edges stay almost sharp. Over the smooth gradient supplied, that staircase of blur barely shows; it appears as soon as something detailed (a photo, a pattern, text) passes behind.
When the scene is hovered, the CSS moves each pane one notch further: a translateZ of 0, 20, 40 and 60 px, and a translateY of 0, −5, −10 and −15 px. Under a 600 px perspective, coming forward means growing — measured on screen: the second pane becomes 196.6 × 155.2 px (+3.4%), the third 171.4 × 128.6 px (+7.1%), the front one 144.4 × 100 px (+11.1%), in 0.5 s. The back pane stays put. Each label is written at the bottom of its pane, in the 15 px strip that shows below the next one: since the panes move up, those strips widen on hover instead of covering each other.
The script (1.4 KB) adds the slide. On each scene, mousemove works out the mouse position from −0.5 to 0.5 and writes two variables per pane, --lg-depth-x and --lg-depth-y, with 5 px of travel multiplied by the pane's rank: 10 px from the corner, the panes are offset by 2.3, 4.5, 6.8 and 9.1 px, in the direction of the mouse. The CSS adds these variables to the lift inside a single transform; on leaving, the script removes them and everything settles back. Two stacks on one page mind their own business (measured: the first stays still while the second is hovered).
Accessibility
- Reduced motion: with
prefers-reduced-motion: reduce, the CSS forcestransform: noneon all four panes and the script stops reading the mouse. Measured at the corners of the scene in all three engines: no pane moves. The nesting and the blur are enough to read the four planes. - Keyboard: the stack is decoration, nothing in it takes focus. If you put a link or a button inside a pane,
:focus-withinlifts the stack just as hover does — measured with a link in the front pane: the same 196.6, 171.4 and 144.4 px widths. The slide itself is mouse-only. - Touch: measured in touch emulation (Chromium and WebKit), a tap lifts the stack and it stays lifted until the next tap elsewhere. The browser sends a single
mousemoveper tap, so the panes do not follow a dragging finger. - Contrast: the demo label (80% white, 9.6 px) measures 3.5:1 on the pink pane, below the 4.5:1 threshold. For real text, use solid white, a larger size and a darker pane tint (
rgba(40, 20, 80, .45)for instance). - Screen readers: text is read in HTML order, from the back pane to the front one. Write it in the order it should be heard, or hide purely decorative panes with
aria-hidden="true".
Browser compatibility
Measured with Chromium 149, Firefox 151 and WebKit 26.5: same sizes on hover and on focus, same offsets, same stillness under reduced motion. Two caveats. Depth: Chromium and Firefox do draw the enlarged panes; the test build of WebKit computes the right boxes but paints them flat — real Safari not verified. Blur: checked over a striped background, it is only painted by Chromium in our automated captures; the Firefox and WebKit test builds render the stripes sharp under the glass, which says nothing about the real browsers — not verified. Minimum versions per MDN: inset (Chrome 87, Edge 87, Firefox 66, Safari 14.1), backdrop-filter (Chrome 76, Firefox 103, Safari 18, or 9 with the -webkit- prefix the code also writes).
Without JavaScript you keep everything but the slide: the nesting, the blurs and the hover lift are CSS. Without backdrop-filter the panes become plain tinted veils, still nested. Before inset (Safari 14.0 and older) the panes lose their size: replace it with top, right, bottom, left if you target those versions.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0327-root">
<div class="lg-depth-scene" data-depth-stack>
<div class="lg-depth-bg"></div>
<div class="lg-depth-pane lg-depth-pane-1">…</div>
<div class="lg-depth-pane lg-depth-pane-2">…</div>
<div class="lg-depth-pane lg-depth-pane-3">…</div>
<div class="lg-depth-pane lg-depth-pane-4">…</div>
</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 |
|---|---|---|
Blur of each pane (CSS — .lg-depth-pane-1 to -4, backdrop-filter) |
2, 6, 12 and 18 px | The progression is what makes the depth: 4, 8, 16, 32 px gives a fully frosted centre, 3 px everywhere a stack of clear panes. Change both lines of each pane, prefixed and unprefixed. |
Nesting (CSS — inset of each pane) |
0, 15, 30 and 45 px | 24 px margins leave a strip tall enough for a 13 px line of text. For fewer panes, delete the last one in the HTML along with its rule; the script adapts to however many it finds. |
Travel on hover (CSS — translateZ() and translateY() in the :hover rules) |
0 / 20 / 40 / 60 px towards the screen, 0 / 5 / 10 / 15 px upwards | Double the translateZ values for a stack that opens up boldly; past 240 px the front pane outgrows the scene. Lower perspective (400 px) to exaggerate, raise it (1200 px) to tone down. |
Slide travel (JS — var SHIFT = 5) |
5 px per rank: 5, 10, 15 and 20 px from one edge to the other | 10 makes the mouse-following obvious; 0 removes it and keeps the lift only. A negative value makes the panes run away from the mouse. |
Tints (CSS — background of each pane) |
15% indigo, 20% violet, 25% fuchsia, 30% pink | A single colour at rising opacity gives smoked glass. Stay under 50%: beyond that the pane hides the very blur it produces. |
Backdrop (CSS — .lg-depth-bg) |
indigo → fuchsia gradient, 10 px overhang, 18 px corners | Put an image in it (background: url(…) center / cover) or delete the element to set the stack on your page: the glass then blurs whatever lies underneath. |
Speed (CSS — transition: transform .5s) |
0.5 s, quick start and soft landing | The same duration smooths both the lift and the mouse-following. 0.2 s sticks to the gesture; 0.8 s gives panes that float behind the pointer. |
FAQ
.lg-depth-bg and the steps appear.