HTML Text Styling

HTML Text Formatting

Master the art of text formatting with HTML elements - from basic styling to semantic markup that enhances meaning and accessibility.

What is the difference between <b> and <strong> in HTML?

<strong> marks text as important and <em> marks stress emphasis. Both carry meaning that screen readers and search engines can use. <b> and <i> only change appearance (bold and italic) without adding importance. Use <strong>/<em> when the meaning matters, and <b>/<i> for stylistic offsets like key terms or foreign words.

<p><strong>Warning:</strong> this cannot be undone.</p>
<p>I <em>really</em> mean it.</p>
<p>Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy.</p>
<p>H<sub>2</sub>O and E = mc<sup>2</sup></p>
<p><mark>Highlighted</mark>, <del>removed</del> and <ins>inserted</ins> text.</p>

Try It: Complete Text Formatting Guide

Explore all HTML text formatting elements in one comprehensive example. Try modifying different elements to see how they affect the appearance and meaning of text.

Code Editor

<p><strong>strong</strong>: important &nbsp; <b>b</b>: just bold</p>
<p><em>em</em>: stress &nbsp; <i>i</i>: alternate voice</p>
<p><mark>mark</mark>, <small>small</small>, <del>deleted</del>, <ins>inserted</ins></p>
<p>H<sub>2</sub>O and E = mc<sup>2</sup></p>
<p>Press <kbd>Ctrl</kbd> + <kbd>C</kbd>, then run <code>npm start</code></p>

Preview

Physical vs Semantic Formatting

Physical Formatting

Physical elements define how text looks but don't add semantic meaning.

Common Physical Elements:

  • <b>Bold text appearance
  • <i>Italic text appearance
  • <u>Underlined text
  • <s>Strikethrough text
  • <small>Smaller text size

Semantic Formatting

Semantic elements define the meaning of content, which browsers and assistive technology can understand.

Common Semantic Elements:

  • <strong>Strong importance
  • <em>Emphasized text
  • <mark>Highlighted relevance
  • <dfn>Definition term
  • <abbr>Abbreviation

Best Practice Recommendation:

Use semantic elements whenever possible. They provide better accessibility, SEO benefits, and are more maintainable. For example, use <strong> instead of <b> when you want to indicate importance, not just bold appearance.

Elements That Add Meaning

Technical Content

<code>

Inline code fragments

console.log("Hello")

<kbd>

Keyboard input

Ctrl+C

<var>

Variables in mathematics/programming

x + y = 10

Reference Content

<cite>

Citations of works

The Great Gatsby

<abbr>

Abbreviations with explanations

HTML

<time>

Dates and times

Quotations and Citations

Inline Quotes

<q>Short quote here</q>

Use for short quotations within paragraphs. Browsers automatically add quotation marks.

Block Quotes

<blockquote cite="source">
  <p>Longer quote text</p>
</blockquote>

Use for longer quotations that should be set apart from the main text.

Example Usage:

As Shakespeare wrote: To be or not to be, that is the question.

The only way to do great work is to love what you do.

— Steve Jobs

Text Formatting Best Practices

Do These:

  • Use semantic elements

    Choose elements based on meaning, not appearance

  • Provide context for abbreviations

    Always include the title attribute for <abbr>

  • Use proper datetime format

    Include machine-readable datetime in <time>

  • Include cite attribute

    Add source URLs to <blockquote> elements

Avoid These:

  • ✗
    Overusing <b> and <i>

    Use <strong> and <em> for meaning instead

  • ✗
    Using formatting for structure

    Don't use <strong> to make headings

  • ✗
    Inconsistent formatting

    Be consistent with your semantic choices

  • ✗
    Mixing physical and semantic

    Choose one approach and stick with it

Your Learning Path

Master HTML text formatting systematically

What You've Learned

  • ▶Semantic text elements (strong, em, mark)
  • ▶Presentation elements (b, i, u)
  • ▶Special formatting (sub, sup, del, ins)
  • ▶Definition and abbreviation elements
  • ▶Code and keyboard text formatting

What's Next

  • ▶HTML Comments - Document your code
  • ▶HTML Links - Connect pages and resources
  • ▶HTML Images - Add visual content
  • ▶HTML Lists - Organize information
  • ▶HTML Tables - Display structured data

Pro Learning Tip

Practice combining different text formatting elements to create rich, meaningful content. Remember: semantic elements provide better accessibility and SEO benefits than purely presentational ones.

HTML Text Formatting — step by step

1 / 4
1

Use semantic text elements

HTML provides semantic elements for text formatting: strong for important text (bold), em for emphasized text (italic), mark for highlighted text, del for deleted text, and ins for inserted text. These carry meaning, not just appearance.

1 of 4
🔍Semantic Formatting Improves Accessibility
Screen readers interpret semantic text elements differently from styled spans. A strong element conveys importance while a bold span does not. Using the correct semantic element — rather than just applying bold or italic CSS — ensures assistive technologies communicate the right meaning to users.

🎯 Quick Check

What is the difference between the strong and b elements?

HTML Text Formatting: summary

Key points

  • Other formatting elements: <mark> (highlight), <small> (side comments), <sub>/<sup>, <del>/<ins>, <code>, <kbd> and <abbr>.
  • Choose elements for meaning; adjust the look with CSS.
  • <u> is for non-textual annotations such as spelling errors. Underlined text is easily mistaken for a link.

Frequently asked questions

›Should I use <b> or <strong>?

Use <strong> when the text is genuinely important or urgent. Use <b> to draw attention without extra importance, such as product names in a review.

›How do I write superscript and subscript?

Use <sup> for superscript (x<sup>2</sup>) and <sub> for subscript (H<sub>2</sub>O).