Parallax Scroll Hero Template

Add a dynamic, layered feel to your website with this classic parallax scrolling hero section.

This popular effect makes the background image appear to move slower than the foreground content, creating a premium 3D illusion that adds a sophisticated touch to any page.

A hero section demonstrating a parallax scrolling effect.

Get Source Code Preview

About the Parallax Scroll Hero

The parallax effect, where background layers move at different speeds, can significantly elevate a website's design. This template uses a lightweight JavaScript snippet to achieve this effect, creating an engaging and memorable user experience. It is an excellent choice for storyteller sites, product showcases, and modern portfolios where a high-end feel is desired.

Features

Code Breakdown

The component is split into CSS for the head, HTML for the body, and a JavaScript block to be placed just before the closing tag.

In the CSS, unlike simpler methods, we do not use background-attachment: fixed. The background image is applied normally to the .parallax-hero section.

The parallax effect is achieved with the JavaScript. A script listens for the browser's scroll event. Whenever the user scrolls, the script gets the current vertical scroll position (window.pageYOffset). It then multiplies this value by a speed factor (e.g., 0.5 for half-speed). Finally, it dynamically updates the backgroundPositionY of the hero section using this new, smaller value. This continuous, rapid updating of the background position creates the smooth illusion of slower movement.

Code

View Output