Lesson

HTML Formatting

10 min reading
Free Course

HTML Formatting: Semantic and Visual Text Tags

HTML formatting elements let you change how individual words or phrases look inside a paragraph, and they also tell browsers and assistive technology what that text means. A warning, a stressed word, a deleted price, and a chemical formula each have their own tag. Picking the right one makes a page clearer for every reader, including people who use screen readers.

This guide explains the difference between semantic and purely visual tags, walks through a complete example, and covers the mistakes that most often lead to messy or confusing markup.

What Is HTML Formatting?

It means using inline elements to mark up parts of a sentence. "Inline" means the element sits inside a line of text and doesn't start a new block, unlike a <p> or <h2>.

Some of these tags exist mainly for meaning (<strong>, <em>, <del>, <ins>), while others are closer to visual styling (<b>, <i>, <small>). In modern HTML, however, even the older visual tags have a defined purpose. They are not just "make it bold" switches. If you only need a particular look with no extra meaning, CSS is the better tool.

Semantic Emphasis vs. Visual Offset

Modern HTML separates semantic tags from purely presentational tags. Although strong and b both display bold text visually, strong marks critical or urgent warnings, whereas b highlights keywords like product names without extra vocal stress.

Similarly, em adds spoken stress emphasis that changes how a sentence reads aloud, while i marks technical terms, foreign phrases, or ship names in italic text.

Practical Formatting Tags Example

HTML includes several specialized inline formatting elements for notes, revisions, math, and chemistry:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HTML Text Formatting</title>
</head>
<body>
    <p><strong>Warning:</strong> Always back up your database before running migrations.</p>
    <p>You <em>must</em> restart the server for environment changes to apply.</p>
    <p>Search match: <mark>HTML formatting</mark> improves document clarity.</p>
    <p>Sale price: <del>$49</del> <ins>$29</ins></p>
    <p>Water formula is H<sub>2</sub>O and squares write as x<sup>2</sup>.</p>
    <p><small>Offer ends Friday at midnight UTC.</small></p>
</body>
</html>

Use del for deleted text, ins for newly inserted text, sub for chemical subscripts, sup for exponents or footnotes, and small for legal side comments.

A few details are easy to miss:

  • <mark> is about relevance, not decoration. Use it for something like a search term in results. Don't use it as a general highlighter pen.

  • <del> and <ins> accept two optional attributes: cite (a URL explaining the change) and datetime (when it happened). For example, <del datetime="2026-11-01">$49</del>.

  • <small> is for side comments, not for shrinking whole sections. Long legal text belongs in its own paragraph or element, possibly styled with CSS.

  • <sub> and <sup> are for meaning, such as formulas and footnotes. They are not a shortcut for nudging text up or down for layout.

How to Check That Your Formatting Works

  1. Open the page in a browser and confirm the default styles appear: bold, italic, strikethrough, raised and lowered text.

  2. Open DevTools and inspect an element such as <strong>. Check that it sits in the right place in the DOM and that no unexpected CSS overrides it.

  3. In the Accessibility pane of your browser's DevTools, look at how the elements are exposed. This is a quick way to confirm you used real semantic tags and not styled <span> elements.

  4. If you can, try a screen reader (such as NVDA, VoiceOver, or Narrator) on a short test page. Behavior varies between screen readers and settings, so treat it as a rough check.

  5. Run the page through an HTML validator to catch unclosed or misplaced tags.

Common Mistakes to Avoid

  • Using b and i everywhere: Default to strong when text is genuinely important and em when stressing a word changes meaning.

  • Using u for regular emphasis: Underlined text confuses visitors because web browsers associate underlines with clickable links.

  • Replacing headings with strong tags: Keep section titles in h2 or h3 tags rather than bolding a standalone paragraph.

Frequently Asked Questions

What is the difference between strong and b in HTML?

Both render bold text by default, but strong signals serious importance to screen readers while b only draws visual attention to words.

How do I write superscripts and subscripts in HTML?

Wrap exponents or ordinal suffixes in sup tags and chemical or mathematical subscripts in sub tags.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
HTML Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum