There are two ways to express color in HTML: 1) named colors, and 2) hex codes.
Named colors are easy. There are 16 "official" named colors: aqua, gray, navy, silver, black, green, olive, teal, blue, lime, purple, yellow, fuchsia, maroon, red, and white. There are also hundreds of other named colors, all through the spectrum; a complete list of these color names can be found in "HTML and XHTML: The Definitive Guide", pp.634-5.
The problem with named colors is two-fold. Firstly, named colors have not traditionally been consistent in hue from platform to platform and browser to browser, despite official standards. Secondly, these named colors are mostly not "web-safe"; we'll talk about web-safe colors a little later.
The alternative to named colors are hex codes. Hex codes express color precisely using the 24-bit RGB color palette, the standard for full-color reproduction on computers. Hex codes are expressed in seven digits, the first digit always being the # (pound) symbol, followed by six numbers representing the desired color.
Here are some example hex codes:
black: #000000
white: #FFFFFF
Why are there LETTERS in some of these hex codes, and what do these numbers and letters represent?
Not all counting systems are in Base 10, the decimal counting system that we are accustomed to. Hex codes are written in Base 16, the hexadecimal counting system.
Where we are accustomed to these numbers in Base 10:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Base 16 uses:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10
Because Base 16, or hex, rolls over to "10" at 16 rather than 10, we need to add some letters into our numbers in order to make up the difference. This means that "A" is really 10, "B" is really 11, C is really 12, etc, until you get to "10" which is equivalent to our 16.
The hex color code, then, represents the millions of colors, 24-bit RGB color palette. Remember that in 24-bit color, there is one 8-bit palette with 256 shades of red, one 8-bit palette with 256 shades of green, and one 8-bit palette with 256 shades of blue; the three palettes are combined to make millions of possible colors.
The hex code is really #RRGGBB
; the first two numbers represent 256 possible shades of red, the second two numbers represent 256 possible shades of green, and the third two numbers represent 256 possible shades of blue, making the complete 24-bit RGB color spectrum. Because we are counting in Base 16, or hex, however, we only need two digits to represent all the numbers from 0 to 255. The value "FF", then, is equivalent to 255; the number "00" is equivalent to 0, etc.
Any color in the millions of colors RGB spectrum can be coded using these hex codes. Only a fraction of these colors, however, are officially "web-safe".
Web-safe colors may only use the following digits (in hex): 00, 33, 66, 99, CC, FF
. The following randomly selected codes, then, WOULD be web-safe: #3399CC, #6666FF, #9900FF
, etc. The following randomly selected hex codes would NOT be web-safe: #3399A5, #1234AB, #DDDDDD
, etc.
For those that are interested, the decimal equivalents of the web-safe color units are as follows:
00 = 0 33 = 51 66 = 102 99 = 153 CC = 204 FF = 255
Notice how these numbers are all multiples of 51! Knowledge of hex-to-decimal equivalents may prove useful if you are not using the most up-to-date software; some older software requires that color codes be decimal ONLY!
Copyright © 2001 Michael Masumoto. All Rights Reserved.