How to Use and Set CSS text color property?

What is text color property?

The color property is used to set the text color in CSS. You can specify the color of each element’s text separately. For example color of headings, link, paragraphs, Divs, list items etc.

However, if no color is given, the default is taken from body selector.

How to use the CSS color property?

Following is the syntax of using the color property:

color:#003399;

OR

color: red;

OR

color: rgb(33,45,55)

The text color can be set by using:

Hexadecimal value: This value is given by using a hash sign (#) and up to 6 HEX values (0-F).

Color name: Giving a color name like red, green, yellow etc. Generally, this is not the preferred method.

RGB: RGB stands for Red, Green, and Blue. It defines the values of red, green and blue at the range of 0-255 for each. For example, for the R part if it is set to 0 means no red and 255 would mean full red.

Example of using the text color property

In this example we will set the color of heading 1, heading 2, and paragraph with the color value in HEX, color name, and RGB value respectively. See the online demonstration by clicking the link or image below:

CSS color text

Experience this example online



You can see, by using the color CSS property, the color of the text of three different HTML elements are set along with the background colors.

Further Reading: CSS text


Was this article helpful?

Related Articles

Leave A Comment?