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

Style backgroundColor Property

Style Object Reference Style Object

Example

Set a background color for a document:

document.body.style.backgroundColor="red";

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.


Syntax

Return the backgroundColor property:

object.style.backgroundColor

Set the backgroundColor property:

object.style.backgroundColor="color|transparent|initial|inherit"

Property Values

Value Description
color Specifies the background color. Look at CSS Color Values for a complete list of possible color values
transparent Default. The background color is transparent (underlying content will shine through)
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: transparent
Return Value: A String, representing the background color
CSS Version CSS1


More Examples

Example

Set a background color of a specific <div> element:

document.getElementById("myDiv").style.backgroundColor="lightblue";

Try it yourself »

Example

Return the background color of a specific <div> element:

alert(document.getElementById("myDiv").style.backgroundColor);

Try it yourself »

Example

Return the background color of a document:

alert(document.body.style.backgroundColor);

Try it yourself »


Related Pages

CSS tutorial: CSS Background

CSS reference: background-color 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 BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE