7.1. Methods of Formatting Text

Previous chapters have shown you how to format different block elements. You have seen many tags that can be used to format large chunks of a document. As you can imagine, there are several additional tags and methods to format text. However, the road through text formatting options is complex; many of the text formatting methods used in previous versions of HTML have been deprecated. Still, many other legacy methods still survive in XHTML. The following sections detail some of the more popular methods of formatting text.

7.1.1. The Font Tag

The font tag (<font>) used to be the predominant way to control text within documents. However, with HTML 4.01 (and hence, XHTML) the <font> tag was deprecated and should not be used. To aid in understanding legacy document coding, the format of the <font> tag is as follows:

<font face="font_name" size="relative_size"
color="font_color">...text...</font>

The font size is given relative to the default document font size. The default size is typically controlled via the <basefont> tag (also deprecated). The <basefont> tag supports the same arguments as the <font> tag, but it has no closing mate.

Default font types and sizes are left up to the user agent. No standard correlation exists between the size used in a <font> tag and the actual font size used by the user agent.

To be XHTML compliant, you should use CSS methods for font control.

7.1.2. Inline Text Attributes

Several tags still exist in the XHTML standard ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.