How to Create a Parallax Scrolling Effect With CSS Only (No JavaScript)
A CSS parallax effect happens when the background of a page moves slower than the content in front of it while you scroll, which tricks the eye into seeing depth on a flat screen. Most tutorials solve this with a JavaScript library that listens to every scroll event, recalculates positions and quietly destroys your Interaction to Next Paint score. See geeksforgeeks.org for their take. You do not need any of that. In 2026, the browser can handle parallax natively with three techniques: background-attachment, 3D transforms with perspective and transform-style, and scroll-driven animations. This guide gives you working code for each one, plus the mobile fallbacks and accessibility rules that almost every other tutorial skips. The three CSS-only parallax methods compared Method Best for Difficulty Support Performance background-attachment: fixed Hero banners, section dividers Beginner Universal on desktop, broken on iOS Can trigger repaints on large images 3D transforms (perspective + translateZ) Multi-layer scenes, different speeds per layer Intermediate Every modern browser Excellent, GPU composited Scroll-driven animations (animation-timeline) Precise control, any property, modern sites Intermediate Chromium, Safari 26+, Firefox (recent versions) Excellent, runs off the main thread Method 1: the two-line parallax hero with background-attachment This is the fastest way to get a parallax hero online. The background image stays locked to the viewport while the section scrolls over it, so the image appears to move slower than the page. HTML <section class=”parallax-hero”> <div class=”parallax-hero__content”> <h1>Build faster interfaces</h1> <p>No JavaScript, no scroll listeners, no layout thrashing.</p> </div> </section> <section class=”content”> <p>Your regular page content goes here.</p> </section> CSS .parallax-hero { min-height: 100svh; display: grid; place-items: center; background-image: linear-gradient(rgba(0,0,0,.45), rgba(0,0,0,.45)), url(“/img/hero-1920.webp”); background-size: cover; background-position: center; background-repeat: no-repeat; background-attachment: fixed; } .parallax-hero__content { color: #fff; text-align: center; max-width: 40rem; padding: 2rem; } /* Fallback: iOS Safari and touch devices */ @media (max-width: 768px), (hover: none) and (pointer: coarse) { .parallax-hero { background-attachment: scroll; } } /* Accessibility: respect motion preferences */ @media (prefers-reduced-motion: reduce) { .parallax-hero { background-attachment: scroll; } } Why the fallback matters: iOS Safari has never implemented background-attachment: fixed the way desktop browsers do. Without the media query above, the image is scaled to the full document height and looks zoomed in or jumps as the address bar collapses. Switching to scroll on touch devices gives you a clean static background instead of a broken one. Bonus: a parallax content divider The same idea works beautifully as a narrow band between two text sections. Keep it short so the page keeps its rhythm. .parallax-divider { min-height: clamp(220px, 45vh, 420px); background-image: url(“/img/divider-1600.webp”); background-size: cover; background-position: center; background-attachment: fixed; display: grid; place-items: center; } .parallax-divider blockquote { color: #fff; font-size: clamp(1.25rem, 3vw, 2rem); text-shadow: 0 2px 12px rgba(0,0,0,.6); max-width: 45ch; text-align: center; } @media (max-width: 768px), (prefers-reduced-motion: reduce) { .parallax-divider { background-attachment: scroll; } } Method 2: true multi-layer parallax with perspective and transform-style If you want several layers moving at different speeds (a sky, mountains, trees, foreground text), background-attachment is not enough. The classic pure CSS solution uses a 3D scene: you push layers away from the camera on the Z axis, and because they are further away, they appear to move slower when the scroller moves. The math you need When you push an element back with translateZ, it also shrinks. You compensate with scale(): scale = 1 + (translateZ * -1) / perspective perspective: 10px and translateZ(-10px) gives scale(2) and a layer moving at roughly half speed perspective: 10px and translateZ(-20px) gives scale(3) and a layer moving at roughly one third speed translateZ(0) means normal speed, which is your foreground HTML <div class=”parallax”> <section class=”parallax__group”> <div class=”parallax__layer parallax__layer–back”> <img src=”/img/mountains.webp” alt=”” width=”1920″ height=”1080″> </div> <div class=”parallax__layer parallax__layer–base”> <h1>Depth without a single line of JS</h1> </div> </section> <section class=”parallax__group parallax__group–plain”> <p>Normal scrolling content.</p> </section> </div> CSS .parallax { height: 100svh; overflow-x: hidden; overflow-y: auto; perspective: 10px; perspective-origin: 0 0; /* keeps native scroll snapping and momentum intact */ scroll-behavior: smooth; } .parallax__group { position: relative; height: 100svh; transform-style: preserve-3d; } .parallax__layer { position: absolute; inset: 0; transform-origin: 0 0; } .parallax__layer–back { transform: translateZ(-10px) scale(2); z-index: 1; } .parallax__layer–base { transform: translateZ(0); z-index: 2; display: grid; place-items: center; color: #fff; } .parallax__layer img { width: 100%; height: 100%; object-fit: cover; } @media (prefers-reduced-motion: reduce) { .parallax { perspective: none; } .parallax__layer–back { transform: none; } } Things to watch with the 3D method The scroll container is the element with perspective, not the body. Anchor links, sticky headers and position: fixed elements behave differently inside it, so test your navigation. Stacking order is controlled by z-index inside each group. A layer pushed back on Z will still paint above another layer if its z-index is higher. Do not nest transforms on parents. Any ancestor with its own transform, filter or will-change creates a new containing block and flattens your 3D scene. Method 3: scroll-driven animations, the modern way Scroll-driven animations are the cleanest option available today. You write a normal @keyframes rule and then tell the browser to drive it with scroll progress instead of time, using animation-timeline. The animation runs on the compositor, so it does not block the main thread the way a JavaScript scroll handler does. Parallax hero with view() @keyframes parallax-shift { from { transform: translate3d(0, -12%, 0); } to { transform: translate3d(0, 12%, 0); } } .hero { position: relative; min-height: 100svh; overflow: hidden; isolation: isolate; } .hero__bg { position: absolute; inset: -15% 0; z-index: -1; background: url(“/img/hero-1920.webp”) center / cover no-repeat; } @supports (animation-timeline: view()) { .hero__bg { animation: parallax-shift linear both; animation-timeline: view(); animation-range: cover 0% cover 100%; } } @media (prefers-reduced-motion: reduce) { .hero__bg { animation: none; } } Whole-page background driven by scroll() Use scroll() when you want an element to react to the progress of the nearest scroller rather than its own visibility. @keyframes drift { to { background-position: center 70%; } } .page-bg { position: fixed; inset: 0; z-index: -1; background: url(“/img/texture.webp”) center 30% / cover no-repeat; animation: drift linear both; animation-timeline: scroll(root block); } Wrapping the rules in
How to Create a Parallax Scrolling Effect With CSS Only (No JavaScript) Read More »









