HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Set a background color for a document
The backgroundColor property sets or returns the background color of an element.
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
backgroundColor | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Return the backgroundColor property:
Set the backgroundColor property:
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 |
Default Value: | transparent |
---|---|
Return Value: | A String, representing the background color |
CSS Version | CSS1 |
Set a background color of a specific <div> element:
document.getElementById("myDiv").style.backgroundColor = "lightblue";
Return the background color of a specific <div> element:
alert(document.getElementById("myDiv").style.backgroundColor);
Return the background color of a document:
alert(document.body.style.backgroundColor);
CSS tutorial: CSS Background
CSS reference: background-color property
HTML DOM reference: background property