HTML Tutorial menu

HTML Text Formatting

HTML has special tags to make parts of a text bold, italic, highlighted, smaller and more.

Bold and Important Text

<b> makes text bold only for looks. <strong> makes text bold and tells the browser the text is important.

Example

html
<!DOCTYPE html>
<html>
<body>

<p>This shirt is <b>blue</b>.</p>
<p><strong>Warning:</strong> Do not wash in hot water.</p>

</body>
</html>
Try it Yourself »

Italic and Emphasised Text

<i> shows italic text, often for a foreign word, a name or a thought. <em> adds emphasis, and screen readers say it with stress.

Example

html
<!DOCTYPE html>
<html>
<body>

<p>My grandmother calls it <i>chai</i>, never tea.</p>
<p>You <em>must</em> bring your ID card to the exam.</p>

</body>
</html>
Try it Yourself »

Prefer <strong> and <em> when the words really are important or stressed. They carry meaning, which helps accessibility and search engines.

Highlighted, Small, Deleted and Inserted Text

Example

html
<!DOCTYPE html>
<html>
<body>

<p>Remember: the test is on <mark>Friday</mark>.</p>
<p>Laptop bag: <del>Rs 3500</del> <ins>Rs 2800</ins></p>
<p><small>Prices include tax.</small></p>

</body>
</html>
Try it Yourself »
Output
Remember: the test is on Friday.          (Friday highlighted)
Laptop bag: Rs 3500 Rs 2800               (old price crossed out, new price underlined)
Prices include tax.                       (smaller text)

Subscript and Superscript

<sub> puts text slightly below the line; <sup> puts it slightly above. They are common in science and maths.

Example

html
<!DOCTYPE html>
<html>
<body>

<p>Water is H<sub>2</sub>O.</p>
<p>The area is 25 m<sup>2</sup>.</p>
<p>The 1<sup>st</sup> batch starts in March.</p>

</body>
</html>
Try it Yourself »

All Formatting Tags

TagMeaningLooks like
<b>Bold text, no extra meaningBold
<strong>Important textBold
<i>Alternate voice, foreign wordItalic
<em>Emphasised textItalic
<mark>Highlighted textYellow background
<small>Side notes, fine printSmaller
<del>Removed textLine through
<ins>Added textUnderlined
<sub>SubscriptLowered
<sup>SuperscriptRaised

Combining Tags

You can nest formatting tags. Close them in the reverse order you opened them.

Example

html
<p><strong><em>Last day to apply!</em></strong></p>

Exercise

Exercise

Which tag marks text as important and shows it in bold?

Learn HTML with a teacher

Join the Web Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp