Learn how to emphasize, highlight, and format text using HTML elements like strong, em, code, and more.
HTML provides several elements for formatting text. The key principle to understand is the difference between semantic and visual formatting.
Semantic elements describe the meaning or purpose of the text:
<strong> — Indicates strong importance. Browsers display it as bold.<em> — Indicates emphasis. Browsers display it as italic.Visual-only elements describe only how text looks, without conveying meaning:
<b> — Bold text, no added importance.<i> — Italic text, no added emphasis.Always prefer semantic elements. Screen readers and search engines use them to understand your content better. Use <strong> instead of <b> when the text is truly important, and <em> instead of <i> when you are genuinely emphasizing something.
<p><strong>Warning:</strong> Do not touch the hot surface.</p>
<p>HTML is <em>really</em> fun to learn.</p>
<p>The <code>console.log()</code> function prints output to the browser console.</p>
<p>Water is H<sub>2</sub>O and the formula for area is r<sup>2</sup>.</p>
<p>This text has been <del>removed</del> and <ins>replaced</ins>.</p>
<p>Use the <mark>highlighted</mark> keyword in your search.</p>Beyond bold and italic, HTML offers several other useful formatting elements:
<code> — Represents a fragment of computer code. Displayed in a monospace font.<sub> — Subscript text (appears slightly below the normal line, useful for chemical formulas like H₂O).<sup> — Superscript text (appears slightly above the normal line, useful for exponents like x²).<del> — Strikethrough text indicating something has been deleted or is no longer accurate.<ins> — Underlined text indicating an insertion or addition.<mark> — Highlighted text, as if marked with a highlighter pen.You can also nest formatting elements. For example:
<p><strong><em>This text is bold and italic.</em></strong></p>
When nesting, always close tags in the reverse order you opened them.
Which element should you use to mark text as important, rather than just visually bold?