CSS 2.1 Colours
Colours in in CSS 2.1 are defined as a combination of red, green and blue light. Each of the 3 primary colours is given a numeric value from zero to 255, the higher the value the greater the amount of that primary colour in the finished colour.
This value is known as an RGB value - RGB from the initial letters of Red, Green and Blue and this can be written either in either the decimal(0 to 9) or hexadecimal(base 16 - from 0 to F) numbering system. The table below shows the three primary colours with their Decimal and Hex values and the resulting colour displayed.
|Colour name||RGB value||Hex value||Resulting colour|
The hexadecimal format is a '#' followed by either 3 or 6 digits. i.e. #FF0 or #FFFF00 - they both represent the same colour. In the three digit format the first digit is the red value, the second is green and the third is the blue value. In the six digit format the first pair represents red, the second green and the final pair give you the blue value.
Additionally colours can be set using the 'rgb' notation with the letters 'rgb' followed by brackets containing three different values for each colour using either three numbers from 0 to 255 or three percentages i.e. rgb(255,51,102) or rgb(100%,20%,40%).
In CSS 2.1 there are also 16 colour names which are universally supported and can be used in place of RGB values. The following table lists these colours with their hex and rgb values.
|Colour displayed||Colour name||Decimal rgb value||Hex rgb value||Colour displayed|
So including colour name there are five different notations you can use to apply the same red background colour to a <div> element: