Click to Rate and Give Feedback
Properties
 backgroundColor Property
background-color Attribute | backgroundColor Property

Sets or retrieves the color behind the content of the object.

Syntax

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

Possible Values

sColorString or Integer that specifies or receives one of the following values.
transparentDefault. Color of the next parent object through which the background is visible.
colorAny 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.

Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see About Dynamic Properties.

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>
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

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>
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Standards Information

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

Applies To

A, ADDRESS, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, currentStyle, CUSTOM, DD, defaults, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FORM, 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, MARQUEE, MENU, NOBR, OL, OPTION, P, PLAINTEXT, PRE, runtimeStyle, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP
Tags What's this?: Add a tag
Community Content
 
Add Community Content
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker