BODY.bgColor (Property)

The background color of the current page.


DOM level - 1
JavaScript - 1.5
JScript - 3.0
Internet Explorer - 4.0
Netscape - 6.0
Property/method value type:String primitive
JavaScript syntax:-myBODY.bgColor

This corresponds to the BGCOLOR="..." HTML tag attribute on the <BODY> tag.

You can modify this value at any time, the result of which will be to change the background color of the page.

Now that the style control facilities are more sophisticated, this tag attribute is likely to fall into disuse. On the other hand it does work consistently on both MSIE and Netscape where style sheet controls do not. Later, a DOM standardized approach to style handling will provide a cross platform way to access style information from JavaScript. DOM level 2 introduces a first attempt at standardizing this area.

The background can be colored whether an image is loaded into the background of a document or not. In fact, it may be advisable to set the background color to something similar to the average color of the background image in case the image takes a long time to load or the browser is unable to display a background image.

The background color for the document that is defined in the <BODY> tag is also reflected in the bgColor property of the document object, although that is now deprecated as of DOM level 1.

See also:Color names, Color value, Document.bgColor, Document.linkColor, HTML object