HTML Formatting

What is HTML Formatting?

HTML provides various formatting elements that allow you to style text without using CSS. These elements make text bold, italic, underlined, and more. However, many of these formatting elements have been deprecated in HTML5 in favor of CSS styling.

Text Formatting Elements

Bold Text

The <b> tag makes text bold. The <strong> tag also makes text bold, but indicates that the text is important:

Example
<p>This is <b>bold</b> text.</p>
<p>This is <strong>strong</strong> text (semantically important).</p>

Italic Text

The <i> tag makes text italic. The <em> tag also makes text italic, but indicates emphasis:

Example
<p>This is <i>italic</i> text.</p>
<p>This is <em>emphasized</em> text.</p>

Underlined Text

The <u> tag underlines text. The <ins> tag also underlines text, but indicates inserted text:

Example
<p>This is <u>underlined</u> text.</p>
<p>This is <ins>inserted</ins> text.</p>

Strikethrough Text

The <s> tag strikes through text. The <del> tag also strikes through text, but indicates deleted text:

Example
<p>This is <s>strikethrough</s> text.</p>
<p>This is <del>deleted</del> text.</p>

Marked/Highlighted Text

The <mark> tag highlights text:

Example
<p>This is <mark>highlighted</mark> text.</p>

Small Text

The <small> tag makes text smaller:

Example
<p>This is normal text. <small>This is small text.</small></p>

Superscript and Subscript

The <sup> tag creates superscript text, and the <sub> tag creates subscript text:

Example
<p>This is <sup>superscript</sup> text.</p>
<p>This is <sub>subscript</sub> text.</p>
<p>H<sub>2</sub>O (water)</p>
<p>E = mc<sup>2</sup></p>

Deprecated Formatting Elements

The following elements are deprecated in HTML5 and should be avoided. Use CSS instead:

<font> (Deprecated)

The <font> tag was used to specify font face, size, and color. Use CSS instead:

Example - Don't Use (Deprecated)
<font color="red" size="5" face="Arial">Old way (deprecated)</font>
Example - Modern Way (CSS)
<p style="color: red; font-size: 18px; font-family: Arial;">Modern way with CSS</p>

<center> (Deprecated)

The <center> tag was used to center text. Use CSS text-align: center instead:

Example - Modern Way (CSS)
<p style="text-align: center;">Centered text</p>

Complete Formatting Example

Example
<p>
    This paragraph contains <b>bold</b>, 
    <i>italic</i>, 
    <u>underlined</u>, 
    <mark>marked</mark>, 
    <small>small</small>, 
    <del>deleted</del>, 
    <ins>inserted</ins>,
    <sub>subscript</sub>, and 
    <sup>superscript</sup> text.
</p>

Best Practices

Formatting Element Reference

Tag Description
<b> Bold text
<strong> Important text (bold)
<i> Italic text
<em> Emphasized text (italic)
<u> Underlined text
<ins> Inserted text (underlined)
<s> Strikethrough text
<del> Deleted text (strikethrough)
<mark> Marked/highlighted text
<small> Smaller text
<sub> Subscript text
<sup> Superscript text