backgroundColor Property (A, ADDRESS, ARTICLE, ...)

Switch View :
ScriptFree
background-color Attribute | backgroundColor Property

Gets or sets the color behind the content of the object.

Syntax

CSS { background-color : sColor }
Scripting [ sColor = ] object.style.backgroundColor

Possible Values

sColor String or Integer that specifies or receives one of the following values.
transparent
Default. Color of the next parent object through which the background is visible.
color
Any color value, including those specified in the Color Table.

The property is read/write for all objects except the following, for which it is read-only: currentStyle. The property has a default value of transparent. The Cascading Style Sheets (CSS) attribute is not inherited.

DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are supported in IE7 Standards mode and IE5 (Quirks) mode only. For more information, see About Dynamic Properties and Defining Document Compatibility.

Remarks

This property can be set with the other background properties by using the background composite property.

Microsoft Internet Explorer 3.0 supports the background-color attribute, but only when it's set by using the background attribute.

Examples

The following examples use the background-color attribute and the backgroundColor property to specify the background color.

This example uses an inline style sheet to set the background color to lime.


<span style="font-size: 14px; background-color: lime">The background color of the text has been set inline using the <b>background-color</b> attribute.</span>

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/background-color.htm

This example uses inline scripting to set the background color to lime.


<span style="font-size: 14px" onmouseover="this.style.backgroundColor='lime'" onclick="this.style.backgroundColor='orange'" ondblclick="this.style.backgroundColor=''">
    Run your mouse over this text to change the background color to lime. Click 
    to turn orange. Double-click to return to the default color. </span>

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/backgroundColor.htm

Standards Information

This property is defined in Cascading Style Sheets (CSS), Level 1 (CSS1).

Applies To

A, ADDRESS, ARTICLE, ASIDE, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, CSSStyleDeclaration, currentStyle, CUSTOM, DD, defaults, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FIGCAPTION, FIGURE, FOOTER, FORM, HEADER, HGROUP, hn, HTML, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MARK, MARQUEE, MENU, NAV, NOBR, OL, OPTION, P, PLAINTEXT, PRE, runtimeStyle, S, SAMP, SECTION, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, CSSCurrentStyleDeclaration Constructor, CSSRuleStyleDeclaration Constructor, CSSStyleDeclaration Constructor