HTML offers a family of inline elements that mark up parts of a sentence. The key idea of this lesson is that each one carries a meaning. Browsers add a default look, but you should choose the element for its meaning and change the look with CSS.
Strong and em#
<!-- strong: serious importance; em: stress emphasis -->
<p><strong>Warning:</strong> the soup is <em>very</em> hot.</p><strong>marks content of strong importance, urgency or seriousness. Browsers show it bold.<em>marks stress emphasis, the word you would lean on when speaking. Browsers show it in italics. Moving<em>to another word changes the meaning of the sentence.
Screen readers can announce both differently, so they help more than a purely visual style does.
b and i#
<b> and <i> also exist. They draw attention or offset text without adding importance or emphasis. Use <b> for a product name in a review and <i> for a technical term, a ship name or a thought.
<p>I ordered the <b>Himalayan Mocha</b> and it was gorgeous.</p>
<p>The barista called it a <i lang="it">cortado</i>.</p>If you only want bold or italic looks, use CSS rather than these elements.
mark, small, del, ins#
<p>Today's special is <mark>cardamom latte</mark>.</p>
<p>Price: <del>Rs. 350</del> <ins>Rs. 300</ins></p>
<p><small>Prices include 13% VAT.</small></p><mark>highlights text that is relevant right now, like a search match.<del>shows removed text and<ins>shows inserted text.<small>marks side comments and fine print such as legal notes.
code, kbd, samp, var#
These elements are essential for technical writing:
<p>Run <code>npm install</code> to fetch dependencies.</p>
<p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save.</p>
<p>The server replied <samp>404 Not Found</samp>.</p>
<p>Set the price to <var>x</var> rupees.</p><code> is a snippet of code, <kbd> is keyboard input, <samp> is sample output from a program, and <var> is a variable name. Browsers show them in a monospace font. For a multi-line block of code, wrap <code> in <pre> to preserve the line breaks.
sub and sup#
<p>Water is H<sub>2</sub>O and our cafe is on the 2<sup>nd</sup> floor.</p><sub> lowers text (chemical formulas) and <sup> raises it (ordinals, powers, footnote marks).
Choosing correctly#
| Need | Element |
|---|---|
| Important warning | <strong> |
| Spoken stress | <em> |
| Highlight a match | <mark> |
| Fine print | <small> |
| Code snippet | <code> |
| Key to press | <kbd> |
Common mistakes#
- Using
<strong>or<em>everywhere. If everything is important, nothing is. - Picking
<i>for emphasis. That is the job of<em>. - Using
<u>for decoration. Underlined text looks like a link, which confuses visitors. - Using
<font>or<center>. They are obsolete; use CSS.
Try it yourself#
Write a short recipe tip for the cafe: a sentence with one important warning, one emphasised word, a highlighted ingredient, a price with the old value struck out and a small fine-print line about allergies. Then write one line of technical text using <code> and <kbd>.
Recap#
Inline text elements carry meaning: strong for importance, em for emphasis, mark for highlights, code and kbd for technical text, and sub and sup for lowered and raised text. Choose by meaning, and use CSS for pure decoration.
Check your understanding
Lesson quiz
OptionalA short quiz to check what you just learned.
- Questions
- 4
- Time limit
- 5 min
- Pass mark
- 70%
- Best score
- -