Gallery✨ Premium

Parallax Slider

Depth carousel: while the track slides, each slide's background shifts the other way and moves slower than the title on top of it.

CSSParallaxDepth

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Gallery has 44 effects, including 6 free. Explore the category →

3 usage examples

The three stages of a ridge crossing — top of a mountain guides' website — Parallax Slider example 1

① The three stages of a ridge crossing — top of a mountain guides' website

WhenOn arrival, the visitor clicks ›: the stage name moves off to the left while the mountain ranges behind it slide more slowly, then day 2 and its snowfields take over.
WhyLayered mountain planes are made for parallax: the relief reads in the gap between the title and the landscape, with no video or looping animation. The band stays still until someone clicks.
SettingsFull-width band: --pxsl-width:100%, --pxsl-height:100%, --pxsl-radius:0, dark arrows --pxsl-arrow-bg:rgba(20,22,28,.35), data-slide="étape" ("stage"), default depth (30). Backgrounds as <img class="pxsl-bg">, dark veil under the title added by the page CSS. Capture: click on › every 1.5 s.
Chapters of a children's audiobook — a cover to swipe in the player — Parallax Slider example 2

② Chapters of a children's audiobook — a cover to swipe in the player

WhenIn the player, the child swipes the illustration: the forest leaves, the boat at sunset comes in, and the scenery lags behind the chapter title; the length under the bar switches to the new chapter's.
WhyA finger swipe is all a child needs, and the depth brings a still illustration to life without turning it into a cartoon. There are few chapters, so going back to the start feels natural.
Settings--pxsl-height:186px, --pxsl-ratio:auto, --pxsl-radius:16px, data-depth="40" for a stronger shift, data-slide="chapitre" ("chapter"), no arrows. Capture: the scene sends the real code a pointerdown then a pointerup 120 px further left.
Featured stories in a magazine's drop-down menu — Parallax Slider example 3

③ Featured stories in a magazine's drop-down menu

WhenOpening "Sections", the reader sees a small "Featured" box on the right; a click on › moves from the breathing towers to the return of saffron, with the section and reading time below.
WhyIn a mega menu, the box must catch the eye without moving on its own: the parallax only plays on click, and the sense of relief gives an editorial feel even at 150 px high.
Settings--pxsl-height:150px, --pxsl-ratio:auto, --pxsl-radius:10px, 28 px arrows, data-slide="sujet" ("story"). Backgrounds as <img>, bottom veil to keep the title readable. Capture: click on › every 1.4 s.

How it works

Each .pxsl-slide holds two layers: a .pxsl-bg background wider than the slide (160%, overflowing by 30% on each side) and a .pxsl-caption title in front. On change, the track slides by 100% like an ordinary carousel, and the script also shifts each background by 30% of its own width per step of distance from the visible image, in the opposite direction.

The result: the title crosses the frame at full speed while the landscape behind it only covers about half the way. That speed gap creates the sense of relief. The background has its own transition (0.6 s), slightly longer than the track's (0.5 s), which adds to the lag. The value 30 is set with the frame's data-depth attribute.

The parallax only shows if the background has shapes: a flat colour or a near-uniform gradient slides by unnoticed. The demo backgrounds therefore carry a light disc and slanted stripes. With your photos, use an <img class="pxsl-bg"> (cropped with object-fit: cover) or a <div class="pxsl-bg"> with a background-image; a landscape with ridges or a horizon gives the best result.

Controls: ‹ › arrows, ← → keys while focus is in the frame, horizontal drag of more than 50 px (Pointer Events). After the last view, back to the first. Each .pxsl-carousel is independent, nothing is put on window, and running the script again does nothing (data-pxsl-ready).

