Fixed Background (Parallax Style) Hero Template

Add a dynamic, layered feel to your website with this classic fixed-background hero section.

This popular effect is often referred to as a parallax-style effect, creating an illusion of depth by keeping the background image stationary while the foreground content scrolls over it.

A hero section demonstrating a parallax-style fixed background effect.

Get Source Code Preview

About the Fixed Background Hero

The fixed background effect can significantly elevate a website's design. This template achieves the effect using only CSS, making it lightweight, performant, and very easy to implement. It is an excellent choice for storyteller sites, product showcases, and modern portfolios where you want to add a sense of depth without the overhead of JavaScript.

For a true parallax effect, where the background image also scrolls, but at a slower rate than the overlaid content, see the Parallax Scroll Hero.

Features

Code Breakdown

The component is split into CSS for your site's head and HTML for the body. The provided HTML includes a second section below the hero to create enough scrollable space to demonstrate the effect.

The main player in this template is background-attachment: fixed. It's important to note that while this creates a popular parallax-style effect, true parallax involves the background moving at a slower speed, which requires JavaScript. This pure CSS approach "fixes" the background relative to the viewport. As you scroll the page, the section element moves, but its background image stays put. This difference in movement creates the illusion of depth.

This property works in tandem with background-position: center and background-size: cover to ensure the fixed image is well-placed and always covers the background area. The centered text content is layered on top using Flexbox.

Code

View Output