Gestures & WebcamPremium

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.

WebcamMediaPipeFace tracking3D parallaxCanvas 2D

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

A window with depth behind the headline — launch page of fleet-tracking software for bike rental shops — Head-Tracked Parallax example 1

① A window with depth behind the headline — launch page of fleet-tracking software for bike rental shops

WhenA rental shop owner lands on the version 3 page. Moving the mouse makes the grid room slide behind the headline; the second button offers to look around with their head.
WhyThe depth catches the eye without taking the text's space: the set is pushed right, the headline stays readable, and the camera is only requested if the visitor wants it.
SettingsThe .htp-hero-page variant built into the shipped CSS (the small camera button only appears there to switch it off), data-htp-anchor="right", text block as a data-htp-depth="0.1" layer, secondary button with data-htp-start. Captured with the cursor.
This month's games float behind the glass and follow passers-by — window display screen of a board game shop — Head-Tracked Parallax example 2

② This month's games float behind the glass and follow passers-by — window display screen of a board game shop

WhenOn the screen in the shop window, three of the month's game boxes float at three depths. When someone walks past, their head slides the boxes in front of one another and the staff pick comes to the front.
WhyA window screen is watched on the move: motion that answers the passer-by stops the eye better than a slideshow. The cards are HTML, so the shop swaps its games without touching the drawing.
SettingsThree HTML cards at data-htp-depth −0.7, −0.3 and +0.1; the code's set moves to the background (canvas at 62% opacity, hue shifted by a CSS filter in the scene). A screen without a mouse (pointer-events: none): for the capture, the script sends the scene pointermove events that cross it like a passer-by, and the shipped code turns them into the viewpoint.
Lean over to find the hidden robot — mini-game on the waiting page of a robotics fair — Head-Tracked Parallax example 3

③ Lean over to find the hidden robot — mini-game on the waiting page of a robotics fair

WhenDoors open in twelve minutes. A small robot hides behind a panel: leaning left or right, the visitor sees it come out from behind, and the box says "Robot spotted!".
WhyThe game rests entirely on parallax: the robot, far away, slides one way, the panel, in front of the glass, the other. Ten seconds of play explain the effect better than a paragraph.
SettingsRobot as a data-htp-depth="-2" layer, panel at +0.6, a 302 × 296 px scene that receives pointer moves from the whole section. The page compares where the robot and the panel are (getBoundingClientRect): 70% of the robot visible means a win. With reduced motion the shift is too small to reveal it: add a "Show the robot" button in that case.

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.

Chrome 88+✓ Full (measured)
Firefox 89+✓ Full (measured)
Safari 15+✓ Demo measured · camera not verified
Edge 88+✓ Not verified
iOS Safari 15+✓ Not verified
Android Chrome 88+✓ 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):

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

No. The depth comes from the shift between far and near things, recomputed from the head position: motion parallax, the same thing you notice when moving in front of a window. It works for one person at a time, the one the camera sees; everyone else sees a moving picture.
No. The picture is not displayed (unless you add 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.
Yes: 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.