Contact Us | +1 888 239-0733 (Toll free US/CA) Mon-Fri: 7:30am to 4:30pm (PST)

CSS 'background-attachment' Property Explained

Est. Reading: 1 minute
Updated: April 1, 2024

The CSS 'background-attachment' property specifies whether a background image should scroll with the content or be fixed about the viewport. This property can be used to create various effects, such as a parallax scrolling effect or ensuring that a background image remains static as the user scrolls through a webpage.

CSS 'background-attachment' Property Example

See the Pen CSS 'background-attachment' Property by Webzstore (@webzstore) on CodePen.

The 'background-attachment' property offers creative control over how background images interact with page scrolling, allowing for diverse design strategies that can enhance a website's aesthetic and user experience.

Browser Support For 'background-attachment' Property

FirefoxSafariChromeMicrosoft EdgeOpera
1.01.01.04.03.5

CSS Syntax of the 'background-attachment' Property

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

Usage of the 'background-attachment' Property

Use 'background-attachment' to control the scrolling behavior of background images. It's beneficial for adding visual depth to a webpage or creating specific visual effects that enhance the user's experience. For instance, a fixed background image can create a sense of immersion, while a scrollable background can maintain context as content moves.

Property Values of the 'background-attachment' Property

  • Scroll: The default value. The background image scrolls with the rest of the page.
  • Fixed: The background image is fixed with regard to the viewport, creating a parallax effect as the user scrolls.
  • Local: The background image scrolls with the element's contents.
  • Initial: Resets the property to its default value (scroll).
  • Inherit: Inherits this property from its parent element.

Ryan Parker

Ryan has been a standout in digital marketing since 2010. He's the go-to person for getting businesses noticed online, with over 300 projects under his belt—these range from helping local business owners to big online stores. As the Head of Digital Marketing at his company, Ryan knows all the tricks to make companies shine on the internet. He's excellent at using the latest tech and smart strategies to get results. Ryan is all about making businesses grow and reach more people online.

chevron-down