HTML Tutorial 011 - Colors

If you have a suggestion for a new tutorial or questions about HTML please go to the Forum


Other Tutorial Options:
PDF Download

So far in all of the tutorials we have gone over background colors and text colors but I have not told you all of the different colors you can use. There are three ways to define a color in HTML. The first way and the only way we have used so far have been with one of the presets. There are only 16 of those: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow.

This is an excruciatingly limited list of colors. Let’s expand it to 16,777,216, over a million times more choices! There are two ways use that amount and you can either use the RGB values or you can use the hex decimal values. Both of them work equally well, however the most popular is the hex decimal. To do the hex decimal you would do something like this:

<html>
<head>
<title>My Web Page</title>
</head>
<body bgcolor="#123456">
</body>
</html>

A hex decimal color must always have six numbers or letters following the # symbol. The color above will be a dark blue color. For each of the six decimals you can use 0 through 9 and A through F. Black is #000000 and White is #FFFFFF. F is higher than A, 9 is higher than 0, and A is higher than 9. The order looks like this: 0123456789ABCDEF. The hex numbers work in a similar way to RGB values in the fact that the first two decimals is the red value, the second two are the green and the last two are the blue. So:

#FF0000 = Red
#00FF00 = Green
#0000FF = Blue

The other way to make HTML colors is to use the actual RGB values rather than having to convert them into hex decimal. To do this your coding will look something like this:

rgb(255,255,255) = White
rgb(0,0,0) = Black

However, this is not very popular and does not work correctly on all web browsers. I highly suggest not even using it and sticking to the Hex decimal values. I think that is all there is to know about colors. It’ll take a bit to get used to hex decimal coloring if you aren’t already.