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 stylesheet 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. Mac users with OS X 10.4 (Tiger) can download the free Hex Calculator Widget at:
| www.apple.com/downloads/dashboard/calculate_convert/hexcalculatorwidget.html |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access