webdevpuneet.com

Rellax Parallax Layers — Free data-rellax-speed Parallax Hero Snippet

Rellax Parallax Layers · Scroll · Plain HTML, CSS & JS · Live preview

Copy & paste

Source Code

Requires
<div class="rlx-hero">
  <div class="rlx-layer rlx-back" data-rellax-speed="-8"></div>
  <div class="rlx-layer rlx-mid" data-rellax-speed="-4">
    <div class="rlx-blob rlx-blob-a"></div>
    <div class="rlx-blob rlx-blob-b"></div>
  </div>
  <div class="rlx-layer rlx-front" data-rellax-speed="2">
    <h1>Depth, from a single attribute</h1>
    <p>Every layer here moves at its own <code>data-rellax-speed</code> as you scroll — Rellax reads the attribute and does the rest.</p>
  </div>
</div>
<div class="rlx-spacer"></div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Attribute-driven depth
data-rellax-speed sets each layer's parallax rate directly in HTML.
Single constructor call
new Rellax(...) wires up every tagged layer at once.
Shared scroll listener
One listener updates all layers, regardless of layer count.
GPU-composited movement
translate3d keeps layer motion smooth and off the main thread.
Pixel rounding
round: true avoids sub-pixel blur on sharp-edged layers.
No dependencies
Rellax has zero external dependencies beyond the browser.
Refreshable offsets
rellax.refresh() recalculates after dynamic layout changes.
Blurred color blobs
A soft gradient blob mid-layer adds atmosphere with pure CSS.

About this UI Snippet

Rellax Parallax Layers — Depth Through data-rellax-speed Attributes

Screenshot of the Rellax Parallax Layers snippet rendered live

Rellax is a dependency-free parallax library built around one idea: instead of writing scroll-math for every layer by hand, you tag elements with data-rellax-speed and let the library translate them proportionally as the page scrolls. This snippet builds a three-layer hero — a gradient backdrop, a pair of blurred color blobs, and an anchored content layer — where the entire depth effect is expressed through three attribute values.

Speed as depth

Each .rlx-layer carries a data-rellax-speed value: -8 on the back gradient, -4 on the mid blob layer, and 2 on the front content. Rellax interprets negative speeds as moving slower than natural scroll (so the element appears to lag behind and read as farther away) and positive speeds as moving faster than natural scroll (so the element appears to rush ahead and read as closer to the viewer). This mirrors the same depth logic used in Parallax Hero Section, but where that snippet computes per-layer factors from mouse position in hand-written JavaScript, Rellax computes them from scroll position automatically once you call new Rellax(...).

One constructor call, many layers

new Rellax('.rlx-layer', { speed: -2, center: false, round: true }) is the entire JavaScript integration — Rellax queries every matching element, reads its own data-rellax-speed (falling back to the speed option when absent), and attaches a single shared scroll listener that updates all of them together. Adding a fourth layer means adding a new element with its own data-rellax-speed attribute — no changes to the JS at all.

round: true and performance

Rellax uses transform: translate3d under the hood so layer movement is GPU-composited, and the round: true option rounds computed pixel offsets to whole numbers, which avoids sub-pixel blurring on layers with sharp edges or text. Because there's a single scroll listener shared across every tagged element rather than one listener per layer, the library stays cheap even with many layers on a busy page.

Rellax versus a custom parallax script

Compared to hand-rolling parallax with lerp smoothing (as in Parallax Hero Section), Rellax trades fine-grained control (easing curves, mouse-driven input, device tilt) for simplicity — it's scroll-only, attribute-driven, and requires no per-project math. It's the right tool when you want several elements drifting at different rates purely from scroll position and don't need mouse interactivity.

Customizing it

Adjust each layer's data-rellax-speed to taste (Rellax typically expects values roughly between -10 and 10), add more blobs or shapes as additional layers, or call rellax.refresh() after dynamic content changes so offset calculations stay accurate. Pair this hero with Hero Section copy patterns or a Gradient Progress indicator below the fold.

Step by step

How to Use

  1. 1
    Add the Rellax CDN scriptInclude rellax.min.js from the CDN panel.
  2. 2
    Paste HTML, CSS, and JSA three-layer hero with a gradient, blobs, and content renders.
  3. 3
    Scroll down slowlyThe back layer drifts slower, the front content drifts slightly faster.
  4. 4
    Compare layer speedsNotice the blobs and headline separate visually as you scroll.
  5. 5
    Change data-rellax-speed valuesIncrease or invert them to intensify or reverse the depth effect.
  6. 6
    Add a new layerAdd an element with its own data-rellax-speed — no JS changes needed.

Real-world uses

Common Use Cases

Landing page heroes
Build a layered hero where each element's depth is one data-rellax-speed attribute, as a lighter alternative to a full parallax hero.
Launch page layered shots
Layer product shots and glow shapes at different speeds, with translate3d keeping the movement composited off the main thread.
Event and conference sites
Add drifting shapes behind a hero section, wiring every tagged layer with one new Rellax() call.
Editorial scene building
Build scroll-driven scenes for editorial and storytelling pages without hand-writing scroll maths for every layer of the illustration.
App marketing combinations
Combine with a scroll reveal grid of features below, while one shared scroll listener updates all parallax layers regardless of count.
Related: Scroll 3D Flip Reveal
See the Scroll 3D Flip Reveal for a related scroll pattern worth pairing with this one.

Got questions?

Frequently Asked Questions

It's a rate relative to normal scroll. A speed of 0 would scroll with the page exactly like any other element. Negative values move the element slower than the page scrolls, so it visually lags behind and reads as farther away; positive values move it faster than the page scrolls, so it visually rushes ahead and reads as closer to the viewer. Rellax typically expects values roughly between -10 and 10 for a natural-looking effect.

The selector passed to new Rellax(selector, options) — '.rlx-layer' in this snippet — is queried once on initialization. Every matching element is then read for its own data-rellax-speed attribute; if an element doesn't have one, it falls back to the speed value in the options object. All matched elements are then updated together on every scroll event via a single shared listener.

Rellax calculates each layer's scroll range based on its position and the document's height at initialization time. If images, web fonts, or other async content change the page's layout height after that initial calculation, the cached offsets can drift out of sync with actual scroll position — calling refresh() recalculates everything against the current, fully-loaded layout.

Rellax works on touch scrolling the same way it works on mouse-wheel scrolling, since it responds to actual scroll position rather than pointer movement — unlike mouse-driven parallax such as Parallax Hero Section. That said, heavy parallax can feel unusual on mobile, so consider reducing speed magnitudes or disabling the effect below a breakpoint for smaller screens.

Install the rellax npm package (or keep the CDN script), import it, and instantiate new Rellax(selector, options) inside a mount effect (useEffect, onMounted, or ngAfterViewInit) after your layered elements have rendered. Keep the data-rellax-speed attributes directly on your JSX/template elements. Call rellax.destroy() in the cleanup function to remove Rellax's scroll listener when the component unmounts.