HTML
HTML introduction
HTML basics
HTML text format 1
HTML text format 2
HTML text format 3
HTML links
HTML images
HTML image maps
HTML forms
Fieldset/legend tags
Email links
HTML labels
HTML tables
HTML frames
HTML backgrounds
HTML colors
HTML color shades
HTML color usage
HTML marquees
HTML fonts
HTML entities
HTML stylesheets
HTML layout
HTML div/span
HTML audio
HTML video
HTML objects
HTML d'load media
HTML meta tags
HTML scripts
HTML declarations
HTML head section
HTML document types
HTML tag rules
HTML things to avoid
URL formatting
Encoding and decoding
HTML use/access
HTML publish work
History of HTML
HTML summary

Programming

Programming intro
Java

Markup

First webpage guide
XHTML

Style & Layout

CSS

Browser scripting

Javascript
VBScript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

HTML font

What would text on the web be if there was no way to style it? Surely, a page would not have much character. Font is an important element on the world wide web. The default appearance of text is not very exciting, but with fonts you can change it by adding much style to your text.

This lesson focuses on:

The <font> tag

With the <font> tag you can set the size, color, and font of text.

Attributes of the <font> tag
  • size - Sets the size of text.

    Possible values: a number from 1 to 7, +number (increases the default size), -number (decreases the default size)

  • face - Sets the font of text.

    Possible values: a font name such as Arial, Verdana, Helvetica

  • color - Sets the color of text.

    Possible values: a color name, hexadecimal value, or RGB value.
    If you are not familiar with color naming convention in HTML, read our HTML colors page.

Example:

<font size="5"> Text in font size 5 </font> <br /> <font size="+2" face="Georgia" color="green"> Text in a font size that is two sizes bigger than the default size in a Georgia font that is also green </font> <br /> <font size="-1" face="Arial" color="gray"> Text in a font size that is one size smaller than the default size in an Arial font that is also gray </font>

Output:

Text in font size 5 Text in a font size that is two sizes bigger than the default size in a Georgia font that is also green Text in a font size that is one size smaller than the default size in an Arial font that is also gray

The <font> tag is deprecated in HTML 4.01 and above. CSS should be used instead.

The <basefont> tag

The <basefont> tag can be used to specify a general appearance for text on a webpage. It should be placed right after the <body> tag.

NOTE: The <basefont> tag has the same attributes as the <font> tag.

Example:

<html> <head> <title>Basefont</title> </head> <body> <basefont size="5" face="Verdana, Arial, Helvetica" color="blue" /> This text will be in a size of 5, have a Verdana font, and will be blue </body> </html>

Output:

This text will be in a size 5, have a Verdana font, and will be blue

NOTE: If you specify a list of fonts with the face attribute like in the above example, the visitor's web browser will use the first font in the list that is available on the visitor's computer. Meaning, if someone is viewing a webpage and their computer does not support the first font you specify, the browser will try the second font and so on until it gets to a font that is supported. This applies to the <basefont> tag as well as the <font> tag.

The <basefont> tag:

Different Fonts

There are many different fonts available to use, but it is generally a good idea to use the common ones since those are what most peoples computers support.

Common fonts example:

<font face="Arial">This text is in an 'Arial font'</font> <font face="Comic Sans MS">This text is in a 'Comic Sans MS' font (NOTE: The 'Comic Sans MS' font is highly frowned upon)</font> <font face="Courier New">This text is in a 'Courier New' font</font> <font face="Georgia">This text is in a 'Georgia' font</font> <font face="Lucida Console"> This text is in a 'Lucida Console' font </font> <font face="Tahoma">This text is in a 'Tahoma' font</font> <font face="Times New Roman"> This text is in a 'Times New Roman' font </font> <font face="Trebuchet MS">This text is in a 'Trebuchet MS' font</font> <font face="Verdana">This text is in a 'Verdana' font</font> <font face="MS Serif">This text is in a 'MS Serif' font</font>

Output:

This text is in an 'Arial font' This text is in a 'Comic Sans MS' font (NOTE: The 'Comic Sans MS' font is highly frowned upon) This text is in a 'Courier New' font This text is in a 'Georgia' font This text is in a 'Lucida Console' font This text is in a 'Tahoma' font This text is in a 'Times New Roman' font This text is in a 'Trebuchet MS' font This text is in a 'Verdana' font This text is in a 'MS Serif' font

Transition to CSS

The <font> tag and <basefont> tag are both deprecated in HTML 4.01 and above. CSS should be used instead.

Of all the tags and attributes that have been deprecated in favor of CSS, the <font> tag and the <basefont> tag are among those whose exit is the most significant. Font is one of those things that is all about styling. Having such tags in HTML is not correct, and the W3C realized this when they deprecated them in favor of CSS.

With the <font> tag, you have to specify text for so many different elements. Imagine what it would be like to have to go and change 5, 10, even 20 different styles manually? Such is the case with the <font> tag.

The <basefont> tag does make things easier. Since it dictates a universal style, it is easier to change things with it when necessary, but still requires editing HTML files.

The transition to CSS allows for a declaration of font styles in a separate language (and no editing of HTML files required). This makes things so much easier for the web developer as changing font styles does not require editing any tags but rather declarations that will affect the font styles of elements which you specify.

If you want to jump right into styling fonts with CSS, read our CSS font properties page.

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments