Style backgroundAttachment property
The Style object
Definition and Usage
The backgroundAttachment property sets or returns whether a background image is fixed or scrolls with the rest of the page.
Syntax
Set the backgroundAttachment property:
Object.style.backgroundAttachment="scroll|fixed|local"
Return the backgroundAttachment property:
Object.style.backgroundAttachment
| Value | Description |
|---|---|
| scroll | The background scrolls with the element. This is the default. |
| fixed | The background is fixed. |
| local | The background scrolls with the content of the element. |
Browser support





All major browsers support the backgroundAttachment property.
Example
Example
Set the background image to fixed (not scrolling):
Hello World!
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
Try it »
More examples
Toggle between scroll and fixed
Toggle between the scroll and fixed values of backgroundAttachment.
The Style object