Specifying Colors

In an HTML document colors are specified with a six digit hexadecimal number.

Hexadecimal numbers

The hexadecimal system of counting uses the base 16 as compared to 10 used in the decimal system. The following compares the two sytems

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 etc

Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 etc

The decimal number 10 is represented by the letter A in hexadecimal, dec 20 =hex 14 and dec 32=hex 20 etc.

In the 6 digit hexadecimal number the first two digits (XX0000) represent the amount of RED, the middle two digits (00XX00) the amount of GREEN and the last two digits (0000XX) the amount of BLUE. Where XX is replaced by a hexadecimal number between 00 and FF. The maximum amount of each color is given by the number FF (255 in decimal) and the minimum is 00 (0 in decimal). Thus full RED is given by FF0000, full GREEN by 00FF00, and full BLUE by 0000FF.

Tints, shades and combination colors can be produced by varying the amount of RED, GREEN and BLUE.The following gives some examples.

White = FFFFFF, BLACK = 000000, YELLOW = FFFF00, MAGENTA = FF00FF, CYAN = 00FFFF.

Notes

Most browsers allow the viewer to set default colors that overwrite the colors you specify on your web page. If you have ever tried to read web pages with text virtually indistinguisable from the background you will understand why!

Many computer screens (and/or video cards) can only display 256 or worst still 16 colors, whereas the six digit hexadecimal color code can specify 16.7 million. To allow for this a 256 color screen/ video setting will attempt to produce addition colors by mixing combinations of the 256 it can produce. This process is known as dithering. When used to produce a background color dithering can produce an unpleasant granular effect that is often difficult to read text against.

By now you may have come to the conclusion that specifying anything other than white (FFFFFF) for a background color is fraught with problems, I would agree with you. Default is quite a nice color too ;).

Images

Most browsers support only a limited range of colors, Netscape, one of the most popular browsers only supports 216 colors, these are the colors produced by combining all possibilities of six levels of each primary. These levels are represented by the hexadecimal numbers of 00, 33, 66, 99, CC and FF ( or approximately 0, 20, 40 50, 80 & 100% of each primary color). Thus the color represented by 3300CC is a valid Netscape color, 2245AB is not. Netscape tries to show non-Netscape colors by mixing appropriate colors on the screen. This is called dithering and results in a pattern of colors rather than a "pure" color. This causes problems when viewing graphics that use colors other than those supported by Netscape.