How to change font color of heading using CSS?

Answer

To change font color of heading using CSS, you can set the color style property for the heading 2 elements with the values like #FF0000, Olive, rgb(20, 105, 201), etc.

CSS Code

The following is the typical CSS code to change font color of heading in HTML page using tag name h2.

Using hex color

h2 {
   color: #FF0000;
}

Using color name

h2 {
   color: Olive;
}

Using rgb() function to specify color

h2 {
   color: rgb(20, 105, 201);
}

Examples

We shall go through some working examples on how to change font color of heading using CSS. In the following examples, you may change the value of color and Run the code to visually observe the changes made to the Heading 2 elements.

Example 1

This is an example on how to change font color of heading using hex color.

You may edit the following code, and click on Run button.

Example 2

This is an example on how to change font color of heading using color name.

You may edit the following code, and click on Run button.

Example 3

This is an example on how to change font color of heading using rgb() function to specify color.

You may edit the following code, and click on Run button.