Formatting in HTML
?? Formatting in HTML
HTML provides tags to format text and control its appearance semantically.
Common Text Formatting Tags
| Tag | Description | Example |
|---|---|---|
<b> | Bold text (stylistic) | <b>Bold text</b> |
<strong> | Important/bold (semantic) | <strong>Strong emphasis</strong> |
<i> | Italic text (stylistic) | <i>Italic text</i> |
<em> | Emphasis/italic (semantic) | <em>Emphasized text</em> |
<u> | Underlined text | <u>Underlined</u> |
<mark> | Highlighted text | <mark>Highlighted</mark> |
<small> | Smaller text | <small>Small print</small> |
<del> | Deleted/strikethrough text | <del>Deleted text</del> |
<ins> | Inserted/underlined text | <ins>Inserted text</ins> |
<sub> | Subscript text | H<sub>2</sub>O |
<sup> | Superscript text | E = mc<sup>2</sup> |
<code> | Computer code / monospaced font | <code>console.log('Hi');</code> |
Example
<p>This is <strong>important</strong> and <em>emphasized</em> text.</p><p>Water formula: H<sub>2</sub>O</p><p>Einstein's formula: E = mc<sup>2</sup></p><p>This is <del>old</del> and <ins>new</ins> text.</p>Semantic vs. Stylistic
Use
<strong>and<em>when you want to give meaning (importance or emphasis) — better for accessibility and SEOUse
<b>and<i>purely for visual styling (no semantic meaning)
Want tips on how to style formatted text with CSS or combine formatting tags?