w3resource logo

JavaScript Client Objects

JavaScript Document Object : bgColor property

Secondary Nav


A string specifying the color of the document background. The bgColor property expressed as HTML hexadecimal triplet value (for example "00FF80) or any standard color name like "red".


Implemented in JavaScript 1.0


document.bgColor = "color_name"

Example of document Object : bgColor property

In the following web document bgColor property change the background color of the document.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /><title>JavaScript document Object : bgColor Property. Example-1</title>
<h1 style="color: red">JavaScript document Object : bgColor Property</h1>
<h3>Click on any button and check the background color of the document.</h3>
<hr />
<form action="#">
<input type="button"
onclick="changeBackGroundColor('red')" />
<br />
<input type="button"
onclick="changeBackGroundColor('blue')" />
<br />
<input type="button"
onclick="changeBackGroundColor('white')" />
<script type="text/javascript" language="JavaScript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
// Following function changes the background color and fills in the text box.
function changeBackGroundColor(color)

View the example of document object's bgColor property in the browser

Supported Browser

Internet Explorer 7 Firefox 3.6 Google Chrome 7 Safari 5.0.1 Opera 10
Yes Yes Yes Yes Yes

See also :

JavaScript Client side objects, methods, properties.

JavaScript Core objects, methods, properties.

Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number