CSS | background-attachment Property
The property background-attachment property in CSS is used to specify the kind of attachment of the background image with respect to its container. It can be set to scroll or remain fixed. It can be applied to all HTML elements.
Syntax:
background-attachment: scroll|fixed|local|initial|inherit;
Property:
scroll: It sets the background image to get fixed at its position with respect to the containing element and scroll with the page. It is the default value.
- Syntax:
background-attachment: scroll;
- Example:
<!DOCTYPE html><html><head><title>background-attachment property</title><style>#example {background-image:background-position: center;background-repeat: no-repeat;background-attachment: fixed;}</style></head><bodystyle="text-align:center"><h1>GeeksforGeeks</h1><h2> background-attachment: scroll;</h2><br><br><divid="example"><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful.</p><br><br><br><p>This course is especially designed for theJava apprentices who want to hone theirskills in Java for Coding Interviews andCompetitive Programming. No matter if youare a school student or college student,if you have the zeal of programming, thisis the right time to start.</p><br><br><br><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful</p><br><br><br><p>This course is especially designed for theJava apprentices who want to hone theirskills in Java for Coding Interviews andCompetitive Programming. No matter if youare a school student or college student,if you have the zeal of programming, thisis the right time to start.</p><br><br><br><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful</p></div></body></html>chevron_rightfilter_none - Output:

fixed: This property is used to set the background image to fixed at its position with respect to the viewport.
- Syntax:
background-attachment: fixed;
- Example:
<!DOCTYPE html><html><head><title>background-attachment property</title><style>#example {background-image:background-position: center;background-repeat: no-repeat;background-attachment: fixed;}</style></head><bodystyle="text-align:center"><h1>GeeksforGeeks</h1><h2> background-attachment: fixed;</h2><br><br><divid="example"><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful.</p><br><br><br><p>This course is especially designed for theJava apprentices who want to hone theirskills in Java for Coding Interviews andCompetitive Programming. No matter if youare a school student or college student,if you have the zeal of programming, thisis the right time to start.</p><br><br><br><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful</p><br><br><br><p>This course is especially designed for theJava apprentices who want to hone theirskills in Java for Coding Interviews andCompetitive Programming. No matter if youare a school student or college student,if you have the zeal of programming, thisis the right time to start.</p><br><br><br><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful</p></div></body></html>chevron_rightfilter_none - Output:

local: This property is used to set the background image to scroll along with the content of its container element instead of the page.
- Syntax:
background-attachment: local;
- Example:
<!DOCTYPE html><html><head><title>background-attachment property</title><style>#example {background-image:background-position: center;background-repeat: no-repeat;background-attachment: local;}</style></head><bodystyle="text-align:center"><h1>GeeksforGeeks</h1><h2> background-attachment: local;</h2><br><br><divid="example"><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful.</p><br><br><br><p>This course is especially designed for theJava apprentices who want to hone theirskills in Java for Coding Interviews andCompetitive Programming. No matter if youare a school student or college student,if you have the zeal of programming, thisis the right time to start.</p><br><br><br><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful</p><br><br><br><p>This course is especially designed for theJava apprentices who want to hone theirskills in Java for Coding Interviews andCompetitive Programming. No matter if youare a school student or college student,if you have the zeal of programming, thisis the right time to start.</p><br><br><br><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful</p></div></body></html>chevron_rightfilter_none - Output:

initial: It is used to set background-attachment property to its default value.
- Syntax:
background-attachment: initial;
- Example:
<!DOCTYPE html><html><head><title>background-attachment property</title><style>#example {background-image:background-position: center;background-repeat: no-repeat;background-attachment: initial;}</style></head><bodystyle="text-align:center"><h1>GeeksforGeeks</h1><h2> background-attachment: initial;</h2><br><br><divid="example"><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful.</p><br><br><br><p>This course is especially designed for theJava apprentices who want to hone theirskills in Java for Coding Interviews andCompetitive Programming. No matter if youare a school student or college student,if you have the zeal of programming, thisis the right time to start.</p><br><br><br><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful</p><br><br><br><p>This course is especially designed for theJava apprentices who want to hone theirskills in Java for Coding Interviews andCompetitive Programming. No matter if youare a school student or college student,if you have the zeal of programming, thisis the right time to start.</p><br><br><br><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon,Adobe etc with a free online placementpreparation course. The course focuses onvarious MCQ's & Coding question likely tobe asked in the interviews & make yourupcoming placement season efficient andsuccessful</p></div></body></html>chevron_rightfilter_none - Output:
inherit: It is used to set the property from its parent element.
Supported Browsers: The browser supported by background-attachment property are listed below:
- Google Chrome 1.0
- Internet Explorer 4.0
- Firefox 1.0
- Opera 3.5
- Safari 1.0
Recommended Posts:
- HTML | DOM Style backgroundAttachment Property
- CSS | transition-property Property
- CSS | nav-right property
- CSS | all Property
- CSS | right Property
- CSS | nav-down property
- CSS | nav-up property
- CSS | top Property
- CSS | clip Property
- CSS | resize Property
- CSS | align-self Property
- CSS | perspective Property
- CSS | transition Property
- CSS overflow-y Property
- CSS | cursor property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


