Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

CSS background-attachment property


May 05, 2021 CSS Reference Manual


Table of contents


Definitions and usages

Background-attachment sets whether the background image is fixed or scrolls with the rest of the page.

Default: scroll
Inherited: no
Version: CSS1
JavaScript syntax: object object.style.backgroundAttachment="fixed"


The property value

Value Description
scroll The background picture scrolls with the rest of the page. This is the default
fixed The background image is fixed
inherit The settings that specify background-attachment should be inherited from the parent element
local The background picture scrolls with the scroll element

How to specify a fixed background image:

body
{
background-image:url('smiley.gif');
background-repeat:no-repeat;
background-attachment:fixed;
}

Try it out . . .

Browser support

The numbers in the table support the first browser version number of the property.

The number immediately before -webkit-, -ms- or -moz- is the first browser version number that supports the prefix property.

Attributes
background-attachment 1.0 4.0 1.0 1.0 3.5
Note: Internet Explorer 8 and earlier browsers do not support multiple background images in one element.

Related articles

CSS tutorial: CSS Background