Copied!
Guide

Parallax scrolling without a library

Parallax is layers moving at different speeds. You can do it with one line of CSS, with a small script, or with the new scroll timelines. Here is each one, and why the classic CSS line fails on phones.

← Blog
Title card: Parallax that works. Preview of the Layered parallax scene element from the Enrichr Library.

December 4, 2026

3 min read3 methods

Parallax scrolling makes layers move at different speeds, so the page seems to have depth. Without a library you have three choices: the CSS property background-attachment: fixed, a small script that shifts each layer with a transform, or CSS scroll-driven animations. The script is the one that works everywhere.

Try it on any site. The free animation library checker shows you which animation libraries actually run on a page (GSAP, Lenis, Framer Motion). Paste a URL, no sign-up for your first lookup.

How do the three compare?

MethodCodeWorks on iPhoneSmooth
background-attachment: fixedOne lineNoRepaints a lot
Transform from scroll positionAbout 20 linesYesYes
CSS scroll-driven animationA few linesCheck current supportYes

What is the script?

<section class="scene">
  <img class="layer" data-speed="-0.3" src="hills-back.svg" alt="">
  <img class="layer" data-speed="-0.15" src="hills-mid.svg" alt="">
  <h2 class="layer" data-speed="0.1">Depth</h2>
</section>
const layers = [...document.querySelectorAll(".layer")];
const calm = matchMedia("(prefers-reduced-motion: reduce)");

function update() {
  if (calm.matches) return;
  for (const el of layers) {
    const box = el.parentElement.getBoundingClientRect();
    if (box.bottom < 0 || box.top > innerHeight) continue;       // off screen
    // distance of the section's centre from the centre of the window
    const d = box.top + box.height / 2 - innerHeight / 2;
    el.style.transform = `translate3d(0, ${d * el.dataset.speed}px, 0)`;
  }
}

let queued = false;
addEventListener("scroll", () => {
  if (queued) return;
  queued = true;
  requestAnimationFrame(() => { queued = false; update(); });
}, { passive: true });
update();

A negative speed makes a layer lag behind the page, which reads as far away. A positive speed makes it move ahead, which reads as close. Measuring from the centre of the window means every layer sits exactly in its designed position when the section is in the middle of the screen.

What is wrong with background-attachment: fixed?

It pins a background image to the window while the section scrolls over it. Two problems: iOS Safari ignores it, and on other browsers it forces the background to be repainted on every scroll frame. It is fine for one decorative section on a desktop-only page. Do not build a whole page on it.

What does the modern CSS version look like?

@supports (animation-timeline: view()) {
  .layer-back {
    animation: lag linear both;
    animation-timeline: view();
  }
  @keyframes lag { from { translate: 0 -60px; } to { translate: 0 60px; } }
}

The animation's progress is tied to the element's journey through the window instead of to time. It runs off the main thread, so it stays smooth even when scripts are busy. Wrap it in @supports so other browsers simply show a still layer.

How do I keep parallax tasteful?

Which finished examples can I copy?

ElementWhat it does
Layered parallax sceneA landscape of hill ridges, a sun and a headline tucked behind the front hill, each moving at its own speed.
Parallax pattern sectionsFull-height sections whose patterned backgrounds drift slower than the page.
Alternate column scrollA three-column image grid where the outer columns slide up and the middle one slides down.
Paper cutout parallaxEight layered SVG paper cutouts that drift with weighted pointer parallax.
Depth map shaderA photo and its depth map drawn by a WebGL shader, so near parts move more than far ones.

All are free in the Enrichr Library. It lists 22 parallax elements in total.

Where to go next

FAQ

How do I make a parallax effect with CSS only?

The old way is background-attachment: fixed on a section with a background image. The modern way is a scroll-driven animation: animation-timeline: view() with keyframes that shift the layer. Check browser support before relying on the second.

Why does parallax not work on iPhone?

iOS Safari does not support background-attachment: fixed on scrolling pages and treats it as a normal background. Use a transform-based parallax instead.

Why is my parallax janky?

Either the work is done directly in the scroll event, or you are changing a property that forces layout or paint, such as top or background-position. Use transform inside requestAnimationFrame.

Is parallax bad for accessibility?

Large parallax movement can cause dizziness and nausea for people with vestibular disorders. Respect prefers-reduced-motion and keep the layers still when it is set.