How to set text font family in HTML?

To change the text font family in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-family. HTML5 do not support the <font> tag, so the CSS style is used to add font size.

Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML <style> tag or external style sheet.


You can try to run the following code to change the text font family in an HTML page

Live Demo

<!DOCTYPE html>
      <title>HTML Font Family</title>

      <h1>Our Products</h1>
      <p style="font-family:georgia,garamond,serif;">
         This is demo text

Updated on: 31-Oct-2023

24K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started