Practice: HTML Text Fundamentals
Emphasis and Importance
In human language, we often emphasize certain words to alter the meaning of a sentence, and we often want to mark certain words as important or different in some way. HTML provides various semantic elements to allow us to mark up textual content with such effects, and in this section, we'll look at a few of the most common ones.
Emphasis
When we want to add emphasis in spoken language, we stress certain words, subtly altering the meaning of what we are saying. Similarly, in written language we tend to stress words by putting them in italics. For example, the following two sentences have different meanings.
I am glad you weren't late.
I am glad you weren't late.
The first sentence sounds genuinely relieved that the person wasn't late. In contrast, the second one sounds sarcastic or passive-aggressive, expressing annoyance that the person arrived a bit late.
In HTML we use the <em>
(emphasis) element to mark up such instances. As well as making the document more interesting to read, these are recognized by screen
readers and spoken out in a different tone of voice. Browsers style this as italic by default, but you shouldn't use this tag purely to get italic styling. To do that, you'd use a <span>
element
and some CSS, or perhaps an <i>
element (see below).
<p>I am <em>glad</em> you weren't <em>late</em>.</p>
Strong importance
To emphasize important words, we tend to stress them in spoken language and bold them in written language. For example:
This liquid is highly toxic.
I am counting on you. Do not be late!
In HTML we use the <strong>
(strong importance) element to mark up such instances. As well as making the document more useful, again these are recognized
by screen readers and spoken in a different tone of voice. Browsers style this as bold text by default, but you shouldn't use this tag purely to get bold styling. To do that, you'd use a <span>
element
and some CSS, or perhaps a <b>
element (see below).
<p>This liquid is <strong>highly toxic</strong>.</p>
<p>I am counting on you. <strong>Do not</strong> be late!</p>
You can nest strong and emphasis inside one another if desired:
<p>This liquid is <strong>highly toxic</strong> —
if you drink it, <strong>you may <em>die</em></strong>.</p>
Active learning: Let's be important!
In this active learning section, we've provided an editable example. Inside it, we'd like you to try adding emphasis and strong importance to the words you think need them, just to have some practice.
Live output
Editable code
Press Esc to move focus away from the code area (Tab inserts a tab character).
If you get stuck, you can always press the Show solution button.
Italic, bold, underline...
The elements we've discussed so far have clearcut associated semantics. The situation with <b>
, <i>
,
and
<u>
is somewhat more complicated. They came about so people could write bold, italics, or underlined text in an era when CSS was still supported poorly or
not at all. Elements like this, which only affect presentation and not semantics, are known as presentational elements and should no longer be used because, as we've seen before, semantics is so important to accessibility,
SEO, etc.
<i>
is used to convey a meaning traditionally conveyed by italic: foreign words, taxonomic designation, technical terms, a thought...<b>
is used to convey a meaning traditionally conveyed by bold: key words, product names, lead sentence...<u>
is used to convey a meaning traditionally conveyed by underline: proper name, misspelling...
A kind warning about underline: People strongly associate underlining with hyperlinks. Therefore, on the web, it's best to underline only links. Use the <u>
element
when it's semantically appropriate, but consider using CSS to change the default underline to something more appropriate on the web. The example below illustrates how it can be done.
<!-- scientific names -->
<p>
The Ruby-throated Hummingbird (<i>Archilochus colubris</i>)
is the most common hummingbird in Eastern North America.
</p>
<!-- foreign words -->
<p>
The menu was a sea of exotic words like <i lang="uk-latn">vatrushka</i>,
<i lang="id">nasi goreng</i> and <i lang="fr">soupe à l'oignon</i>.
</p>
<!-- a known misspelling -->
<p>
Someday I'll learn how to <u style="text-decoration-line: underline; text-decoration-style: wavy;">spel</u> better.
</p>
<!-- Highlight keywords in a set of instructions -->
<ol>
<li>
<b>Slice</b> two pieces of bread off the loaf.
</li>
<li>
<b>Insert</b> a tomato slice and a leaf of
lettuce between the slices of bread.
</li>
</ol>