3DPremium

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.

JS3DParallax

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

Raised cover of a pop-up book — a children's publisher's website — Parallax Depth Layers example 1

① Raised cover of a pop-up book — a children's publisher's website

WhenPage for a pop-up book for little ones: the blurb and price on the left, the cover on the right. Moving over it, the sky, the hills, the fir trees and the title card shift like the planes of a scene unfolding.
WhyA pop-up book sells on what it does when you open it. A cover that goes into relief under the hand shows that before you even look inside, and the effect's four planes are exactly those of a pull-tab page: background, two cut-out planes, title.
SettingsArea set to 226 × 274 px, the proportions of a cover; the four panels made full-surface (inset: 0, no border) and redrawn — gradient sky, hills and firs in clip-path, title cartouche on the front plane; same depths of 0, 30, 60 and 90 px, with scales of 0.97, 0.94 and 0.91 that offset the perspective so that the planes coincide exactly when flat.
Three paper-cut pictures — shop of a light-box maker — Parallax Depth Layers example 2

② Three paper-cut pictures — shop of a light-box maker

WhenA catalogue of three light boxes: undergrowth, peaks, little harbour. Each thumbnail is a small stack; you hover it — or reach it with Tab then the arrow keys — to look between the sheets.
WhyThese pictures are made of sheets spaced a few millimetres apart in front of a light: a flat photo does not show that. Tilting the thumbnail reveals the gap between the sheets, which is precisely what a buyer wants to check.
SettingsThree roots, one per picture, 116 × 164 px area; back plane in an amber gradient (the light), two sheets pierced with a circle by a radial gradient that is transparent in the centre, a clip-path silhouette on the front plane; full-surface planes with the same compensating scale; focus outline switched to yellow.
Raised-letter sign, previewed as you type — a sign-maker's website — Parallax Depth Layers example 3

③ Raised-letter sign, previewed as you type — a sign-maker's website

WhenA shopkeeper types the text of the sign and picks a finish; on the right, the preview set on a wall. Tilting it shows the letters standing off the plate and their shadow sliding behind them.
WhyLetters mounted on spacers differ from a plain sticker by their shadow, and that shadow only shows when something moves. The effect's planes reproduce the assembly: plate on the wall, shadow, letters, decorative rule.
Settings240 × 136 px area; plane 1: the plate; plane 2: the text in black blurred by 3 px (the shadow); plane 3: the same text in brass; plane 4: a rule. The page's script copies the field into planes 2 and 3, works out the price and switches the finish; for the capture, it types “LE FOURNIL” by itself at the pointer's first move.

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 #fda4af outline, 8 px off), Right twice then Down give rotateX(2.4deg) rotateY(-4.8deg), Escape returns to zero. The area is a group named by an aria-label written in English, to adapt to your page.
  • Reduced motion: a rule scoped to the root forces transform: none on the scene; with the pointer in a corner, the computed transform stays none in 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 to touch-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).

Chrome 87+✓ Full (measured, relief seen)
Firefox 66+✓ Full (measured, relief seen) — dedicated focus ring from 85
Safari 14.1+✓ Not verified on a real Safari (angles measured in WebKit)
Edge 87+✓ Not verified (same engine as Chrome)
Mobile iOS 14.5+✓ Not verified
Android Chrome 87+✓ Measured in emulation: a drag tilts, the page does not scroll

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

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

Very little, to be frank. Both tilt a stack of four planes towards the pointer with the same script, at the same depths and in the same colours; this one leans 12° instead of 10°. The difference is in the layout: Layered Parallax 3D nests three empty frames, shrunk by a scale, around a central badge; here the four panels are stepped and each carries readable text in its strip. Take this one if every plane has something to say, the other for a centred decorative object. If you already own one of the two, a few lines of CSS give you the other.
Give each .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.
Not as supplied: the script only listens to the pointer and the keyboard. Everything goes through the 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.