Friday, January 6, 2012

CSS: Values: Colors: Hexadecimal


By Richard York

Hexadecimal colors have been around nearly as long as the World Wide Web has been. Hexadecimal refers to a numbering scheme that uses 16 characters as its base, expressed in a combination of letters and numbers. The decimal numbering system, on the other hand, uses 10 numbers as its base. A hex-adecimal system uses 0-9 for the first 10 digits and A-F to represent the remaining 6 digits. Letter A corresponds to the number 10, B to 11, C to 12, and so on up to 15, which is represented by F. Hexadecimal values are another way of expressing an RGB value. For instance, #FFFFFF refers to white, which is expressed in RGB as 255, 255, 255. To switch from RGB values to hexadecimal, each channel is converted to its hexadecimal equivalent, so each 255 becomes FF in hexadecimal. To calculate the hexadecimal value, divide the RGB number by 16. The result is the first hexadecimal digit. The remainder from the division becomes the second hexadecimal digit. The RGB value 255 divided by 16 equals 15 with a remainder of 15. In hexadecimal, the number “15” is represented by “F”, so applying this formula results in FF. The process is repeated for each RGB color channel, so the hexadecimal notation of 255, 255, 255 is FF, FF, FF or #FFFFFF. In CSS, hexadecimal colors are included just as RGB or color keywords are, as shown in the following example.
#000000 is the hexadecimal representation of black; the same as RGB 0, 0, 0 or simply the black color keyword. #FF0000 is a hexadecimal representation of red, or RGB 255, 0, 0, or the red color keyword. Finally, #FFA500 is a hexadecimal representation of orange, or RGB 255, 165, 0, or the orange color keyword.
Post a Comment