Converting Colors

Format Hex

The Hex color format or hex triplet is a 3 byte hexadecimal number. The first byte is the red color, the second the green value and the last byte is for the blue color. The hex color is build by concatenating these six digits, as example FF00AA.

If one of the three hexadecimal color values is less than 16, a zero must be prepended. So a hex value of 4 would be 04 as the triplet always has six digits. There are 16777216 possible colors in this format.


In CSS it is possible to use a shorthand three digit format, where the single digits get doubled. So for example 0FC would be 00FFCC in the normal format. In the Shorthand format there are only 4096 possible colors.


To use a Hex color in CSS the following format needs to be used #RRGGBB. Hex colors are supported by all browsers.

div {