Colors

FilterElements

NOTE: Because color is presentational, it should be specified with Cascading Style Sheets, not HTML attributes. This material is included only for completeness.

Color values may be provided by numeric RGB values or standardized color names.

RGB Values

The most common and precise way to specify a color is by its numeric RGB (red, green, blue) values. Using an image-editing tool such as Adobe Photoshop, you can determine the RGB values (on a scale from 0 to 255) for a selected color. For example:

Red: 212   Green: 232   Blue: 119

These values must be converted to their hexadecimal (base-16) equivalents in order to be used as attribute values. In this example, the previous decimal values are converted to hexadecimal:

Red: D4   Green: E8   Blue: 77

In (X)HTML, these values are provided in a six-character string, preceded by the # symbol, like so:

#D4E877

The underlying syntax is this:

#RRGGBB where RR stands for the hexadecimal red value, GG stands for the hexadecimal green value, and BB stands for the hexadecimal blue value.

Fortunately, Adobe Photoshop makes the hexadecimal values for colors readily available at the bottom of the color picker next to the # symbol. The hex values can be copied from the color picker and pasted into a style sheet or HTML document.

If you are using an image tool that does not list hexadecimal values, you’ll need to convert decimal to hexadecimal yourself using a hexadecimal calculator. Windows users can find a hexadecimal calculator in the “Scientific” view of the Windows standard calculator. On the Mac, the standard calculator has a “Programmer” view (from the menu, select View→Programmer) that can convert decimal to hexadecimal.

Standard Color Names

Colors may also be identified by predefined color names. The syntax for using color names is extremely straightforward:

<body link="navy">

HTML 4.01 and XHTML 1.0 include 16 valid color names. They are listed here with their equivalent RGB values:

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

These color names may be used with style sheets as well. The CSS 2.1 Recommendation adds orange (#FFA500 ) to this list for a total of 17 supported colors. CSS 3 supports 140 additional standard color names that are widely supported by browsers, but they are not valid for use in (X)HTML documents.