Accessibility

  • Decorative backgrounds: the .pxsl-bg layer is scenery only; a background <img> takes alt="", and the information goes in the caption or the slide's text.
  • Roles: role="region" and aria-roledescription="carousel" on the frame, "slide" groups named "2 of 3", hidden slides set to inert + aria-hidden.
  • Announcement and controls: invisible aria-live="polite" area after each change; arrows are real named buttons, white focus ring, ← → keys.
  • Reduced motion: under prefers-reduced-motion: reduce, no sliding and no background shift: the view changes at once. The depth goes, navigation stays.
  • Readability: the white title has a drop shadow; on a light background, add a dark veil under the caption to keep the contrast.

Browser compatibility

About 4 KB of JavaScript. Playwright measurements on 08/11/2026 in Chromium, Firefox and WebKit: two independent carousels, script run twice with no effect, Tab, Enter and →, finger swipe (Chromium, 390 px) and mouse drag, background shift read mid-transition, reduced motion without errors. Minimum versions from @mdn/browser-compat-data 8.1.8; inert sets them.

Chrome 102+✓ Full (measured)
Firefox 112+✓ Full (measured)
Safari 15.5+✓ Full (measured in WebKit)
Edge 102+✓ Full (Chromium engine)
iOS Safari 15.5+✓ Not checked on a real device
Android Chrome 102+✓ Full (Chromium engine)

Without inert, everything works but a link in a hidden view can still be reached by keyboard. Without aspect-ratio (Safari 14), set --pxsl-height. Without JavaScript, the first view shows with its background, with no navigation.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0169-root">
  <div class="pxsl-carousel" role="region" aria-roledescription="carousel" aria-label="Slideshow" data-slide="slide" data-of="of">
    <div class="pxsl-track">
      <div class="pxsl-slide"><div class="pxsl-bg pxsl-bg-1"></div><span class="pxsl-caption">Parallax 1</span></div>
      <div class="pxsl-slide"><div class="pxsl-bg pxsl-bg-2"></div><span class="pxsl-caption">Parallax 2</span></div>
      <div class="pxsl-slide"><div class="pxsl-bg pxsl-bg-3"></div><span class="pxsl-caption">Parallax 3</span></div>
      <!-- one div.pxsl-slide per view; your photo: <img class="pxsl-bg" src="…" alt=""> instead of the background div -->
      <!-- depth: data-depth="30" (optional) on .pxsl-carousel -->
    </div>
    <button type="button" class="pxsl-arrow pxsl-prev" aria-label="Previous slide"><svg>…</svg></button>
    <button type="button" class="pxsl-arrow pxsl-next" aria-label="Next slide"><svg>…</svg></button>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Depth (HTML — data-depth on .pxsl-carousel) 30 Background shift, in % of its width, per slide of distance. 15 for a subtle effect, 40 for strong relief; beyond that, the edge of the background may show.
Background overflow (CSS — inset and size of .pxsl-bg) -30% · 160% If you raise the depth, enlarge the background accordingly so it always covers the slide.
Durations (CSS — --pxsl-duration, --pxsl-bg-duration) 0.5s · 0.6s A background slower than the track strengthens the sense of depth.
Size (CSS — --pxsl-width, --pxsl-ratio, --pxsl-height) 640px · 16 / 10 · auto Maximum width, format and optional imposed height.
Arrows and corners (CSS — --pxsl-arrow-bg, --pxsl-radius) white at 20% · 1rem Darken the arrows over light skies.
Demo backgrounds (CSS — .pxsl-bg-1 to .pxsl-bg-3) gradients with disc and stripes Remove them as soon as you add your images.
Spoken texts (HTML — data-slide, data-of, aria-label) slide · of · Slideshow "stage 2 of 3", "chapter 1 of 3"…

FAQ

The shift is only noticed on shapes: a plain sky or a blurred background slides by with nothing to anchor the eye. Pick images with a horizon, ridges or sharp objects, raise data-depth to 40, or lengthen --pxsl-bg-duration.
Not with this code: the shift depends only on the slide on screen. Scroll-driven parallax is a different effect, in the Scroll category.
Yes, every slide is recomputed on each change: the leaving one slides outwards, the arriving one starts from -30% and comes back to 0. That double movement is what you see in the middle of the transition.