Gets or sets the color of the text of the object.
Syntax
CSS { color : sColor } Scripting [ sColor = ] object.style.color [ = sColor ]
Possible Values
sColor String or Integer 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.
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
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 */ EM { color: rgb(100%,0%,0%) ] /* float range: 0.0 - 100.0 */Some browsers do not recognize color names, but all browsers should recognize RGB color values and display them correctly.
Internet Explorer 9 introduces support for the RGBA, HSL, and HSLA color models.
In Internet Explorer 9, the RGB color model has been extended to include an alpha channel, or transparency. The format of an RGBA value is
rgba(red,green,blue,alpha). The red, green, and blue components are identical to those of the RGB color model, and are expressed as integers or percentages. The alpha component is expressed as a value between 0.0 (completely transparent) and 1.0 (completely opaque).
Internet Explorer 9 supports hue-saturation-lightness (HSL) color values. The format of an HSL value is
hsl(hue,saturation,lightness). In the HSL color model, "hue" is defined as the indicated color's angle on the color wheel (for instance, red is 0 or 360, green is 120, blue is 240, and so on). "Saturation" and "lightness" are expressed as percentages.
Internet Explorer 9 also extends the HSL color model with an alpha channel. As with the RGBA model, the alpha channel is expressed as a value between 0.0 and 1.0. The format of an HSLA value is
hsla(hue,saturation,lightness,alpha).
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
redwhen 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'"> . . .Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/color_h.htm
This example uses inline scripting to change the text color to
redwhen an onmouseover event occurs.<SPAN STYLE="font-size:14" onmouseover="this.style.color='red'"> : </SPAN>Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/color_s.htm
Standards Information
This property is defined in Document Object Model (DOM) Level 1 and is defined in Cascading Style Sheets (CSS), Level 1 (CSS1).
Applies To
A, ADDRESS, APPLET, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, CSSStyleDeclaration, 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, CSSCurrentStyleDeclaration Constructor, CSSRuleStyleDeclaration Constructor, CSSStyleDeclaration Constructor
See Also
Color Table
Internet Explorer 9 introduces support for the RGBA, HSL, and HSLA color models.