X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Style backgroundAttachment Property

Style Object Reference Style Object

Example

Set a background-image to be fixed (will not scroll):

document.body.style.backgroundAttachment="fixed";

Try it yourself »


Definition and Usage

The backgroundAttachment property sets or returns whether a background image should scroll with the content, or be fixed.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The backgroundAttachment property is supported in all major browsers.


Syntax

Return the backgroundAttachment property:

object.style.backgroundAttachment

Set the backgroundAttachment property:

object.style.backgroundAttachment="scroll|fixed|local|initial|inherit"

Property Values

Value Description
scroll The background scrolls along with the element. This is default
fixed The background is fixed with regard to the viewport
local The background scrolls along with the element's contents
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Technical Details

Default Value: scroll
Return Value: A String, representing how the background image is attached to the object within the document
CSS Version CSS1


More Examples

Example

Choose between scroll and local on a DIV element:

document.getElementById("myDIV").style.backgroundAttachment = "local";

Try it yourself »

Example

Toggle between scroll and fixed:

var x = document.body.style.backgroundAttachment;
document.body.style.backgroundAttachment=(x=="scroll")? "fixed":"scroll";

Try it yourself »

Example

Return the value of the background-attachment property:

alert(document.body.style.backgroundAttachment);

Try it yourself »


Related Pages

CSS tutorial: CSS Background

CSS reference: background-attachment property

HTML DOM reference: background property


Style Object Reference Style Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook