Colors

Colors can be specified in HTML pages in two ways: by using numbers to denote an RGB color value, or by using a color name.

RGB notation

An RGB color value normally consists of a '#' immediately followed by a triad of two-digit hexadecimal numbers specifying the intensity of the corresponding color: Red, Green, and Blue. For example, the color value #FF0000 is rendered red because the red number is set to its highest value, FF (or 255, in decimal).

The three-digit shorthand form is converted into the six-digit form by replicating digits (#F00 becomes #FF0000). The "functional" RGB notation uses a comma-separated list of decimal or percentage values.

Each of the following style rules applies the same color (red) to the EM selector:

EM {color: #f00;}              /* #rgb */
EM {color: #ff0000;}           /* #rrggbb */
EM {color: rgb(255, 0, 0);}    /* integer range 0 - 255 */
EM {color: rgb(100%, 0%, 0%);} /* float range 0.0% - 100.0% */ 
EM {color: red;}               /* color keyword */ 

Standard HTML colors

Only 16 color "keywords" (names) are defined by the HTML 4.01 standard. These colors can always be rendered correctly, regardless of the color resolution of the user's display card:

black

(#000000)

silver

(#C0C0C0)

gray

(#808080)

white

(#FFFFFF)

maroon

(#800000)

red

(#FF0000)

purple

(#800080)

fuchsia

(#FF00FF)

green

(#008000)

lime

(#00FF00)

olive

(#808000)

yellow

(#FFFF00)

navy

(#000080)

blue

(#0000FF)

teal

(#008080)

aqua

(#00FFFF)

The Cascading Style Sheets (CSS), Level 2 Revision 1 (CSS2.1) Ee371205.xtlink_newWindow(en-us,Expression.40).png specification includes "orange," for a total of 17 color keywords:

orange

(#FFA500)

Standards-compliant mode

When you use the !DOCTYPE declaration to specify standards-compliant mode, Internet Explorer 6 and later versions ignore style sheet declarations that do not comply with the Cascading Style Sheets, Level 1 (CSS1) Ee371205.xtlink_newWindow(en-us,Expression.40).png specification. Colors specified with hexadecimal RGB values must have a leading "#" character (see the color tables earlier in this topic). Values like "FFFFFF" are ignored, instead of being treated the same as "#FFFFFF" (also known as white). This affects all cascading style sheet attributes and properties that accept an RGB color value.

See also

Concepts

Color and background
User interface

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.