Use CSS to change the font family in HTML

Aug 23rd, 2022

Use CSS to change the font family in HTML

advertisement

To change the font family in the HTML with CSS added the following content to your code,

.font2{
  font-family: "Comic Sans MS";
}

The same goes for different fonts,

<div class="container">
  <p class="font1">Hello world</p>
  <p class="font2">Hello World</p>
  <p class="font3">Hello World</p>
</div>

and to change the font family of all these fonts,

.font1{
  font-family: "Arial", sans-serif;
}

.font2{
  font-family: "Comic Sans MS";
}

.font3{
  font-family: "PT Sans", sans-serif;
}

Live demo,

See the Pen by Dhairya Shah (@dhairyathedev) on CodePen.