Latest web development tutorials

HTML DOM Style backgroundColor property

Style Object Reference Style Objects

Examples

Set the background color of the document:

document.body.style.backgroundColor="#f3f3f3";

try it"

Definition and Usage

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support backgroundColor property.

Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".


grammar

Setting backgroundColor properties:

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

Back backgroundColor attributes:

element .style.backgroundColor

Property Value

描述
color 规定背景颜色。在 CSS 颜色值中寻找可能的颜色值的完整列表。
inherit 背景颜色从父元素继承。
transparent 默认。背景颜色是透明的(基本内容将会穿透)。

technical details

Defaults: transparent
return value: A string background color representative
DOM version Core Level 1


Style Object Reference Style Objects