How to change font size of Div using CSS?

Answer

To change font size of Div using CSS, you can set the font-size style property for the div elements with the values like 20px, 2rem, 1.1in, etc.

CSS Code

The following is the typical CSS code to change font size of Div in HTML page using tag name div.

Using pixels

div {
   font-size: 20px;
}

Using font size relative to parent

div {
   font-size: 2rem;
}

Using inches

div {
   font-size: 1.1in;
}

Examples

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

Example 1

This is an example on how to change font size of Div using pixels.

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

Example 2

This is an example on how to change font size of Div using font size relative to parent.

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

Example 3

This is an example on how to change font size of Div using inches.

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