Module lessons (2/4)
Text, Headings & Document Hierarchy
Headings Are a Table of Contents, Not Font Sizes
Beginners frequently pick <h4> because <h2> looked "too big" on screen. That breaks accessibility: screen reader users press shortcut keys (H or 1–6) to skim a page's outline, trusting that an <h3> sits logically underneath an <h2>.
Use one <h1> for the main page topic, use <h2> for top-level sections, and nest <h3> inside those sections. If a heading looks too large, shrink it later with CSS—never pick a wrong level!
| Element | Semantic Meaning | When to Avoid |
|---|---|---|
<h1> | Primary page title (one per page) | Repeating for every hero banner card |
<h2>–<h6> | Nested sub-sections in sequential order | Jumping directly from <h1> to <h3> |
<p> | Standalone prose paragraph | Spacing empty lines with <p></p> |
<strong> | Urgent or high-importance phrase | Mere visual bold weight for logos |
<em> | Spoken stress that shifts meaning | Decorative italics on metadata tags |
<code> | Computer code, tag name, or CLI command | Long multi-line blocks without <pre> |
<blockquote> | Multi-sentence external quotation | Indenting ordinary text visually |
Example 1 — Clean Logical Outline
Notice how every level steps down cleanly by one:
<main>
<h1>Complete Coffee Roasting Guide</h1>
<p>From green beans to balanced morning espresso.</p>
<h2>1. Choosing Green Beans</h2>
<h3>Altitude and Density</h3>
<p>High-grown Arabica beans carry brighter acidity.</p>
<h2>2. Controlling Heat</h2>
<p>Wait until the <strong>first crack</strong> before cooling.</p>
</main>Example 2 — Code Snippets & Quotes
Wrap multi-line code inside <pre><code>...</code></pre> to preserve indentation, and pair <blockquote> with <footer> or <cite> for attribution:
<p>Inspect CSS specificity in prose with <code>:where()</code>.</p>
<blockquote>
<p>Good design is as little design as possible.</p>
<footer>— <cite>Dieter Rams</cite></footer>
</blockquote>Step 1 — Fix a skipped heading hierarchy
Fix the skipped heading levels inside <main> so the page starts with one <h1>, followed by an <h2> section and a nested <h3> subsection.
Show hint
Change <h4> to <h2> and <h5> to <h3> so levels go 1 -> 2 -> 3 without skipping.
Solution available after 3 attempts
Step 2 — Add semantic emphasis and inline code
Inside the <p>, wrap 'git status' in <code>, mark 'never force push' with <strong>, and emphasize 'shared' using <em>.
Show hint
Wrap the command in <code>git status</code>, urgent rule in <strong>never force push</strong>, and word "shared" in <em>shared</em>.
Solution available after 3 attempts
Step 3 — Quote with attribution cleanly
Convert the raw quote div into a semantic <blockquote> holding the quote inside a <p> and citing 'Tim Berners-Lee' inside <cite>.
Show hint
Replace <div class="quote"> with <blockquote>, wrap the sentence in <p>, and wrap Tim Berners-Lee in <cite>.
Solution available after 3 attempts
Your designer wants a subtitle below <h1> to look small (14px). What is the cleanest semantic choice?
How does <strong> differ from CSS font-weight: bold?