Semantic vs visual formatting

HTML gives you two ways to format text: semantic and visual. Semantic tags carry meaning (importance, emphasis), while visual tags are purely for appearance.

Why does this matter? Screen readers (used by blind users) read semantic tags differently than visual ones. Search engines also pay attention to semantic tags when ranking content. As a web developer, you should prefer semantic tags whenever possible.

Golden rule:
Use semantic tags by default. Only use visual tags when semantic doesn't apply. This makes your HTML more accessible and SEO-friendly.

Bold and italic: <b> vs <strong>, <i> vs <em>

These tags look similar but behave differently:

formatting.html Bold and italic tags
  • <strong> โ€” Semantic: marks text as having strong importance. Screen readers emphasize it. Good for warnings or critical info.
  • <b> โ€” Visual only: renders as bold but carries no semantic weight. Use for keywords, product names, or highlights.
  • <em> โ€” Semantic: marks text as emphasized. Screen readers pronounce it differently (stressed). Good for emotional emphasis.
  • <i> โ€” Visual only: renders italic but no emphasis. Use for titles (The Great Gatsby), foreign words (c'est la vie), or citations.

Mark, delete, insert, subscript & superscript

HTML has several other useful formatting tags for highlighting, showing edits, and writing chemistry or math:

advanced-formatting.html Mark, del, ins, sub, sup
  • <mark> โ€” Highlights text with a yellow background. Like using a marker pen.
  • <del> โ€” Shows deleted text with a strikethrough. Good for showing what was removed.
  • <ins> โ€” Shows inserted text (often underlined). Use with <del> to show edits.
  • <sub> โ€” Subscript: text that goes below the baseline. Used in formulas (H2O).
  • <sup> โ€” Superscript: text that goes above the baseline. Used in math (x2) and degrees (25°C).

Try it yourself โ€” Format a technical article

Edit the code below to practice bold, italic, mark, del, ins, sub, and sup. Click Run to see your changes rendered.

โœ๏ธ Try It Yourself โ€” Edit & Run
Preview

Quotations: <blockquote>, <q>, and <cite>

When you quote someone else's words, use semantic quotation tags. This helps search engines and readers understand that the text isn't your own.

quotes.html Block quotes, inline quotes, and citations
  • <blockquote> โ€” A large quote that stands alone. Typically indented by browsers. Include a <cite> tag with the author's name.
  • <q> โ€” An inline, short quote. Browsers usually add quotation marks automatically (though you can style this with CSS).
  • <cite> โ€” Marks the source/author. Use inside a <blockquote> or separately to cite a work.

Technical text: <code>, <kbd>, <samp>, and <abbr>

When writing about code, keyboard input, or abbreviations, these tags help convey meaning:

technical.html Code, keyboard, sample output, and abbreviations
  • <code> โ€” Inline code snippets. Styled as monospace with a background.
  • <kbd> โ€” Keyboard input. Shows what the user should type or press. Often styled to look like a keyboard key.
  • <samp> โ€” Sample output from a program. Visually distinct from code the user types.
  • <abbr title="..."> โ€” Abbreviations. The title attribute shows the full text on hover. Great for acronyms like SEO or API.

Try it yourself โ€” Create a quotations showcase

Practice block quotes, inline quotes, citations, and abbreviations. Click Run to see how these elements render.

โœ๏ธ Try It Yourself โ€” Quotes & Citations
Preview

Common mistakes

  • Using <b> instead of <strong> โ€” <b> is fine for visual styling, but <strong> is better for important information. Prefer semantic tags.
  • Using <i> instead of <em> โ€” <em> tells screen readers to stress the text. Use <i> only for titles, foreign words, or visual styling.
  • Forgetting the title attribute on <abbr> โ€” An abbreviation without a title is useless. Always include: <abbr title="Full Text">ABR</abbr>.
  • Not citing block quotes โ€” A <blockquote> without a source looks incomplete. Always add <cite> to show who said it.
  • Using quotation marks manually โ€” Use <q> instead of typing "like this". The browser will add proper quotes and they'll be translatable to different languages.
Challenge: Format a Science Article about Water

Task: Create an HTML article about water with proper formatting. Include:

  • An <h1> title: "Water: The Universal Solvent"
  • A paragraph mentioning H2O using subscript (H<sub>2</sub>O)
  • A paragraph with <mark> around key terms like "polar molecule" or "hydrogen bonds"
  • Temperatures shown with superscript degrees (25°C using <sup>)
  • A <blockquote> from a famous scientist with <cite>
  • An abbreviation using <abbr title="..."> for a scientific term like "H2O" or "pH"
  • An inline quote using <q> from a real or fictional scientist
  • Code examples using <code> if relevant (e.g., chemical formulas)

Hint: Start with your HTML skeleton. Write a paragraph about water's properties. Use subscript for Hโ‚‚O. Mark key terms. Add a famous quote from a scientist (Marie Curie, Einstein, etc.) in a blockquote. Use superscript for temperatures (100°C for boiling point). Add an abbr tag for "H2O" or "dihydrogen oxide".

Key takeaways

  • Use semantic tags by default: <strong> for importance, <em> for emphasis. They're better for accessibility and SEO.
  • <b> and <i> are visual-only. Use them for product names, titles, or foreign words when semantic meaning doesn't apply.
  • <mark> highlights text. <del> shows deletions. <ins> shows insertions. <sub> and <sup> are for chemistry and math.
  • Always cite quotations with <blockquote> + <cite> for large quotes, or <q> for inline quotes.
  • <abbr title="..."> makes acronyms accessible. Always include a title with the full text.
  • <code>, <kbd>, and <samp> are for technical writing โ€” they help readers understand what's code vs user input vs output.

Test your knowledge

Question 1 of 5
What's the main difference between <b> and <strong>?
Question 2 of 5
Which tag highlights text with a yellow background?
Question 3 of 5
Which tag is used for short, inline quotations?
Question 4 of 5
What does the <abbr> tag do?
Question 5 of 5
Which tag represents deleted text?
0
/5
Great work! You understand text formatting.
Africa & India's Best AI Academy
๐Ÿค– AI-first ๐ŸŽ“ Placement Assistance

You just mastered text formatting.
Next: Links and navigation.

Join the Best AI Programs โ€” three 5-month courses, fully online, with placement assistance. Week 1 is free.

Explore our AI-era courses โ†’