CSS background-attachment Property
Description
The background-attachment property in CSS controls the behavior of a background image with respect to the viewport and the element it is applied to. By default, a background image scrolls along with the content of an element. However, background-attachment allows developers to modify this behavior, giving them the flexibility to create visual effects where the background either remains fixed while the content moves or scrolls in relation to its container. This can be particularly useful for achieving depth and layering effects in web design, such as parallax scrolling or fixed hero sections.
When using background-attachment, the property interacts closely with background-position, which determines the starting point of the image, and background-repeat, which controls whether the image is repeated or tiled. For instance, a fixed background can create a sense of stability behind a scrolling element, but care must be taken to ensure the image aligns properly, especially if it is repeated. Designers often pair background-attachment with responsive considerations to ensure that the fixed image does not create awkward gaps or overflow issues on different screen sizes.
Beyond static layouts, background-attachment can also enhance interactive and dynamic designs. For example, combining it with background-size allows designers to scale the background image while maintaining a fixed position, creating visually engaging effects without the need for complex JavaScript. Additionally, using this property thoughtfully can improve user experience by subtly directing attention, creating visual hierarchy, or emphasizing content sections. Despite its simplicity, background-attachment is a versatile tool for adding depth and polish to modern web pages.
Definition
- Initial value
- scroll
- Applies to
- All elements
- Inherited
- No
- Computed value
- As specified
- Animatable
- No
- JavaScript syntax
- object.style.backgroundAttachment
Interactive Demo
Syntax
background-attachment: <attachment> [ , <attachment> ]*
Values
- scrollBackground image scrolls with the object as the document is scrolled.
- fixedBackground image will not scroll with its containing element, instead remaining stationary within the viewport.
- localBackground image will not scroll with its containing element, but will scroll when the element's content scrolls: it is fixed regarding the element's content.
- inherit
Example
Browser Support
The following information will show you the current browser support for the CSS background-attachment property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
