color Attribute | color Property

Internet Development Index

Sets or retrieves the color of the text of the object.

Syntax

HTML { color : sColor }
Scriptingobject.style.color(v) [ = sColor ]

Possible Values

sColorVariant that specifies or receives one of the color names or RGB values 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 no default value. The Cascading Style Sheets (CSS) attribute is 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

These are different ways to specify a color—in this example, red.

EM { color: red }              /* natural language / CNS */
EM { color: #F00 }             /* #RGB */
EM { color: #FF0000 }          /* #RRGGBB */
EM { color: rgb 1.0 0.0 0.0 }  /* float range: 0.0 - 1.0 */

Some browsers do not recognize color names, but all browsers should recognize RGB color values and display them correctly.

Examples

The following examples use the color attribute and the color property to change the text color of an object.

This example uses a call to an embedded (global) style sheet to change the text color to red when an onmouseover event occurs.

<STYLE>
.color1 { color:red }
.color2 { color: }
</STYLE>
</HEAD>
<BODY>
<SPAN STYLE="font-size:14" onmouseover="this.className='color1'"
onmouseout="this.className='color2'"> . . .
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 change the text color to red when an onmouseover event occurs.

<SPAN STYLE="font-size:14" onmouseover="this.style.color='red'">
:
</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 World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 Non-Microsoft link and is defined in Cascading Style Sheets (CSS), Level 1 (CSS1) Non-Microsoft link.

Applies To

A, ADDRESS, APPLET, 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, 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