Head-Tracked Parallax
The screen becomes a pane of glass: as visitors move their head in front of the webcam, the 3D room behind it and your own text blocks shift as if seen through a real window. Without a camera, the cursor stands in for the head.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Gestures & Webcam has 11 effects, all premium. Explore the category →
3 usage examples



How it works
Nothing is drawn on the visitor, and their image is not even shown. The face detector serves one purpose: knowing where they are looking from. The midpoint of the outer eye corners gives the head position; the gap between the eyes, compared with the one measured during the first 0.6 seconds, tells whether they leaned in or back. A One Euro filter strips the detection jitter, then smoothing eases the viewpoint into place.
That viewpoint sits in front of the screen, 1.5 scene widths away. Every object has a depth: negative behind the glass, positive in front. It is drawn where the ray from the eye to the object crosses the screen (s = e + (p − e) · ez / (ez − z)). That is why far things slide with the head and near things the other way: the brain reads it as depth, with no glasses and no WebGL.
The bundled set is a grid room 1.7 widths deep, six dashboard cards, two rings, four light points and 140 dust specks, 40 of them in front of the glass on a second canvas laid over the text. Your HTML elements marked data-htp-depth follow the same formula through a plain translate3d: text stays crisp and selectable. Travel is capped at 28% of the width and 22% of the height.
With the camera off, the cursor position over the scene plays the head; with no cursor, the viewpoint drifts along a slow automatic path. The captures on this page are made that way, with the shipped code. If the face leaves the frame, the viewpoint holds for 0.8 s, then glides back to the centre.
Accessibility
- Decoration, not content: both canvases and the video are hidden from assistive technology. Text you place in depth remains ordinary HTML, read in document order whether the head moves or not.
- Keyboard: the effect adds one tab stop, the camera button (plus any button you mark
data-htp-start), on Enter or Space. Depth cannot be driven from the keyboard: nothing it reveals should be essential, unless you offer another route as the third example does. - Reduced motion: no automatic path, no drifting dust or moving charts in the cards, and the shift drops to 30% of its normal range. The scene holds still as long as the head, or the cursor, does.
- Comfort: no flicker, no jump. The viewpoint is always eased, and the capped range keeps a small head movement from rocking the whole page.
- Touch: dragging horizontally moves the viewpoint, vertically the page scrolls. A tap does nothing in particular. Tried by emulating a finger in Chromium, Firefox and WebKit, not on a real phone.
Browser compatibility
Canvas 2D (two layers) and CSS transforms, 46 KB of JavaScript and 13 KB of CSS unminified. Under Firefox 151, Chromium 149 and WebKit 26.5, two copies placed on one page each move with the cursor hovering them, the demo makes no request and rendering pauses off screen. Simulated webcam in Chromium and Firefox: four files from two domains on the first click, then one MediaPipe usage record per minute (see the FAQ). A test video let the detector find the face; face positions injected into the shipped code confirmed the shift left and right, leaning in and back, and the return to centre when the face disappears. Safari: camera not verified.
aspect-ratio sets the minimum versions. Camera refused, missing or busy, or model unreachable: the status pill says so and the cursor keeps playing the head. No face found for 2.5 s: "No face detected", with a lighting tip. Without JavaScript the set is not drawn and your HTML layers stay in place, unshifted. On click, the browser asks for webcam access (https page); the camera turns off when the scene leaves the screen or the tab is hidden.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0853-root">
<div class="htp-scene" data-htp-lang="en" role="region" aria-label="Head-Tracked Parallax — the scene becomes a 3D window that follows your point of view. Cursor demo, camera on request (processed on your device only)">
<video class="htp-video" playsinline muted autoplay aria-hidden="true" tabindex="-1"></video>
<canvas class="htp-canvas" aria-hidden="true"></canvas>
<div class="htp-bar">
<button class="htp-btn htp-cam-btn" type="button" aria-pressed="false">
<span class="htp-btn-ico" aria-hidden="true"></span><span class="htp-btn-txt">Turn camera on</span>
</button>
<p class="htp-track"><span class="htp-track-dot" aria-hidden="true"></span>Head tracking on</p>
<p class="htp-privacy">No image ever leaves your device.</p>
</div>
<p class="htp-status" role="status" aria-live="polite"></p>
<div class="htp-vignette" aria-hidden="true"></div>
<div class="htp-hero htp-layer" data-htp-depth="0.12">
<p class="htp-eyebrow">2026 edition</p>
<p class="htp-title">HORIZON</p>
<p class="htp-tagline">The page becomes a window.</p>
</div>
<canvas class="htp-front" aria-hidden="true"></canvas>
<div class="htp-label" aria-hidden="true">
<span>Head-Tracked Parallax</span>
<span class="htp-hint">move the cursor · or turn the camera on</span>
</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 |
|---|---|---|
Your HTML layers (HTML — data-htp-depth) |
0.12 for the bundled title | Depth in scene widths: negative behind the glass (slides with the head), positive in front (slides the other way). Stay below 1.5 in front of the glass, the resting eye distance. |
Set to the right of the text (HTML — data-htp-anchor="right") |
centred | Pushes the room and its objects to the right; in portrait, upwards. |
Camera picture (HTML — data-htp-thumb) |
hidden | Shows the feed as a small thumbnail to help visitors face the camera. |
Buttons that start the camera (HTML — data-htp-start) |
none | Any button in the scene can switch the camera on, like the second button of the .htp-hero-page variant. |
Range (JS — AMP_X, AMP_Y, GAIN) |
0.28, 0.22, 1.5 | Maximum viewpoint travel as a fraction of the scene, and the share of the camera image to cover to reach it (a third of the width with 1.5). |
Distance (JS — EZ0, LEAN_MIN, LEAN_MAX) |
1.5, 0.74, 1.32 | Eye-to-screen distance in scene widths, and the limits of the lean-in and lean-back effect. A lower EZ0 strengthens the depth. |
Set (JS — CARDS, RINGS, ORBS, ROOM_D) |
6 cards, 2 rings, 4 points, 1.7-deep room | Each object has its resting position, size and depth z. Empty these arrays to keep only your HTML layers. |
Texts (JS — TEXT, TEXT_EN) |
French, English with data-htp-lang="en" |
Camera and status pill messages. |
FAQ
data-htp-thumb) and never leaves the browser: detection runs on the device and the effect keeps only three numbers from it, horizontal position, vertical position and eye gap. Nothing identifies the person. The only thing that goes out, once a minute while detection runs, is a usage statistic the MediaPipe library sends to Google (odml.pa.googleapis.com: version, processing times), with no image and no eye position; remember to list it in your privacy policy.scene.htpBase.effect.eye holds x and y, from −1 to 1, and lean, the relative distance. To know what is actually visible, the safest way is to compare the on-screen positions of your layers, as the mini-game in the third example does.