teach-ict.com logo

THE education site for computer science and ICT

Uses of hexadecimal

2. HTML colour and hex

One of the more common ways to handle colour on a computer system is to define it in terms of a specific combination of three primary colours namely Red, Green and Blue (RGB code).

The diagram below shows the html hex code for a pair of colours picked from a colour wheel application.

colour wheel as used to define colour in html

Red is made up of 8 bits ranging in value from 0 to 255 decimal or FF hex

Green, also 8 bits from 0 to 255 decimal or FF hex

and blue as 8 bits ranging 0 to 255 decimal or FF hex.

With this triplet of colour values it is possible to define over 16 million colours.

A pure red colour has the triple decimal code of 255,0,0 (pure red, no green, no blue)

This decimal format is awkward and so in html, the convention is to use a 6 digit hex code preceded by a hash #.

The first pair of digits is red, the next pair is green and the last two, blue. Therefore a pure red colour in hex is

       #FF0000

Pure blue is #0000FF

Pure green is #00FF00