English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Comprehensive CSS Properties

CSS background-attachment Attribute Usage and Example

CSS background-attachment Attribute defines whether the background image scrolls with the document or remains fixed in the viewing area.

The following table summarizes the usage context and version history of this attribute

Default Value:scroll
Applicable To:All Elements
Inheritance:None
Animatable:No.Please see Animation Attribute.
Version:CSS 1,2,3
JavaScript Syntax:    
object    object.style.backgroundAttachment="fixed"

background-Syntax of attachment usage

The syntax of this attribute is as follows:

background-attachment: scroll | fixed | initial | inherit

The following examples demonstrate how to use background-attachment Attribute.

body { background-image: url("images/recycle.jpg");background-attachment: fixed;}
Test See‹/›

Attribute Value

The following table describes the values of this attribute.

ValueDescription
scrollDefault value. The background image is fixed relative to the element itself and scrolls with the elements contained in the viewport.
fixedThe background image is fixed relative to the viewport and does not move with the element.
localThe background image remains fixed relative to the element's content: if the element has a scrolling mechanism, the background scrolls with the element's content.
initialSet this attribute to its default value.
inheritIf specified, the associated element adopts its parent element's background-Computed Value of the attachment Attribute.

Browser Compatibility

background-Browser Compatibility of the attachment Attribute, all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 3.5+

Read More

Please refer to the following tutorials:CSS Background,CSS3Background.

Related Attributes:background,background-color,background-clip,background-image,background-origin,background-position,background-repeat,background-size.