If a background-image
is specified, the background-attachment
CSS property determines whether that image's position is fixed within the viewport, or scrolls along with its containing block.
Initial value | scroll |
---|---|
Applies to | all elements. It also applies to ::first-letter and ::first-line . |
Inherited | no |
Media | visual |
Computed value | as specified |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
background-attachment: scroll; background-attachment: fixed; background-attachment: local; background-attachment: inherit;
fixed
local
scroll
<attachment>#where
<attachment> = scroll | fixed | local
p { background-image: url("https://mdn.mozillademos.org/files/12057/starsolid.gif"); background-attachment: fixed; }
<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>
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 { background-image: url("https://mdn.mozillademos.org/files/12057/starsolid.gif"), url("https://mdn.mozillademos.org/files/12059/startransparent.gif"); background-attachment: fixed, scroll; background-repeat: no-repeat, repeat-y; }
<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>
Specification | Status | Comment |
---|---|---|
CSS Backgrounds and Borders Module Level 3 The definition of 'background-attachment' in that specification. | Candidate Recommendation | The shorthand property has been extended to support multiple backgrounds and the local value. |
CSS Level 2 (Revision 1) The definition of 'background-attachment' in that specification. | Recommendation | No significant change. |
CSS Level 1 The definition of 'background-attachment' in that specification. | Recommendation | No significant change |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Servo |
---|---|---|---|---|---|---|---|
Basic Support | 1.0 | 12 | 1.0 | 4 | 3.5 | 1.0 | ? |
Multiple backgrounds | 1.0 | 12 | 3.6 | 9.0 | 10.5 | 1.3 | ? |
local | 1.0 | 12 | 25 | 9.0 | 10.5 | 5.0 | ? |
Feature | Android | Chrome for Android | Edge Mobile | Firefox for Android | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | 1.0 | (Yes) | 10.0 | 3.2 |
Multiple backgrounds | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | 10.0 | 3.2 |
local | ? | (Yes) | (Yes) | 25 | (Yes) | ? | ? |
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment