W3Schools.com

Style backgroundColor Property

Style Object Reference Style Object

Definition and Usage

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

Syntax

Set the backgroundColor property:

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

Return the backgroundColor property:

Object.style.backgroundColor

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 The background color is transparent (underlying content will shine through). This is default.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The backgroundColor property is supported in all major browsers.


Example

Example

Set a background color for a document:

<html>
<head>
<script type="text/javascript">
function displayResult()
{
document.body.style.backgroundColor="#f3f3f3";
}
</script>
</head>
<body>

<h1>Hello World!</h1>
<br />
<button type="button" onclick="displayResult()">Set background color</button>

</body>
</html>

Try it yourself »


Style Object Reference Style Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE