Search w3schools.com:

SHARE THIS PAGE

Style backgroundColor Property

Style Object Reference Style Object

Example

Set a background color for a document:

document.body.style.backgroundColor="#f3f3f3";

Try it yourself »

Definition and Usage

The backgroundColor property sets or returns the background color of an element.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The backgroundColor property is supported in all major browsers.

Note: The value "inherit" is not supported in IE7 and earlier. IE8 requires a !DOCTYPE. IE9 supports "inherit".


Syntax

Set the backgroundColor property:

element.style.backgroundColor="color|inherit|transparent"

Return the backgroundColor property:

element.style.backgroundColor

Property Values

Value Description
color Specifies the background color. Look at CSS Color Values for a complete list of possible color values
inherit The background color is inherited from the parent element
transparent Default. The background color is transparent (underlying content will shine through)

Technical Details

Default Value: transparent
Return Value: A String, representing the background color
DOM Version Core Level 1


Style Object Reference Style Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]