Little Web Hut

CSS 2.1 Reference: background-attachment Property

CSS background-attachment Property
Syntax
selector {background-attachment: value;}
  • value is specified by using one of the following keywords: scroll, fixed, or inherit.
Usage

The background-attachment property is used to specify whether the background will scroll with the web page or whether it will remain in a fixed position.

This property is specified by using a keyword according to the syntax shown above.


CSS Example: The background-attachment property is set using the keyword scroll.
body {background-attachment: scroll;
    background-image: url("../images/floatingball.gif");
    background-repeat: repeat;
  }
Test It HTML StyleTest It XHTML StyleTest It HTML5 Style

CSS Example: The background-attachment property is set using the keyword fixed.
body {background-attachment: fixed;
    background-image: url("../images/floatingball.gif");
    background-repeat: repeat;
  }
Test It HTML StyleTest It XHTML StyleTest It HTML5 Style

Keywords
  • scroll - Background image will scroll along with the web page.
  • fixed - Background image is fixed and will not scroll.
  • inherit - The inherit keyword is used to specify that the value for this property should be taken from the parent element. If inherit is used with the root element, then the initial value for this property will be used.
Applies To All elements
Inherited No
Initial Value scroll


background-attachment Property Examples
Test It HTML StyleTest It HTML StyleTest It HTML5 StyleThe background-attachment property is set using the keyword scroll.
Test It HTML StyleTest It HTML StyleTest It HTML5 StyleThe background-attachment property is set using the keyword fixed.