This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The background-attachment CSS property sets whether a background image's position is fixed within the viewport, or scrolls with its containing block.
background-attachment: scroll;
background-attachment: fixed;
background-attachment: local;
background-attachment: local, scroll;
background-attachment: scroll, local;
<section id="default-example">
<div id="example-element">
London. Michaelmas term lately over, and the Lord Chancellor sitting in
Lincoln's Inn Hall. Implacable November weather. As much mud in the streets
as if the waters had but newly retired from the face of the earth, and it
would not be wonderful to meet a Megalosaurus, forty feet long or so,
waddling like an elephantine lizard up Holborn Hill. London. Michaelmas term
lately over, and the Lord Chancellor sitting in Lincoln's Inn Hall.
Implacable November weather. As much mud in the streets as if the waters had
but newly retired from the face of the earth, and it would not be wonderful
to meet a Megalosaurus, forty feet long or so, waddling like an elephantine
lizard up Holborn Hill.
</div>
</section>
body {
overflow: scroll;
}
#default-example {
height: 600px;
}
#example-element {
max-width: 20rem;
height: 100%;
background:
url("/shared-assets/images/examples/lizard.png") right 3rem top 1rem / 15rem
no-repeat,
url("/shared-assets/images/examples/moon.jpg") center / 10rem;
color: #ff5454;
font-size: 1.5em;
font-weight: bold;
overflow: auto;
padding: 20px;
text-shadow:
0 0 0.6rem black,
0 0 0.6rem black;
}
/* Keyword values */ background-attachment: scroll; background-attachment: fixed; background-attachment: local; /* Global values */ background-attachment: inherit; background-attachment: initial; background-attachment: revert; background-attachment: revert-layer; background-attachment: unset;
The background-attachment property is specified as one of the keyword values from the list below.
fixedThe background is fixed relative to the viewport. Even if an element has a scrolling mechanism, the background doesn't move with the element.
localThe background is fixed relative to the element's contents. If the element has a scrolling mechanism, the background scrolls with the element's contents, and the background painting area and background positioning area are relative to the scrollable area of the element rather than to the border framing them.
scrollThe background is fixed relative to the element itself and does not scroll with its contents. (It is effectively attached to the element's border.)
| Initial value | scroll |
|---|---|
| Applies to | all elements. It also applies to ::first-letter and ::first-line. |
| Inherited | no |
| Computed value | as specified |
| Animation type | discrete |
background-attachment =
<attachment>#
<attachment> =
scroll |
fixed |
local
<p> There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again. </p>
p {
background-image: url("star-solid.gif");
background-attachment: fixed;
}
This property supports multiple background images. You can specify a different <attachment> for each background, separated by commas. Each image is matched with the corresponding <attachment> type, from first specified to last.
<p> There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again. Suddenly she came upon a little three-legged table, all made of solid glass; there was nothing on it except a tiny golden key, and Alice's first thought was that it might belong to one of the doors of the hall; but, alas! either the locks were too large, or the key was too small, but at any rate it would not open any of them. However, on the second time round, she came upon a low curtain she had not noticed before, and behind it was a little door about fifteen inches high: she tried the little golden key in the lock, and to her great delight it fitted! </p>
p {
background-image: url("star-solid.gif"), url("star-transparent.gif");
background-attachment: fixed, scroll;
background-repeat: no-repeat, repeat-y;
}
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
background-attachment |
1 | 12 | 1 | 3.5 | 1 | 18 | 4 | 10.1 | 3.2 | 1.0 | 4.4 | 3.2 |
fixed |
1 | 12 | 2 | 10.5 | 15.43.1–14 | 18 | 4 | 14 | 15.4 | 1.0 | 37 | 15.4 |
local |
1 | 12 | 25 | 10.5 | 15.45–13 | 18 | 25 | 14 | 15.44.2–13If-webkit-overflow-scrolling: touch is set, then local has no effect. |
1.0 | 37 | 15.44.2–13If-webkit-overflow-scrolling: touch is set, then local has no effect. |
multiple_backgrounds |
1 | 12 | 3.6 | 10.5 | 1.3 | 18 | 4 | 11 | 3.2 | 1.0 | 4.4 | 3.2 |
scroll |
1 | 12 | 1 | 15 | 1 | 18 | 4 | 14 | 3.2 | 1.0 | 4.4 | 3.2 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment