Parallax Depth Layers
Four stepped panels at 0, 30, 60 and 90 px of depth: the stack leans towards the mouse, a finger or the arrow keys, and every panel keeps its label readable.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. 3D has 50 effects, including 8 free. Explore the category →
3 usage examples



How it works
The sensitive area is .pdl-stage, 220 × 160 px, which carries perspective: 1000px. It holds .pdl-scene, in transform-style: preserve-3d, and four .pdl-layer elements set at growing depths with translateZ: 0, 30, 60 and 90 px. Each panel is also smaller and lower than the one behind it — 220 × 160, 188 × 124, 156 × 88 then 124 × 52 px, thanks to inset margins of 24, 48 and 72 px at the top against 12, 24 and 36 px at the bottom. That offset frees a strip at the top of each panel: its label reads there without being covered. The first three are translucent (20% indigo, 30% violet, 40% fuchsia), the front one almost solid (75% pink).
The script (1.9 KB) makes the whole stack lean towards the point you aim at. It turns the pointer's position over the area into two numbers between 0 and 1 and derives two rotations of .pdl-scene, rotateX and rotateY, capped at 12° (MAX_TILT): the side under the pointer comes towards you. Recorded 4 px from the top-right corner: −11.4° and −11.6°. Since the panels are not at the same depth, they do not turn around the same plane: in a corner, the front panel slides some twenty pixels relative to the back one (23 px across, 19 px down, measured). That slide between planes is what gives the relief. A 0.1 s transition softens the tracking; when the pointer leaves, the stack goes flat again.
Three ways to handle it, all in the same script. The mouse, through pointermove. A finger: touch-action: none on the area lets a drag tilt the stack instead of scrolling the page (measured: 9° and −9.4° near the corner, page still), and it flattens when the finger lifts. The keyboard: the area has tabindex="0", each arrow key moves the target point by a tenth, i.e. 2.4° per press, and Escape or losing focus flattens it. The script starts from each .fx-0012-root: two stacks on one page each lean their own way.
Accessibility
- Keyboard: checked in all three engines — Tab brings focus to the area (a 2 px pink
#fda4afoutline, 8 px off), Right twice then Down giverotateX(2.4deg) rotateY(-4.8deg), Escape returns to zero. The area is a group named by anaria-labelwritten in English, to adapt to your page. - Reduced motion: a rule scoped to the root forces
transform: noneon the scene; with the pointer in a corner, the computed transform staysnonein Chromium, Firefox and WebKit. The stack shows face-on and still — and because the panels are stepped, all four labels remain readable. - Touch: mind the flip side of
touch-action: none. A finger resting on the area no longer scrolls the page. At 220 × 160 px that is harmless; if you enlarge the area to the width of a phone, leave room around it for the thumb, or switch totouch-action: pan-y(a vertical drag scrolls again). - Contrast: the front label, bold 13 px white on the 75% pink, measures 4.4:1 — a hair below 4.5:1. Raise the background's opacity to 0.9 or darken it (
#e11d48) if that text matters. Labels on the translucent panels sit on an almost black background: plenty of margin. - Screen readers: the four texts are read from back to front, in HTML order. The tilt carries no information by itself: nothing is hidden from someone who cannot see it.
Browser compatibility
Measurements taken in Chromium 149, Firefox 151 and WebKit 26.5: same angles with mouse and keyboard, back to flat on leaving and on Escape, still stack under reduced motion, two independent copies, no name added to window, no overflow at 320 px. Finger drag measured in Chromium touch emulation. The relief is right in Chromium and Firefox; the WebKit test build does tilt the stack but draws its panels flat, with no offset between them — that test engine flattens CSS 3D, real Safari not verified. Per MDN: pointer events (Chrome 55, Firefox 59, Safari 13), touch-action (Chrome 36, Firefox 52, Safari 13), inset (Chrome 87, Firefox 66, Safari 14.1), :focus-visible (Chrome 86, Firefox 85, Safari 15.4).
Without JavaScript the stack stays face-on: four stepped, readable panels with no tilt. Without inset (Safari 14.0 and earlier) the panels lose their size: write top, right, bottom, left instead if you target those versions. Without 3D transforms the panels show flat, still stepped.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0012-root">
<div class="pdl-stage" tabindex="0" role="group" aria-label="…">
<div class="pdl-scene">
<div class="pdl-layer pdl-layer-1">…</div>
<div class="pdl-layer pdl-layer-2">…</div>
<div class="pdl-layer pdl-layer-3">…</div>
<div class="pdl-layer pdl-layer-4">…</div>
</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 |
|---|---|---|
Maximum tilt (JS — var MAX_TILT = 12) |
12° at the edge of the area, whatever its size | 6° is enough for a detailed image; beyond 20° the text on the panels gets hard to read. |
Depths (CSS — translateZ() of .pdl-layer-2 to -4) |
30, 60 and 90 px | The gap between panels is what makes the slide: 60, 120, 180 px doubles it. A panel brought forward looks bigger; add scale() to the same transform to compensate (0.91 for 90 px under a 1000 px perspective). |
Stepping (CSS — inset of each panel) |
0 · 24px 16px 12px · 48px 32px 24px · 72px 48px 36px |
The first number sets the height of the label strip (24 px). inset: 0 everywhere gives four planes of the same size, for a scene or a cut-out image. |
Colours (CSS — background and border of each panel) |
20% indigo, 30% violet, 40% fuchsia, 75% pink | Translucent panels let the ones behind show through; solid panels read as stacked cards. Each panel can also take a background image. |
Area size (CSS — .pdl-stage { width; height }) |
220 × 160 px | The angle is worked out in proportion to the area: it always reaches MAX_TILT at the edge. The inset margins, however, are in pixels: adjust them if the area changes size a lot. |
Keyboard step (JS — 0.1 in the keydown listener) |
a tenth of the area per press, i.e. 2.4° | 0.25 reaches the edge in two presses; 0.05 gives fine control. Escape and losing focus flatten the stack in every case. |
Perspective and smoothness (CSS — perspective: 1000px, transition: transform .1s ease-out) |
1000 px, 0.1 s | 500 px exaggerates how the panels recede, 2000 px flattens them. 0.3 s gives a stack that follows the pointer with a slight lag. |
FAQ
.pdl-layer inset: 0 and a background-image, with cut-out PNGs or SVGs (transparent background) for the front planes, or cut flat shapes with clip-path as in the book example. Offset the perspective with scale() so that the planes line up when flat.tilt(px, py) function, which expects two numbers between 0 and 1: you can call it from a deviceorientation listener added inside the same loop, mapping the device's angles into that range. On iOS that event requires a permission requested after a user gesture.