background-attachment property CSS Reference



Definition and Usage

If a background-image is specified, the background-attachment CSS property determines whether that image's position is fixed within the viewport, or scrolls along with its containing block.

  • Initial scroll
  • Applies to all elements
  • Inherited no
  • Media visual
  • Computed Value as specified
  • Animatable no
  • Canonical order the unique non-ambiguous order defined by the formal grammar

Syntax

Formal syntax:   <attachment>#
background-attachment: scroll
background-attachment: fixed
background-attachment: local
background-attachment: inherit

Values

scroll
This keyword means that the background image will scroll within the viewport along with the block the image is contained within.
fixed
This keyword means that the background image will not scroll with its containing element, instead remaining stationary within the viewport.
local
This keyword means that the background image will not scroll with its containing element, but will scroll when the element's content scrolls: it is fixed regarding the element's content.

Examples

body {
  background-image: url("images/cartooncat.png");
  background-attachment: fixed;
}

Multiple background image support

This property supports multiple background images. You can specify a different <attachment> for each background, separated by commas:
body {
  background-image: url("img1.png"), url("img2.png");
  background-attachment: scroll, fixed;
}
Each image is matched with the corresponding attachment type, from first specified to last.

Compatibility

Desktop browsers

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support1.01.0 (1.7 or earlier)4.03.51.0
Multiple backgrounds1.03.6 (1.9.2)9.010.51.3
local4.025.0 (25)9.010.55.0

Mobile browsers

FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support2.11.0 (1.9.2)NA10.03.2
Multiple backgrounds2.11.0 (1.9.2)NA10.03.2
localNA25.0 (25)NANANA

Relative articles