Introduction to CSS Colors - Six Revisions |
Posted: 05 Jan 2015 02:00 AM PST We’ll cover all the available methods for specifying colors with CSS in this guide.
There are six ways to declare CSS colors:
HexadecimalExample Result
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 In CSS hex color notation:
A valid CSS hex color starts with a hash ( 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:
What if we wanted blue? We can set the amount of blue to the maximum value (i.e. FF):
Result
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.
Result
In the hex numeral system, 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:
RGBExample Result
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:
Result
RGBAExample Result 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:
For an in-depth discussion of RGBA, read this: A Guide to CSS RGBA Colors. HSLExample Result
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%.
Result
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.
Result
If we want a dark red, we can lower the lightness value.
Result
HSLAExample Result 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 KeywordsExample Result
Basic Color NamesCSS has 16 basic color names. Examples of basic color names are Basic Color Names Chart
Extended Color NamesCSS2 and CSS3 introduced a lot more color names. Examples of extended color names are Example Result
Extended Color Names Chart
transparent Color KeywordThe Example currentColor Color KeywordThe For example: Can also be written as: Result
The benefit of using the Related ContentAbout the AuthorThe post Introduction to CSS Colors appeared first on Six Revisions. |
You are subscribed to email updates from Six Revisions To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States |
No comments:
Post a Comment