Introduction to CSS Colors

We’ll cover all the available methods for specifying colors with CSS in this guide.

There are six ways to declare CSS colors:



div {
 background-color: #000000;



Hexadecimal color notation is a way of declaring a color by indicating the amount of red, green and blue (RGB) it has.

This color notation is based on the hexadecimal numeral system (base 16).

We’re more accustomed to the decimal numeral system (base 10), so hex is a bit tricky to understand at first.

In the example above, black was declared as #000000, which means it has no red, green or blue. (Color theory tells us that the absence of any color is black.)

In CSS hex color notation:

How to read hex color notation

A valid CSS hex color starts with a hash (#) followed by either six characters or three characters. Characters can be between 0-9 and A-F (or lowercase a-f).

The minimum value of each color channel is 00, which is equal to 0 in the decimal numeral system.

The maximum value of each color channel is FF, which is equal to 255 in the decimal numeral system.

So, knowing all of that, if we specify black, then:

RedGreenBlueHex color notation
00 (0 in decimal)00 (0 in decimal)00 (0 in decimal)#000000

What if we wanted blue?

We can set the amount of blue to the maximum value (i.e. FF):

RedGreenBlueHex color notation
00 (0 in decimal)00 (0 in decimal)FF (255 in decimal)#0000FF



We can specify a vast amount of colors simply by adjusting the amount of red, green and blue in the color.

Let’s say we wanted get the color purple. We can do this by mixing together a bit of red with a bit of blue, and by leaving out any green.

RedGreenBlueHex color notation
80 (128 in decimal)00 (0 in decimal)80 (128 in decimal)#800080



In hex color notation, two consecutive characters that are identical can be shortened to just one character. That’s why CSS hex color notation can also be written with just 3 characters.

For example:

For alphabetic characters, you can use lowercases.

For example:



div {
 background-color: rgb(0, 0, 0);



The decimal numeral system is what we’re most used to. It’s usually the system we’re taught in school, and it’s how most numbers are displayed in our world.

The hexadecimal numeral system, on the other hand, isn’t mainstream; it isn’t used much outside computer programming and math-related fields.

RGB color notation is a more intuitive way of declaring CSS colors because it uses the decimal numeral system.

The syntax format is:

rgb(red, green, blue)

OK, so we already know that:

Blue can be specified as:

RedGreenBlueRGB color notation
00255rgb(0, 0, 255)





div {
 color: rgba(255, 255, 255, 0.20);
 background: url(bg.jpg) no-repeat center center;


Sample Text

RGBA is just an extension of RGB, with an added alpha (A) parameter that specifies the level of transparency/opacity the color has. Thus, we can use RGBA color values to make HTML elements semi-transparent.

Alpha can be a value between 0 and 1.

The basic format of RGBA is:

rgba(red, green, blue, alpha)

If we want blue with 25% opacity:

RedGreenBlueOpacityRGBA color notation
002550.25rgba(0, 0, 255, 0.25)

For an in-depth discussion of RGBA, read this: A Guide to CSS RGBA Colors.



div {
 background-color: hsl(240, 100%, 50%);



HSL stands for Hue, Saturation and Lightness.

The HSL color notation is an alternative to the RGB color notation. It was introduced to CSS with the idea that it’s more intuitive to learn compared to the RGB color system.

The basic syntax is:

hsl(hue, saturation, lightness)

Hue refers to the colors we can see. The range of colors visible to the human eye can be charted in a circle, often referred to as the color wheel. Therefore, hue can be a value between 0 and 360.


Looking at the color wheel above, we can see that red is at 0o, green is at 90o, purple is at 270o, and so forth.

Saturation refers to the vividness or "colorfulness" of the hue. A low saturation value leads to a muted hue, while a high saturation value leads to a brighter hue. Saturation can be between 0% and 100%.

Lightness refers to how light or dark the hue is. The higher the value, the lighter the color is. Lightness can also be a value between 0% and 100%.

It’s easy to look at saturation and lightness as the fine-tuning of the hue.

Let’s say we want a pure red. Looking at the color wheel again, red is at 0o. So to get pure red, we can set the saturation to 100% to get the maximum amount of red color, and lightness to 50%.

HueSaturationLightnessHSL color notation
0100%50%hsl(0, 100%, 50%)



If we wanted to have a muted/dull red, we can still use the same hue. We just need to lower the saturation to reduce the color’s vividness.

HueSaturationLightnessHSL color notation
050%50%hsl(0, 50%, 50%)



If we want a dark red, we can lower the lightness value.

HueSaturationLightnessHSL color notation
0100%25%hsl(0, 100%, 25%)





div {
 color: hsla(120, 100%, 50%, 0.2);
 background: url(bg.jpg) no-repeat center center;


Sample Text

HSLA is just like HSL with an added Alpha (A) parameter that allows us to specify the level of transparency/opacity of the color.

The basic syntax is:

hsla(hue, saturation, lightness, alpha)

Alpha can be a value between 0 and 1.

Color Keywords


div {
 background-color: fuchsia;



Basic Color Names

CSS has 16 basic color names. Examples of basic color names are blue, maroon, black and white.

Basic Color Names Chart

ColorColor NameHex


Extended Color Names

CSS2 and CSS3 introduced a lot more color names. Examples of extended color names are thistle, crimson and saddlebrown.


div {
 background-color: olivedrab;



Extended Color Names Chart

ColorColor NameHex


transparent Color Keyword

The transparent color keyword is simply a way to say that the color has 0% opacity.


div {
 background-color: transparent;

currentColor Color Keyword

The currentColor color keyword is a convenience keyword that just means the color being declared is equal to the CSS color property value:

For example:

div {
 color: blue;
 border: 1px solid blue;
 box-shadow: 2px 2px 15px blue;
 background: blue;

Can also be written as:

div {
 color: blue;
 border: 1px solid currentColor;
 box-shadow: 2px 2px 15px currentColor;
 background: currentColor;



The benefit of using the currentColor color keyword is that if you need to update a rule-set, you only need to update the color property value.

Related Content

About the Author

Jacob Gube is the founder of Six Revisions and a front-end web developer. Join him on Twitter @sixrevisions and Facebook.

This was published on Jan 5, 2015


This is awesome!!! Definitely a new bookmark I’ll be returning to often – thanks, Jacob! :D

Darin Spears Jan 05 2015

Brilliant tutorial Jocob! First time I saw some body explaining the basics of CSS so clearly and so well.Great Job!

Jacob Gube Jan 05 2015

@Dreama and @Dreama Thank you for the encouragement!

rebeccapurple: #663399 102,51,153 – wouldn’t have thought you’d have missed this one.

Great reference article, will bookmark and share.

Preston Jan 07 2015

This is one of complete guide to css colors, I’d say. Awesome post and Great work. I am not designer, so I always wondered why some sites use RGB and not # in their CSS. Really great work

Sharing this article on my profiles.

This is excellent work jacob, Definately deserves a bookmark for reference :)

Overcomplete article on CSS colors, simple and to the point! Thank you.

Mick Kennys Jan 08 2015

As a CSS newbie I found this really useful. Your sight Sir goes to my favourites!

Myra Kirbi Jan 09 2015

I am a designer myself but never thought of or even came across some body explaining CSS colors in such detail and with so much clarity. Nice effort!

Very informative article and very good quality of publication. Many thanks !

21coders Jan 13 2015

Beautifully described, truly factual article.

Great article, clearly written. However, on one small point, to help avoid confusion:

“In the hex numeral system, two consecutive characters that are identical can be shortened to just one character.”

The hex system itself does not provide the shortened notation because there are no clues for the reader to know that it had been shortened. However, CSS (and perhaps other languages and applications), allow the user to shorten a six-character color to a three-character color if and only if the color is made up of three pairs of identical digits.

Remember that each PAIR of hex digits represents a color (R, G, or B) in CSS. If a color pair is made up of identical digits, then those digits can be abbreviated, but you must do that to all three colors, because CSS only recognizes 3 or 6-character combinations, not 4 or 5.

For example, #00cc33 can be shortened to #0c3. But #411e55 canNOT be shortened to #41e5 because the pairing is happening across the colors instead of within them, and the browser wouldn’t know which digits were duplicates.

Passerby Jan 14 2015

When you create the hex for purple, it is missing the extra 0 for green channel.

#80080 should be #800080

Jacob Gube Jan 15 2015

@Todd: You’re right. That was a mistake. I actually caught that just now too, before reading your comment. What I meant was hex color notation allows for that, not the hex numeral system.

Your second point is good to point out as well. That’s why I was clear to say that hex can be written with either 6 characters or 3 characters (that point was mentioned twice in the article). I feel like I need to clarify that point even further. Thoughts?

@Passerby: Thank you and I hope you aren’t just a passerby because I can use all the help I can get catching these egregious errors! I’ve corrected the error just now.

This comment section is closed. Please contact us if you have important new information about this post.