How to change text font in HTML?


To change the text font 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, font-size, font-style, etc.

HTML5 do not support the <font> tag, so the CSS style is used to change font. The <font> tag deprecated in HTML5.

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.

HTML Text Font

Example

You can try to run the following code to change the font in HTML

Live Demo

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

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

</html>

Updated on: 06-Sep-2023

41K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements