Aug 23rd, 2022

Use CSS to change the font family in HTML

Author Picture

Dhairya Shah

Software Engineer

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

  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>

and to change the font family of all these fonts,

  font-family: "Arial", sans-serif;

  font-family: "Comic Sans MS";

  font-family: "PT Sans", sans-serif;

Live demo,

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

DigitalOcean Referral Badge