7.3. Bold and Italic

Two tags are used to designate text as bold (<b>) and italic (<i>). As with other XHTML tags, both tags have opening and closing elements and are used to surround the text you want to modify. For example, consider the following code and the results rendered in a user agent as shown in Figure 7-4:

<p>This is normal text.</p>
<p><b>This is bold text.</b></p>
<p><i>This is italic text.</i></p>

Previous versions of HTML contained an underline attribute. However, the underline tag has been deprecated. Underlining should be accomplished using CSS.

Not every font has a bold and/or italic variant. Whenever possible, the user agent will substitute a similar font when bold or italic is asked for but not available. However, not all user agents are font savvy. In short, your mileage with these tags may vary depending on the user agent being used.

For the same reasons mentioned elsewhere, it is advisable to use CSS instead of hard-coded bold and italic tags.

Figure 7-4. Figure 7-4

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.