How to change font family of heading using CSS?

Answer

To change font family of heading using CSS, you can set the font-family style property for the heading 2 elements with the values like cursive, Tahoma, fantasy, etc.

CSS Code

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

Using cursive style font

h2 {
   font-family: cursive;
}

Using Tahoma font family

h2 {
   font-family: Tahoma;
}

Using fantasy font

h2 {
   font-family: fantasy;
}

Examples

We shall go through some working examples on how to change font family of heading using CSS. In the following examples, you may change the value of font-family 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 family of heading using cursive style font.

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

Example 2

This is an example on how to change font family of heading using Tahoma font family.

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

Example 3

This is an example on how to change font family of heading using fantasy font.

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