Skip to content
Laviyx Learn

Try

HTML course menu

HTML Text Formatting: strong, em, mark, small, sub, sup, code and More

Learn HTML text formatting elements: strong vs b, em vs i, mark, small, del and ins, sub and sup, code, kbd, samp and var, with examples of when to use each one.

Beginner4 min readUpdated
On this page

HTML has a set of inline elements that give meaning to words and phrases inside a paragraph: importance, emphasis, highlights, code and more. Each one also has a default look, but it is the meaning that matters.

Importance and emphasis: strong and em#

HTML
<p><strong>Warning:</strong> do not touch the wires.</p>
<p>I <em>really</em> want to learn HTML.</p>
<p>I really want to learn <em>HTML</em>.</p>
Result
  • <strong> marks text as important, serious or urgent. Browsers show it in bold.
  • <em> marks stress emphasis, the word you would stress when speaking. Browsers show it in italics. Moving the <em> changes the meaning of the sentence, as the last two lines show.

b and i#

<b> and <i> also produce bold and italic text, but without adding importance or stress:

HTML
<p>The <b>mango</b> is the national fruit of India.</p>
<p>The word <i lang="fr">déjà vu</i> comes from French.</p>
Result
  • <b> draws attention to a keyword or product name without making it more important.
  • <i> is for text in a different voice: foreign words, technical terms, thoughts, ship names.
You want to sayUse
"This is important"<strong>
"Stress this word"<em>
"Notice this keyword" (no extra importance)<b>
"This is a term, a foreign phrase or a title"<i>
"Make this bold" (just looks)CSS font-weight

Highlights, fine print and edits#

HTML
<p>Search results for "rice": brown <mark>rice</mark> recipes</p>
<p><small>Prices include tax. Offer valid until stocks last.</small></p>
<p>Price: <del>₹999</del> <ins>₹749</ins></p>
<p><s>Ticket bookings open on Monday.</s> Bookings are now closed.</p>
Result
ElementMeaning
<mark>Highlighted because it is relevant, such as a search match
<small>Side comments and fine print
<del> / <ins>Text removed from / added to a document (edits)
<s>Text that is no longer accurate or relevant

Subscript and superscript#

HTML
<p>Water is H<sub>2</sub>O.</p>
<p>The area is 25 m<sup>2</sup>, and E = mc<sup>2</sup>.</p>
Result

<sub> lowers text (chemical formulas) and <sup> raises it (powers, footnote markers).

Code and computer text#

HTML
<p>Use the <code>print()</code> function to show output.</p>
<p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save.</p>
<p>The program replied: <samp>File not found</samp></p>
<p>The area is <var>length</var> × <var>width</var>.</p>
Result
ElementMeaning
<code>A piece of computer code
<kbd>Keyboard input the user types or presses
<samp>Sample output from a program
<var>A variable in maths or programming

For whole blocks of code, put <code> inside <pre> so the spacing is kept:

HTML
<pre><code>for i in range(3):
    print(i)</code></pre>
Result

Common mistakes#

Practice#

Practice exercise

Write a paragraph that tells the reader to press Ctrl + C to copy, where "Note:" at the start is marked as important, and a second paragraph showing that the formula for carbon dioxide is CO₂ using the correct element for the 2.

Show solution
HTML
<p><strong>Note:</strong> press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy.</p>
<p>Carbon dioxide is CO<sub>2</sub>.</p>
Result

Key takeaway#

Finished this lesson?