VOOZH about

URL: https://www.geeksforgeeks.org/css/css-background-attachment-property/

⇱ CSS background-attachment Property - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CSS background-attachment Property

Last Updated : 11 Jul, 2025

The background-attachment property sets whether a background image scrolls with the rest of the page or is fixed. It has three possible values: scroll (default, the image moves with content), fixed (image stays in place), and `local` (image scrolls within the element).

Syntax

background-attachment: scroll|fixed|local|initial|inherit;

Property Value

PropertyDescription
scrollSets the background image to stay fixed relative to the containing element and scroll with the page. Default value.
fixedSets the background image to stay fixed relative to the viewport.
localSets the background image to scroll along with the content of its container element.
initialSets the background-attachment property to its default value.
inheritInherits the property from its parent element.

Example 1: Using background-attachment: scroll

In this example, we are using background-attachment: scroll property.

Output:👁 Image

Example 2: Using background-attachment: fixed

In this example, we are using the background-attachment : fixed property.

Output:👁 Image

Example 3: Using background-attachment: local

In this example, we are using background-attachment: local property.

Output:

👁 Image

Example 4: Using background-attachment: initial

In this example, we are using background-attachment: initial property.

Output:👁 Image

Supported Browsers

The browser supported by background-attachment property are listed below:

Comment