Setting the colours in CSS

You can set the colours for almost anything in CSS. There are two settings:

Using words for colours

You have done this. To set the colour for the BODY (and everything in it). Note the US spelling of color.:

body {
    color:red;
    background-color:blue;
}
        

This goes into a stylesheet (either in the HEAD as an embedded style or into an external stylesheet). Open externalcss.html and myfirststyles.css or make a new page and stylesheet. and put the above inot the stylesheet (replace any styles already there).

Hexadecimal

Words are easy but a bit limiting. Hex gives you ultimate flexibility but what might at first seem unnecessary complication.

There are two things you need to understand:

As you can see those three pairs of numbers (00 FF and 9F) create a bluish green background (that is the background colour of the list).

Insert the following styles in a suitable location and then play with the colour values:

body {
    color:#FF0000;
    background-color:#0000FF;
}
        

You can find lots of colour picker pages to get hexadecimal codes on the Web or in graphics applications (even MS Paint). w3schools lists the named colours and their hex equivalent to get you started. Or just play.

Decimal or RGB

Exactly the same colours can be produced using decimal:

color:rgb(0,0,255);
        

Again there are three values but this time they are decimal values separated by commas. The range is 0 to 255 which is exactly the same as 00 to FF. The example above would be pure blue.

submit to reddit Delicious Tweet