backgroundColor Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundColor

Description

The backgroundColor property sets or gets the element background color.

Property Values

Value Description
color Set the background color.
transparent Default value. The background color is transparent
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: transparent
Return Value: A String, representing the background color
CSS VersionCSS1

Get a background color for a document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body style="background-color:yellow;">

<h1>Hello World!</h1>

<button type="button" onclick="myFunction()">Get background color</button>

<script>
function myFunction() {//from   ww  w  .  j a v  a  2s .  c o  m
    console.log(document.body.style.backgroundColor);
}
</script>

</body>
</html>

Related Tutorials