What is HTML Text Formatting?
HTML text formatting refers to using special tags to control the appearance and meaning of text content. Unlike CSS (which handles visual styling), HTML formatting tags often carry semantic meaning — they tell browsers, search engines, and screen readers why text looks a certain way, not just how it looks.
Quick Reference: All Formatting Tags
| Tag | Category | Visual | Semantic Meaning | Example |
|---|---|---|---|---|
| `<b>` | Physical | Bold | None (presentational only) | `<b>Warning</b>` |
| `<strong>` | Semantic | Bold | High importance/urgency | `<strong>Danger</strong>` |
| `<i>` | Physical | Italic | None (presentational only) | `<i>Foreign word</i>` |
| `<em>` | Semantic | Italic | Stress emphasis | `<em>Really</em> important` |
| `<u>` | Physical | Underline | None (avoid for links) | `<u>Misspelled</u>` |
| `<mark>` | Semantic | Highlight | Relevance/search match | `<mark>keyword</mark>` |
| `<small>` | Semantic | Smaller | Fine print/legal text | `<small>Terms apply</small>` |
| `<del>` | Semantic | Strikethrough | Deleted/removed content | `<del>$100</del> $80` |
| `<ins>` | Semantic | Underline | Inserted/added content | `<ins>New feature</ins>` |
| `<sub>` | Physical | Subscript | Typographic | `H<sub>2</sub>O` |
| `<sup>` | Physical | Superscript | Typographic | `E=mc<sup>2</sup>` |
| `<code>` | Semantic | Monospace | Computer code | `<code>console.log()</code>` |
| `<kbd>` | Semantic | Monospace | Keyboard input | `Press <kbd>Ctrl</kbd>+<kbd>S</kbd>` |
| `<samp>` | Semantic | Monospace | Program output | `<samp>Error 404</samp>` |
| `<var>` | Semantic | Italic | Variable name | `<var>x</var> = 10` |
| `<abbr>` | Semantic | Dotted underline | Abbreviation | `<abbr title="Hypertext">HTML</abbr>` |
| `<cite>` | Semantic | Italic | Citation/Reference | `<cite>The Great Gatsby</cite>` |
| `<blockquote>` | Semantic | Indented | Long quotation | `<blockquote>To be...</blockquote>` |
| `<q>` | Semantic | Quotation marks | Short inline quote | `<q>Hello</q>` |
Semantic vs Presentational: The Critical Distinction
Understanding the difference between semantic (meaningful) and presentational (visual-only) tags is crucial for writing accessible, SEO-friendly HTML.
| Presentational (Avoid for meaning) | Semantic (Preferred) | When to Use Each |
|---|---|---|
| `<b>` | `<strong>` | `<strong>` for importance (alerts, warnings). `<b>` only for visual bold without meaning (product names). |
| `<i>` | `<em>` | `<em>` for verbal stress. `<i>` for foreign words, technical terms, or thoughts. |
| `<u>` | `<ins>` or CSS | `<u>` only for misspellings. Use CSS `text-decoration` for underlines. |
Deep Dive: <strong> vs <b>
Deep Dive: <em> vs <i>
Technical & Code Formatting Tags
These tags are essential for documentation, tutorials, and technical writing.
Quotations & Citations
Edits & Changes: <del> and <ins>
Abbreviations & Definitions
Real-World Example: Blog Post with Rich Formatting
Accessibility Considerations
- Screen readers announce
<strong>and<em>with altered tone/emphasis — use them intentionally <b>and<i>receive no special announcement — purely visual- Don't use
<u>for links — users expect underlined text to be clickable (use CSS for link styling) <mark>helps users find search keywords — screen readers announce "highlighted"<abbr>withtitleprovides expansion — essential for accessibility- Never rely on visual formatting alone to convey meaning (color, bold, italics must have text alternatives)
Best Practices Summary
- ✅ Use
<strong>and<em>for semantic importance/emphasis - ✅ Use
<b>and<i>sparingly — only when no semantic meaning is needed - ✅ Use
<mark>to highlight relevant text (search results, quotes) - ✅ Use
<code>,<kbd>,<samp>for technical content - ✅ Use
<del>and<ins>for document revisions (not for styling) - ✅ Use
<abbr>for all abbreviations on first occurrence - ✅ Use
<cite>for creative work titles (books, articles, movies) - ✅ Use
<blockquote>withciteattribute for quotations - ❌ Avoid
<u>for anything other than misspellings - ❌ Don't use formatting tags just for visual effect — use CSS instead
Common Mistakes & Fixes
| ❌ Mistake | ✅ Fix |
|---|---|
| `<b>Important warning</b>` | `<strong>Important warning</strong>` |
| `<i>Really important</i>` | `<em>Really important</em>` |
| Underlining non-link text with `<u>` | Use CSS `text-decoration: underline` or `<ins>` if appropriate |
| `<p><code>function</p></code>` (mismatched nesting) | Always close tags in reverse order |
| Using `<strong>` inside headings unnecessarily | Headings (`<h1>`-`<h6>`) already convey importance |
| Forgetting `title` attribute on `<abbr>` | Always add `title` for screen readers |
CSS Alternative: When to Use CSS Instead
For purely visual effects that carry no meaning, use CSS instead of HTML formatting tags.
Conclusion
HTML formatting tags go far beyond making text bold or italic. They provide semantic meaning that improves accessibility, SEO, and code maintainability. Use <strong> and <em> for meaning, <b> and <i> only when necessary, and leverage technical tags like <code>, <kbd>, and <abbr> for richer content. When in doubt, ask: "Does this formatting carry meaning, or is it just visual?" — if it's just visual, use CSS.