Dhairya Shah
Dhairya Shah's Blog

Follow

Dhairya Shah's Blog

Follow
How to use CSS to change the font family in HTML

How to use CSS to change the font family in HTML

Dhairya Shah's photo
Dhairya Shah
·Aug 23, 2022·

1 min read

Play this article

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,

 
Share this