HTML & CSS tutorials
6. RGB Colors in CSS Files

Note: While reading this page, bear in mind that although I have some experience of writing HTML and CSS I'm no expert. If you find errors or have proposals for improvements, please send me a message and help make this a better page for the benefit of future visitors. If you're new to or not that experienced in HTML and CSS, I suggest you go to the Introduction page and follow the instructions. To the left, there are links to more HTML and CSS tutorials.


For some reason or another, hexcolors are almost always used in css-files. Personally, I prefer to use RGB colors. It's valid code according to w3schools.com.

Some examples of hexcolors: 000000 = black, ff0000 = red, 00ff00 = green, 0000ff = blue, ffff00 = yellow, ff00ff = magenta, 00ffff = cyan and ffffff = white.

In other words, the values are written with a numerical system that uses sixteen digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e and f.

Some examples of rgb-colors: 0,0,0 = black, 255,0,0 = red, 0,255,0 = green, 0,0,255 = blue, 255,255,0 = yellow, 255,0,255 = magenta, 0,255,255 = cyan and 255,255,255 = white.

In other words, the values are written with a numerical system that uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

I think it's much easier to use the same numerical system I normally use for color code instead of a numerical system I normally don't use.

There are perhaps advantages with using hexcolors in CSS documents that I'm not aware of, but according to my experience the result doesn't differ much (if at all) if you use RGB colors instead.

To get blue text, use this CSS code:

.blue {color:rgb(0,0,255);}

And this HTML code:

<p class="blue">The text returns blue.</p>

To get blue text and grey background, use this CSS code:

.blue_and_grey {color:(0,0,255); background:rgb(224,224,224);}

And this HTML code:

<p class="blue_and_grey">The text returns blue. The background returns grey.</p>

Would you like to comment on this page or some other page? Use the contact form. Write the title of the page you want to comment on and your comment in the field Message.