Scroll to top
Read Time: 3 min

The color property in CSS is used to specify the color of text content. It allows you to set the foreground color, transforming the appearance of elements and making your content visually engaging. With the color property, you can bring your website to life by selecting from a vast palette of hues.

Syntax and Usage

To set the color property, you assign a value to it. Here’s the syntax:

1
selector {
2
  color: value;
3
}

By default, the color property is inherited, meaning that elements within a container will inherit the color of their parent. However, bear in mind that this property applies to text content exclusively and does not affect background colors or other graphical elements.

Moreover, the color property can be animated using CSS animations. This allows for captivating effects, such as smoothly transitioning from one color to another.

Keyword Values

The color property supports a range of keyword values. Let’s explore some of the most commonly used ones:

color: <named-color>;

There are 163 named colors specified by the W3C. These named colors can be used directly in CSS properties to specify colors without specifying the exact RGB, hexadecimal, or HSL values. 

1
h1 {
2
  color: black;
3
}

Here are some unusual examples of named colors!

  • papayawhip
  • linen
  • honeydew
  • chocolate
  • thistle

color: #008080;

Using a hexadecimal value, such as #008080, allows you to specify a precise color using a combination of red, green, and blue channels. This example sets the color to a beautiful teal shade.

1
a {
2
  color: #008080;
3
}

color: rgb(255, 0, 0);

The rgb() function enables you to define a color by specifying the intensity of its red, green, and blue components. This example sets the color to a vivid red.

1
span {
2
  color: rgb(255, 0, 0);
3
}

color: hsl(240, 100%, 50%);

With the hsl() function, you can define a color using its hue, saturation, and lightness values. This example sets the color to a soothing blue shade.

1
blockquote {
2
  color: hsl(240, 100%, 50%);
3
}

Please note that this list showcases some popular keyword values, but there are many more colors to explore! Feel free to experiment and find the perfect hues for your design.

Learn More

Did you know that the color property can accept transparent values? By setting the color property to transparent, you can make text fully transparent, revealing the background underneath. This technique is handy for creating intriguing effects and overlays.

As the esteemed CSS developer Lea Verou once said:

“Colors are the soul of design. They have the power to evoke emotions and create memorable experiences for users.”

You can find more inspiring insights from Lea Verou at https://lea.verou.me/.

Relevant Tutorials

Enhance your understanding of the color property with these helpful tutorials:

  1. Start Here: Learn CSS Colors and Backgrounds
  2. Blending Modes in CSS: Color Theory and Practical Application

Official Specification and Browser Support

With the knowledge gained from this documentation, you are now equipped to wield the color property effectively and breathe life into your web design. Let your creativity soar as you paint your website with a vibrant palette of colors!

Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.