Specifying Color
Because color is presentational, it should be specified with Cascading Style Sheets, not HTML attributes. This material is included only for completeness.
In both (X)HTML and CSS, color values may be provided by numeric 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 ...
Get HTML & XHTML Pocket Reference, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.