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>
<p>and</p>wrap the whole sentence, so the sentence is one paragraph.<strong>is the opening tag. It goes right before the words you want to mark.tomorrow at 12 noonis the marked text.</strong>is the closing tag. It goes right after those words. The rest of the sentence, including the full stop at the end, stays outside<strong>.
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:
- If the content is important, use
<strong>. - If it's a word you stress when you speak, use
<em>. - If it only needs a different look, use
<i>for a scientific name or a foreign term, and<b>for a keyword. - For the title of a work, such as a film or a book, use
<cite>. It is italic too.
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
<mark>: the text looks marked with a yellow highlighter, for example the words that match a search.<del>: the text shows with a line through it, a sign that the text was deleted or replaced.<sup>: small text raised a little above the line of text, like the power inm<sup>2</sup>.<sub>: small text lowered a little below the line of text, like the number in the formulaH<sub>2</sub>O.
⚠️ Where inserting tags goes wrong
- Wrapping the whole paragraph. An
<i>around the<p>makes the whole sentence italic. Wrap only the words you mean. <u>for emphasis.<u>underlines text. Underlined text looks like a link, so people try to click it.- Changing the sentence while adding the tags. A missing space or word makes the paragraph's text different from the original, and the exercise counts it as 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).