background-attachment
Quick Summary for background-attachment
The background-attachment CSS property sets whether a background image's position is fixed within the viewport, or scrolls with its containing block.
Code Usage for background-attachment
/* Keyword values */ background-attachment: scroll; background-attachment: fixed; background-attachment: local;  /* Global values */ background-attachment: inherit; background-attachment: initial; background-attachment: revert; background-attachment: unset; 
More Details for background-attachment

background-attachment

The background-attachment CSS property sets whether a background image's position is fixed within the viewport, or scrolls with its containing block.

Syntax

/* Keyword values */ background-attachment: scroll; background-attachment: fixed; background-attachment: local;  /* Global values */ background-attachment: inherit; background-attachment: initial; background-attachment: revert; background-attachment: unset; 

The background-attachment property is specified as one of the keyword values from the list below.

Values

fixed

The background is fixed relative to the viewport. Even if an element has a scrolling mechanism, the background doesn't move with the element. (This is not compatible with background-clip: text.)

local

The 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.

scroll

The background is fixed relative to the element itself and does not scroll with its contents. (It is effectively attached to the element's border.)

Formal definition

Initial valuescroll
Applies toall elements. It also applies to ::first-letter and ::first-line.
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

<attachment>#

where <attachment> = scroll | fixed | local

Examples

Simple example

HTML
<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> 
CSS
p {   background-image: url("starsolid.gif");   background-attachment: fixed; } 
Result

Multiple background images

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.

HTML
<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> 
CSS
p {   background-image: url("starsolid.gif"),       url("startransparent.gif");   background-attachment: fixed, scroll;   background-repeat: no-repeat, repeat-y; } 
Result

Specifications

Specification
CSS Backgrounds and Borders Module Level 4 # the-background-attachment

See also

Using multiple backgrounds

Last modified: Aug 12, 2021, by MDN contributors

Select your preferred language English (US)DeutschEspañolFrançais日本語한국어PolskiPortuguês (do Brasil)Русский中文 (简体)正體中文 (繁體) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better. You won't believe what you can accomplish by attempting the impossible with the courage to repeatedly fail better.
Unknown
Random CSS Property

border-end-end-radius

The border-end-end-radius CSS property defines a logical border radius on an element, which maps to a physical border radius that depends on the element's writing-mode, direction, and text-orientation. This is useful when building styles to work regardless of the text orientation and writing mode.
border-end-end-radius css reference