Text Formatting — HTML

A text formatting tag wraps some of the words inside a paragraph. The sentence itself stays as it was. <strong> (bold) is for what's important, <em> (italic)…

Sometimes only one or two words in a sentence need to look different: bold because they're important, italic because they're a foreign term, or highlighted in yellow. To do that, wrap just those words in a tag, right inside their paragraph. Tags that mark words inside a sentence are called text formatting tags.

Wrap the words inside the sentence

Here is a sentence with a few words in bold:

<p>Sign-up closes <strong>tomorrow at 12 noon</strong>.</p>

What the browser shows: the sentence stays whole, with no line break. Only "tomorrow at 12 noon" is bold. You don't type the sentence again. You only insert an opening tag and a closing tag between its words.

Same look, different meaning

<strong> makes text bold. So does <b>. So why are there two? Because they mean different things. HTML has two tags for bold and two tags for italic:

Tag Looks Means
<strong> bold the content is important or urgent
<b> bold it only draws attention, like a keyword
<em> italic a word you stress when you say it
<i> italic italic by writing convention: a scientific name, a foreign term

On screen, <strong> and <b> look the same, and so do <em> and <i>. The difference is in what each tag means. Programs like screen readers (which read pages aloud for blind users) read the tags in the HTML, not the look. From <strong> and <em>, such a program knows that the words inside are important or stressed. <b> and <i> don't carry that meaning. But with their default settings, most screen readers don't read those words in a different voice. So the sentence itself must still make clear what is important.

An <em> example: "I didn't say you were wrong." Say it out loud: "didn't" is the word you stress. An <i> example: the scientific name for rice, Oryza sativa. The name is italic because that is the rule for writing it, not because it's stressed.

In short:

Later, with CSS (the language for setting the look), you can also make any text bold. It looks just as bold, but it doesn't have the "important" meaning. So choose the tag by its meaning first. The look is CSS's job.

Highlight, strike-through, raised and lowered text

⚠️ Where inserting tags goes wrong

TL;DR: A text formatting tag wraps some of the words inside a paragraph. The sentence itself stays as it was. <strong> (bold) is for what's important, <em> (italic) for what's stressed. <b> is also bold and <i> is also italic, but they are only a look, with no extra meaning. <i> is for scientific names and foreign terms, while film and book titles use <cite>. Others: <mark> highlights, <del> puts a line through text, <sup> and <sub> are for powers and formulas. Choose the tag by its meaning, the look is CSS's job.

⚡ Wrap just the words

Write:

<p>Sign-up closes <strong>tomorrow at 12 noon</strong>.</p>
Guess first: which part looks different in the browser?

Only "tomorrow at 12 noon", which shows in bold. The sentence stays whole, on one line.

Meaning: Insert the opening tag right before the words you want to mark, and the closing tag right after them. You don't need to type the sentence again.

⚡ Bold that means something

Write:

<p><strong>Don't</strong> touch the cable.</p>
<p>I <em>didn't</em> say you were wrong.</p>

Meaning: <strong> is bold because it's important, <em> is italic because it's stressed when spoken. The meaning is stored in the code, for programs that read it, such as a screen reader (a program that reads the page aloud). It stays even when CSS changes the look. <b> is also bold and <i> is also italic, but they are only a look, with no meaning. Choose the tag by its meaning, the look is CSS's job.

⚡ Highlight, strike, up and down

Write:

<p><mark>Sale</mark> <del>$50</del> $35</p>
<p>Area 9 m<sup>2</sup>, water is H<sub>2</sub>O.</p>

Meaning: <mark> highlights, <del> puts a line through text, <sup> raises text (powers), <sub> lowers it (formulas).

What you will learn