Style backgroundColor Property
- Previous Page backgroundAttachment
- Next Page backgroundImage
- Go Up One Level HTML DOM Style Object
Definition and Usage
backgroundColor
Set or return the background color of the element.
See also:
HTML Styles:background property
CSS Tutorial:CSS Background
CSS Reference Manual:background-color property
Instance
Example 1
Set the background color of the document:
document.body.style.backgroundColor = "red";
Example 2
Set the background color of the specific <div> element:
document.getElementById("myDiv").style.backgroundColor = "lightblue";
Example 3
Return the background color of the specific <div> element:
alert(document.getElementById("myDiv").style.backgroundColor);
Example 4
Return the background color of the document:
alert(document.body.style.backgroundColor);
Syntax
Return the backgroundColor property:
object.style.backgroundColor
Set the backgroundColor property:
object.style.backgroundColor = "color|transparent|initial|inherit"
Property value
Value | Description |
---|---|
color |
Specifies the background color. Please see CSS color values, for a complete list of possible color values. |
transparent | Default. The background color is transparent (the underlying content is visible). |
initial | Set this property to its default value. See initial. |
inherit | Inherit this property from its parent element. See inherit. |
Technical details
Default value: | transparent |
---|---|
Return value: | A string representing the background color. |
CSS version: | CSS1 |
Browser support
backgroundColor
It is a CSS1 (1996) feature.
All browsers fully support it:
Chrome | Edge | Firefox | Safari | Opera | IE |
---|---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera | IE |
Support | Support | Support | Support | Support | Support |
- Previous Page backgroundAttachment
- Next Page backgroundImage
- Go Up One Level HTML DOM Style Object