CSS-Only Parallax Perspective Section — Pure CSS Depth
CSS-Only Parallax Perspective Section · Scroll · Plain HTML, CSS & JS · Live preview
About this UI Snippet
CSS-Only Parallax Perspective Section — Depth Effect With Zero Scroll JavaScript

Most scroll parallax effects rely on a JavaScript scroll listener recalculating transforms on every frame. This snippet gets the same layered depth using only CSS: perspective, transform-style: preserve-3d and translateZ(). The browser's own 3D projection does the work while the box scrolls, so there is no scroll listener at all. Three depths move at three speeds: a star field at one third, coloured glows at one half, and the content cards at full speed.
Perspective on the scroll container
The trick starts on .pp-container, the scrollable element itself: perspective: 1px combined with overflow-y: scroll puts the whole scrolling area into a very shallow 3D space. With such a small perspective, anything pushed backward in Z moves much less on screen per pixel of scroll than content at Z 0. That difference is the parallax, and the browser computes it as part of normal 3D rendering.
Pushing a layer back and scaling it to compensate
The glow layer uses transform: translateZ(-1px) scale(2). One pixel back at a 1px perspective halves its apparent size and its scroll speed; scale(2) restores the size, but not the speed. The star layer uses translateZ(-2px) scale(3), which shrinks it to a third and moves it at a third of the speed, then scales it back up. The general rule is scale = 1 + depth / perspective.
One strip per depth, not one per section
A common version of this technique gives every section its own background layer. That layer then drifts half a section into its neighbours, so the next scene's background slides over the current card, and you cannot clip it: overflow, clip-path and mask all flatten the 3D and kill the effect. This snippet avoids the problem by putting one continuous strip per depth behind all the scenes, inside a single preserve-3d track. The glow strip holds three radial gradients placed so that each scene's colour sits centred when that scene snaps into view, and the colours blend into each other in between. Because the cards and layers share one 3D context, the cards at Z 0 are always drawn in front of the layers behind them.
Sizing the strips
A layer moving at a fraction of scroll speed has to be taller than one screen to stay behind the viewport for the whole scroll. With three scenes, the glow strip is two container heights tall and the star strip five thirds; both formulas use a --pp-scenes variable. There is one catch: Chromium counts a layer's scaled-up size (before the perspective shrinks it) as scrollable area, which would add a blank screen after the last scene. Setting perspective-origin to the bottom edge and anchoring the strips to the bottom of the track with transform-origin: 50% 100% makes all that extra size grow upward, and overflow above the start of a scroll box is never scrollable. The scenes use scroll-snap so each one lands exactly where its glow is centred.
Zero scroll-linked JavaScript
The JS panel is empty apart from a comment. There is no scroll listener, no requestAnimationFrame loop and no per-frame style work, so there is nothing to throttle and no scroll jank to fight.
What's included
Features
Step by step
How to Use
- 1Paste the HTML and CSSNo JavaScript or library is needed. The demo is a full-viewport scroll box with three scenes.
- 2Scroll inside the boxStars drift at a third of the speed, the coloured glows at half, and the cards at full speed. Each scene snaps into place.
- 3Change the coloursEdit the three radial-gradient lines in .pp-glows. Their 25%, 50% and 75% positions line up with scenes one, two and three.
- 4Add or remove scenesAdd a .pp-group, then set --pp-scenes to the new count (the strip insets follow from it), and re-space the glow gradients at k / (scenes + 1): for four scenes 20%, 40%, 60% and 80%.
- 5Use it on a full pageThe demo already fills the viewport (--pp-h is 100dvh). To use it as a smaller block inside a page, set --pp-h to a fixed height such as 520px; the technique works in any scroll container.
Real-world uses
Common Use Cases
translateZ and scale compensation, including the leak problem and how a shared preserve-3d track solves it.Got questions?
Frequently Asked Questions
The scrollable container has a 1px CSS perspective. Layers are pushed back in 3D with translateZ and scaled up to their normal size again. In perspective projection, something further back moves less on screen when the content scrolls, so the layers trail behind the cards. The browser computes this as part of rendering, with no JavaScript involved.
Moving an element 1px back in a 1px perspective space halves how big it looks. scale(2) brings it back to full size. The scale does not change the slower scroll speed, which is the parallax itself. For any depth the rule is scale = 1 + depth / perspective, which is why the star layer at -2px uses scale(3).
A per-section layer moving at half speed drifts half a section into the next one, so a neighbouring scene's background covers the bottom half of the current card. Clipping each section with overflow, clip-path or mask would fix the leak but flattens the 3D, which turns the parallax off. One continuous strip per depth behind all scenes has no edges to leak, and the colours for each scene are placed along it.
Yes. Replace the gradients on .pp-glows with a tall image (background-size: cover; background-position: center). Remember that the strip spans all scenes, so a single tall illustration or a vertical image collage works best.
Copy & paste
Source Code
<div class="pp-container" id="ppContainer">
<div class="pp-track">
<div class="pp-layer pp-stars" aria-hidden="true"></div>
<div class="pp-layer pp-glows" aria-hidden="true"></div>
<section class="pp-group">
<div class="pp-foreground">
<span class="pp-eyebrow">Scene One</span>
<h2>Pure CSS Depth</h2>
<p>Scroll inside this box. No scroll-linked JavaScript at all.</p>
</div>
<span class="pp-scrollcue">Scroll ↓</span>
</section>
<section class="pp-group">
<div class="pp-foreground">
<span class="pp-eyebrow">Scene Two</span>
<h2>Perspective & TranslateZ</h2>
<p>The glow layer sits 1px behind the cards and moves at half speed. The stars sit 2px back and move at a third.</p>
</div>
</section>
<section class="pp-group">
<div class="pp-foreground">
<span class="pp-eyebrow">Scene Three</span>
<h2>Zero Scroll Listeners</h2>
<p>The browser's own 3D projection creates the depth while you scroll.</p>
</div>
</section>
</div>
</div>*{box-sizing:border-box}
html,body{height:100%;margin:0;background:#0b0d14}
body{font-family:system-ui,-apple-system,sans-serif}
.pp-container{
/* every scene is exactly one container-height tall, so a snapped scene lines up with its glow.
Fills the viewport; dvh keeps it exact when mobile browser bars show and hide. */
--pp-h:max(100vh,420px);
--pp-h:max(100dvh,420px);
--pp-scenes:3;
height:var(--pp-h);overflow-y:scroll;overflow-x:hidden;
/* the tiny perspective is what makes layers pushed back in Z scroll slower.
Origin at the BOTTOM edge: the scaled-up layers then only grow upward,
where overflow is never scrollable, so there is no blank space after the last scene. */
perspective:1px;perspective-origin:50% 100%;
background:#0b0d14;
scroll-snap-type:y mandatory;
scrollbar-width:thin;scrollbar-color:#4338ca #0b0d14;
}
.pp-container::-webkit-scrollbar{width:8px}
.pp-container::-webkit-scrollbar-track{background:#0b0d14}
.pp-container::-webkit-scrollbar-thumb{background:#4338ca;border-radius:99px}
/* One shared 3D context for every layer and every card: the cards (z 0) are
always depth-sorted in front of the layers, so no layer can paint over a card. */
.pp-track{position:relative;transform-style:preserve-3d}
/* Each layer is one continuous strip behind ALL scenes, centred on the track.
A strip per scene would leak half a scene into its neighbours (and can't be
clipped without flattening the 3D), so one strip it is. */
.pp-layer{position:absolute;left:0;right:0;bottom:0;transform-origin:50% 100%;pointer-events:none}
/* 1px back, scale 2: moves at 1/2 speed. To cover the view for the whole
scroll it is (scenes + 1) / 2 container heights tall, anchored to the bottom.
Scene k's glow sits at k / (scenes + 1) of the strip: 25%, 50%, 75% for 3. */
.pp-glows{
height:calc(var(--pp-h) * (var(--pp-scenes) + 1) / 2);
transform:translateZ(-1px) scale(2);
background:
radial-gradient(70% 26% at 30% 25%,rgba(67,56,202,.95),transparent 72%),
radial-gradient(70% 26% at 70% 50%,rgba(190,24,93,.9),transparent 72%),
radial-gradient(70% 26% at 40% 75%,rgba(14,116,144,.95),transparent 72%);
}
/* 2px back, scale 3: moves at 1/3 speed, (scenes + 2) / 3 heights tall. */
.pp-stars{
height:calc(var(--pp-h) * (var(--pp-scenes) + 2) / 3);
transform:translateZ(-2px) scale(3);
opacity:.55;
background:
radial-gradient(1.2px 1.2px at 20px 30px,#fff,transparent),
radial-gradient(1px 1px at 90px 80px,#c7d2fe,transparent),
radial-gradient(1.4px 1.4px at 150px 20px,#fff,transparent),
radial-gradient(1px 1px at 60px 140px,#a5f3fc,transparent),
radial-gradient(1.2px 1.2px at 170px 120px,#fbcfe8,transparent);
background-size:190px 170px;
}
.pp-group{
position:relative;height:var(--pp-h);
display:flex;align-items:center;justify-content:center;
scroll-snap-align:start;
}
.pp-foreground{
/* No backdrop-filter: inside a preserve-3d context it makes Chromium drop the element. */
position:relative;
text-align:center;color:#fff;padding:28px 32px;max-width:440px;margin:0 16px;
background:rgba(11,13,20,.62);border:1px solid rgba(255,255,255,.1);
border-radius:18px;
box-shadow:0 24px 60px -20px rgba(0,0,0,.6);
}
.pp-eyebrow{display:inline-block;font-size:11px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;color:#c7cbe0;background:rgba(255,255,255,.08);padding:4px 12px;border-radius:99px;margin-bottom:14px}
.pp-foreground h2{font-size:clamp(22px,4vw,34px);font-weight:800;margin:0 0 10px;letter-spacing:-.02em}
.pp-foreground p{font-size:14px;color:#dfe1ee;margin:0;line-height:1.6}
.pp-scrollcue{
position:absolute;bottom:18px;left:50%;
transform:translateX(-50%);font-size:11px;font-weight:600;letter-spacing:.1em;
text-transform:uppercase;color:rgba(255,255,255,.55);
animation:pp-bounce 1.8s ease-in-out infinite;
}
@keyframes pp-bounce{0%,100%{transform:translateX(-50%)}50%{transform:translate(-50%,6px)}}
@media (prefers-reduced-motion:reduce){.pp-scrollcue{animation:none}}// Intentionally empty: the parallax is pure CSS.
// .pp-container has perspective:1px, and the layers inside the shared
// preserve-3d .pp-track are pushed back with translateZ and scaled up to
// compensate, so the browser's 3D projection makes them scroll slower than
// the cards. No scroll listener or requestAnimationFrame loop is needed.Extend with AI
Take This Snippet Further With AI
You do not need to work out the 3D maths of CSS parallax on your own. Paste this snippet's HTML and CSS into an AI assistant like Claude and ask it to explain why the layers are one long strip instead of one per section, or how the scale and inset values follow from the translateZ depth. It can also help you extend it: add a fourth depth with floating shapes, turn the scenes into a full-page landing section with real copy and buttons, swap the glows for a tall illustrated background, or add a fallback for browsers where you want the effect turned off.
Prompt to recreate it
Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:
Build a CSS-only scroll parallax section in plain HTML and CSS, with no JavaScript.
Requirements:
- A scroll container that fills the viewport (a CSS variable, 100dvh with a 420px minimum, page background matching), overflow-y: scroll, perspective: 1px, perspective-origin 50% 100% (bottom edge, so the scaled layers only overflow upward and add no blank scroll space), a dark background and scroll-snap-type: y mandatory.
- Inside it, one track element with transform-style: preserve-3d that holds both the background layers and three full-height scenes, so every card and layer shares one 3D context and the cards are always drawn in front.
- Do not give each scene its own background layer (it would leak into neighbouring scenes and cannot be clipped without flattening the 3D). Instead use one continuous absolutely positioned strip per depth, centred on the track.
- Layers are anchored with bottom: 0 and transform-origin: 50% 100%.
- Glow strip: translateZ(-1px) scale(2), (scenes + 1) / 2 container heights tall, with three radial gradients (indigo, pink, teal) at 25%, 50% and 75% of its height so each scene's colour is centred when that scene snaps into view.
- Star strip: translateZ(-2px) scale(3), (scenes + 2) / 3 container heights tall, a repeating pattern of tiny radial-gradient dots at reduced opacity.
- Each scene is one container-height tall with scroll-snap-align: start and a centred translucent card (eyebrow label, heading, short text). Do not use backdrop-filter on the cards.
- A bouncing "Scroll" cue on the first scene, with the animation turned off under prefers-reduced-motion.Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.