HTML Tutorial: Complete HTML Tutorial
About Lesson

HTML <font> Tag


Concept

The <font> tag in HTML was used to define the font size, color, and face of text in the main body of the webpage. However, it’s important to note that this tag is not supported in HTML5, and the use of CSS is now the recommended method for formatting text.

What to Use Instead?

Since the <font> tag is no longer supported, you should use CSS to achieve the same effects. Here are some examples of how you can replace the <font> tag with CSS:

Example 1: Setting the Color of Text

<p style="color: red;">This text is red.</p>

Example 2: Setting the Font of Text

<p style="font-family: Arial;">This text is in Arial font.</p>

Example 3: Setting the Size of Text

Sponsored by Google
<p style="font-size: 20px;">This text is 20 pixels in size.</p>

Try it out below:

powered by Advanced iFrame. Get the Pro version on CodeCanyon.

CSS Text

You can also define these styles in a separate CSS file or within a <style> tag in the <head> section of your HTML document. Here’s an example:

p {
  color: blue;
  font-family: Verdana;
  font-size: 18px;
}

Conclusion

The <font> tag has been deprecated, and it’s best to use CSS for styling text in modern web development.


By using CSS, you gain more control and flexibility over the appearance of your text, and it ensures that your code is in line with current best practices.