Background-attachment - CSS Property

background-attachment

Summary of characteristics of the background-attachment property

Quick description
Background image scrolling mode.
Status
Standard
Predefined values
scroll | fixed | local
Percentages
Not applicable.
Initial value
scroll
Inherited by default
No.
Discrète: during an animation, the background-attachment property passes from one value to another without transition.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Backgrounds and Borders Module
 🡇  
 🡅  
Document status: WD (Working Draft)

Document status: CR (Candidate Recommendation)

Document status: REC (Recommendation)

Document status: DEPR (Old specification, declared obsolete or superseded)

Syntax diagram of background-attachment.

background-attachment - Syntax DiagramSyntax diagram of the background-attachment CSS property, which specifies how the background scrolls. scroll scroll fixed fixed local local , ,background-attachment:;background-attachment:;
Syntax diagram of the background-attachment property.
The links in the diagram provide more details about the values.
Download the diagram in SVG.

Description of the background-attachment property.

background-attachment defines what the background image is "attached" to, in other words, is this background image fixed? Does it scroll with the page? Or does it scroll with the content of the element (when the element has a scrollbar)? This property is often applied to the body tag but is also useful for many other tags: div, span, etc. If no background image is set, this property has no effect.

For a general explanation on how backgrounds work, check out the page general information about backgrounds.

Values for background-attachment.

  • background-attachment: scroll;

    scroll is the default value for background-attachment.
    The background is attached to the element: it moves with the element but stays fixed if the element's content scrolls.










     
  • background-attachment: fixed;

    The background never scrolls, which is pretty annoying when it's only visible in one element and the page is scrolling.










     
  • background-attachment: local;

    The background is attached to the element's content: it scrolls with the element's content, and therefore also with the element itself if it moves.










     
  • background-attachment: local, fixed, fixed...;

    This syntax of background-attachment, which includes a series of comma-separated values, can be used when multiple backgrounds have been set by background-image. Each value applies to one of the backgrounds, in the order defined by background-image. For more details on multiple backgrounds, check out the page multiple backgrounds.

  • background-attachment: initial; (scroll) background-attachment: inherit; background-attachment: revert; background-attachment: revert-layer; background-attachment: revert-rule; background-attachment: unset;

    Links to the presentation of these different values: initial, inherit, revert, revert-layer, revert-rule, unset.

Access the background-attachment property via a program

With Javascript, change the value of background-attachment.

In JavaScript, here's how to change the value of background-attachment for the el element.

To refer to the property, JavaScript offers a syntax with the typical CSS notation, in kebab-case (a dash to separate words), or another syntax with camel-case notation (a capital letter to separate words).

Javascript
let el = document.getElementById('id'); el.style['background-attachment'] = 'fixed'; // or let el = document.getElementById('id'); el.style.backgroundAttachment = 'fixed';

With Javascript, read the value of background-attachment.

This code example returns the value of background-attachment if it has been set with the style attribute of the element in the HTML code. The code won't work if the property was set via a CSS selector.

Javascript
let el = document.getElementById('id'); el.style['background-attachment'] = 'fixed'; // or let el = document.getElementById('id'); el.style.backgroundAttachment = 'fixed';

With Javascript, read the computed value of background-attachment.

The computed value is always defined: it will be either the value assigned to background-attachment for this element, via the style attribute or via a CSS selector, or an inherited value, or even the initial value.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('background-attachment');

Read or modify the value of the background-attachment property with JQuery.

JQuery

// Read the value:
$('#id').prop('background-attachment');
// Write the value:
$('#id').prop('background-attachment', 'fixed');
$('#id').prop('{background-attachment': 'fixed'});

Read the computed value of the background-attachment property with JQuery.

JQuery
let value = $('#id').css('background-attachment');

Test it yourself.

The buttons below apply the entered value to the background-attachment property and then show either the value as it was applied or the computed value. In the case of the background-attachment property, it will be the same thing, unless you enter an incorrect value. In that case, the assigned value will be null and the computed value will be reset to the property's initial value.

Simulator.

To clearly see the effect of the different values of background-attachment, scroll through this page and also the content in the area below using its scroll bar.

background-attachment :
The background refers to what is located behind the main subject. In CSS, this can be an image, a combination of images, a gradient, or a color. In the domain of art, photography, or cinema, the background is the part of the scene that is behind the characters, animals, or objects that make up the foreground.
Example: a village can have a mountainous background.

Browsers compatibility with background-attachment.

The background-attachment is well recognized by all modern browsers.

Column 1
Support of the background-attachment property.

Notes:

(1) Does not support the fixed value for the background-attachment property.
Supports the local value only if rounded corners are defined on the element.

1
background-attachment
property
Estimated overall support.
97%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Opéra

Chrome

Edge

Firefox

Chrome pour Androïd

Androïd Brower

Firefox pour Androïd

Safari

Safari sur IOS

Samsung Internet

KaiOS Browser

Opéra mini

Historic of the background-attachment property..

  • Cascading Style Sheets specification - Version 1

    This first level of the CSS specification describes the mechanism of cascading style sheets. Authors and readers can add styles to documents. Mainly intended for formatting HTML documents, CSS allows defining colors, fonts, text formatting, spacing (margins), etc. The CSS language is easy to understand, readable, and easy to write; it uses common terms from desktop publishing.

    Regarding background-attachment First definition of the background-attachment property.
    WD
    November 17, 1995
    Working Draft.
    PR
    November 12, 1996
    Proposed for recommendation.
    REC
    December 17, 1996
    Recommendation .
    DEPR
    September 13, 2018
    Old specification, declared obsolete.
  • Cascading Style Sheets Level 2 - Revision 1 Specification

    This level 2 of the specification describes the mechanism of cascading styles in CSS. This language is used to format HTML or XML documents. It supports media-specific style sheets so that authors can adapt the presentation of their documents for visual browsers, auditory devices, printers, braille devices, portable devices, etc.

    Regarding background-attachment Taking into account the inherit value.
    WD
    November 04, 1997
    Working Draft.
    PR
    March 24, 1998
    Proposed for recommendation.
    REC
    May 11, 1998
    Recommendation .
  • CSS Backgrounds and Borders Module Level 3

    Level 3 of the specification also explains how to position the background relative to the background area, and how to crop it.
    Regarding borders, the concept of image borders is introduced, as well as the ideas of rounded corners and box shadows.

    Regarding background-attachment Adding the local value.
    Multiple backgrounds possible.
    WD
    August 02, 2002
    Working Draft.
    CR
    December 17, 2009
    Candidate Recommendation.
    PR
    REC
  • CSS Backgrounds and Borders Module Level 4

    Level 4 of the specification introduces logical values that depend on the writing mode.

    Regarding background-attachment No change regarding the background-attachment property.
    WD
    November 25, 2025
    Working Draft.
    CR
    PR
    REC

See also, about backgrounds.

The specification "CSS Backgrounds and Borders Module" of W3C covers everything about backgrounds and borders, which includes quite a few properties:

Properties:

background
Summary of background properties.
Background-attachment
Background image scrolling mode.
background-clip
Defines the extent of the background, especially in relation to the border and padding.
background-color
Sets the background color.
background-image
Defines the background image or gradient (multiple images or gradients can coexist).
background-origin
Defines a reference to position the background image.
background-position
Defines how the background image is positioned.
background-position-block
Sets the background positioning in the block direction.
background-position-inline
Sets the background positioning along the lines.
background-position-x
Sets how the background image is positioned horizontally.
background-position-y
Defines how the background image is positioned in the vertical direction.
background-repeat
Defines how the background image is repeated.
background-size
Sizing the background image.
border
A shorthand property that defines the set of border parameters: width, style and color.
border-bottom
Sets the parameters of the bottom border of the element (thickness, line style, color).
border-bottom-color
Sets the border line color for the bottom of the element.
border-bottom-left-radius
Sets the radius of the rounded corner at the bottom left.
border-bottom-right-radius
Sets the radius of the rounded corner in the lower right.
border-bottom-style
Sets the line style for the border below the element.
border-bottom-width
Sets the thickness of the border line located below the element.
border-color
Sets the border color for all four sides of the element.
border-end-end-radius
Sets the radius of the corner rounding at the end of line and end of block.
border-end-start-radius
Sets the radius of the corner rounding at the end of line and beginning of the block.
border-image
Langue française
Shorthand of border properties made with images.
border-image-outset
Langue française
Sets the overflow of the border image.
border-image-repeat
Langue française
Defines how the border image is repeated or expanded to cover the desired area.
border-image-slice
Langue française
Defines how the border image is clipped.
border-image-source
Sets the path and file name for the image used to build the border.
border-image-width
Langue française
Sets the thickness of the border when the border is made with an image.
border-left
Sets the three parameters of the left border of the element (thickness, line style, color).
border-left-color
Sets the color of the left border line of the element.
border-left-style
Sets the border style for the left side of the element.
border-left-width
Sets the thickness of the border on the left side of the element.
border-radius
Radius of rounded corners.
border-right
Sets the three parameters of the right border of the element (thickness, line style, color).
border-right-color
Sets the color of the border line on the right side of the element.
border-right-style
Sets the line style for the right border of the element.
border-right-width
Sets the thickness of the border on the right side of the element.
border-start-end-radius
Sets the radius of the corner rounding at the beginning of the line and the end of the block.
border-start-start-radius
Sets the radius of the corner rounding at the beginning of the line and the beginning of the block.
border-style
Sets the line type for some or all four borders around the element (solid, double, dotted...).
border-top
Sets the parameters of the top border of the element (thickness, line style, color).
border-top-color
Sets the color of the border line above the element.
border-top-left-radius
Sets the radius of the rounded corner at the top left.
border-top-right-radius
Sets the radius of the rounded corner in the upper-right.
border-top-style
Sets the line style for the left border of the element.
border-top-width
Sets the thickness of the border line above the element.
border-width
Sets the thickness of the border line around the element.
box-shadow
Applies a shading effect to the frames by indicating all the parameters: color, shadow shift, blur, etc.