![]() |
VOOZH | about |
Adding a background image to a website is one of the most common design techniques. But what if you want the image to stay fixed in place, even when the user scrolls down the page?
That’s exactly what fixed background images in CSS are for. This article will guide you step-by-step on how to specify and control a fixed background image using CSS.
background-attachment PropertyThe background-attachment property defines the scrolling behavior of background images on a web page or within an element. It determines if the background image moves as the user scrolls or stays fixed.
background-attachment:Syntax:
selector {
background-attachment: scroll | fixed | local;
}
In this example, we are using the background-attachment property.
Output:
In this example:
background-attachment: fixed; keeps the background image fixed relative to the viewport.background-attachmentBrowser | Supported Versions |
|---|---|
Google Chrome | 1.0+ |
Firefox | 1.0+ |
Internet Explorer | 4.0+ |
Opera | 3.5+ |
Safari | 1.0+ |
background-attachmentbackground-size: cover; for full coverage.fixed background on mobile devices due to performance issues; use media queries to disable on smaller screens.