CSS background-attachment Property

Description

The background-attachment property determines whether the background image will scroll along with the contents of the element. The image can be fixed and remain motionless, or move together with the document. You can specify multiple values ​​for a series of background images, listing the values ​​separated by commas.

Initial value
scroll
Applies to
All elements
Inherited
No
Computed value
As specified
Animatable
No
JavaScript syntax
object.style.backgroundAttachment

Interactive Demo

The rusty swing set creaked a lonely lullaby in the twilight, shadows lengthening like grasping fingers across the dew-kissed grass. A lone dandelion seed, adrift on the breeze, whispered secrets of faraway fields, of dandelion suns and galaxies spun from fluff. Somewhere, beyond the veil of dusk, a coyote laughed, echoing through the stillness like a forgotten memory.

Syntax

background-attachment: <attachment> [ , <attachment> ]*

Values

<attachment> = scroll | fixed | local
  • 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

<p>Example of the css background-attachment property.</p> 
body { 
   background-image: url(images/diamond.png);
   background-attachment: fixed;
   height: 500px;
} 
p {
   padding: 10px;
   background: white;
   color: black;
}

Browser Support

The following table will show you the current browser support for the CSS background-attachment property.

Desktop
Edge Chrome Firefox Opera Safari
12113.51
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
18410.13.2137

Last updated by CSSPortal on: 1st January 2024