Specifying Color by RGB Values
The most common and precise way to specify a color is by its numeric RGB (red, green, blue) values. Using RGB values, you can specify any color from the “true color” space (millions of colors). For an explanation of RGB color, see Chapter 28.
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. These are the RGB values for a particularly lovely spring green:
| Red: 212 |
| Green: 232 |
| Blue: 119 |
Color values are most often provided in a two-digit hexadecimal (base-16) form, not decimal, although these values may be used as-is in one CSS color format. Hexadecimal numbering is discussed in more detail in the next section. The same RGB values for that spring green look like this when converted to hexadecimal:
| Red: D4 |
| Green: E8 |
| Blue: 77 |
In the CSS and HTML document, the most common way of representing these values is in a six-character string, preceded by the # symbol:
#D4E877
The underlying syntax is this:
#RRGGBBwhere RR stands for the hexadecimal red
value, GG stands for the hexadecimal green
value, and BB stands for the hexadecimal blue
value. CSS has additional formats for RGB values, as listed in the
upcoming See RGB Colors in
CSS.” section.
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 ...