LEARNING OBJECTIVES โต
- Understand the exact semantic definition of
<section>as a thematic grouping of content. - Differentiate between a semantic
<section>and a generic styling container (<div>). - Master the W3C ARIA rule governing when
<section>is promoted to an accessiblerole="region"landmark. - Structure multi-section document outlines with proper heading hierarchies (
<h2>-<h6>).
๐ The Mental Model & Story (Intuitive Foundation)
Imagine writing a comprehensive doctoral dissertation on Astrophysics.
Your thesis is broken down into distinct, named Thematic Chapters:
- Chapter 1: Introduction & Literature Review
- Chapter 2: Observational Methodology & Radio Telescopes
- Chapter 3: Gravitational Wave Analysis
- Chapter 4: Conclusion & Future Research
+-----------------------------------------------------------------------------------+
| THE DISSERTATION (<main> or <article>) |
| |
| +-----------------------------------------------------------------------------+ |
| | CHAPTER 1 (<section aria-labelledby="sec-1-title"> -> role="region") | |
| | <h2 id="sec-1-title">Chapter 1: Literature Review</h2> | |
| | <p>Analysis of historical pulsar data...</p> | |
| +-----------------------------------------------------------------------------+ |
| |
| +-----------------------------------------------------------------------------+ |
| | CHAPTER 2 (<section aria-labelledby="sec-2-title"> -> role="region") | |
| | <h2 id="sec-2-title">Chapter 2: Observational Methodology</h2> | |
| | <p>Calibration procedures for the Atacama Large Millimeter Array...</p> | |
| +-----------------------------------------------------------------------------+ |
| |
| +-----------------------------------------------------------------------------+ |
| | CHAPTER 3 (<section aria-labelledby="sec-3-title"> -> role="region") | |
| | <h2 id="sec-3-title">Chapter 3: Gravitational Wave Analysis</h2> | |
| | <p>Interferometer telemetry graphs...</p> | |
| +-----------------------------------------------------------------------------+ |
+-----------------------------------------------------------------------------------+
Could Chapter 2 be torn out of your dissertation and published on its own as an independent, standalone magazine article? No. It relies on the context and findings of the other chapters to make sense.
In HTML5, the <section> element represents a Thematic Chapter. It is a logical chunk of a larger document connected by a common theme, headed by an explicit title, but fundamentally part of a greater whole.
Technical Deep Dive & Specifications
WHATWG Specification & ARIA Landmark Rules
- Core Definition: The
<section>element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading. - The ARIA
role="region"Promotion Rule:- An unlabeled
<section>(withoutaria-labeloraria-labelledby) computes to a generic container in the accessibility tree. It does not create a landmark. - A labeled
<section>(witharia-labelledbypointing to its heading or an explicitaria-label) is automatically promoted to an accessiblerole="region"landmark.
- An unlabeled
| Element Markup | Computed ARIA Role | Accessible Landmark Created? | Screen Reader Landmark Shortcut? |
|---|---|---|---|
<section> ... </section> |
Generic container | No | No |
<section aria-labelledby="heading-id"> |
role="region" |
Yes | Yes (e.g., R or landmark rotor) |
<section aria-label="Features"> |
role="region" |
Yes | Yes |
<div class="section"> |
Generic container | No | No |
The Heading Requirement
The WHATWG specification explicitly advises:
"The general rule is that the
<section>element is appropriate only if the element's contents would be listed explicitly in the document's outline. A<section>should almost always include an<h2>โ<h6>heading as a child."
CORRECT:
<section aria-labelledby="pricing-heading">
<h2 id="pricing-heading">Flexible Pricing Plans</h2>
<p>Choose the tier tailored for your team...</p>
</section>
INCORRECT (ANTI-PATTERN):
<section>
<p>Just some text with no heading, used purely for CSS margin styling.</p>
</section>
<section> vs. <div>: The Definitive Rule
- If the container exists purely to apply a CSS background color, a grid layout, or flexbox alignment, use
<div>. - If the container represents a distinct thematic chapter that would appear in a Table of Contents and has an identifying heading, use
<section>.
๐ป Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Line 16 (
<section ... aria-labelledby="features-title">): Establishes a thematic grouping for features. Because it is labeled byfeatures-title, it computes torole="region", allowing screen reader users to jump directly to this region. - Line 17 (
<h2 id="features-title">): The mandatory heading establishing the section theme and providing the accessible name for the region. - Line 18 (
<div class="features-grid">): A non-semantic<div>is properly used as a purely presentational CSS grid container. - Line 19 & 23 (
<article class="feature-card">): Each self-contained feature card is an<article>inside the<section>. - Line 30 (
<section ... aria-labelledby="benchmarks-title">): A distinct thematic chapter containing benchmark data. - Line 49 (
<section ... aria-labelledby="support-title">): Another thematic chapter detailing enterprise guarantees.
Expected Browser Render Output
HyperBase Cloud Database
Distributed ACID transactions across multi-region edge nodes.
---------------------------------------------------------------------------------
CORE ENGINE FEATURES
[Sub-Millisecond Read Latency] [Automatic Sharding]
Local in-memory cache... Dynamic partition rebalancing...
INDEPENDENT PERFORMANCE BENCHMARKS
Tested on 64-node clusters under 100,000 concurrent writes per second.
Engine | Throughput (ops/sec) | p99 Latency (ms)
HyperBase | 142,000 | 1.8ms
Standard SQL | 48,000 | 14.2ms
ENTERPRISE SLA & SUPPORT
24/7 dedicated site reliability engineering response with a 99.999% uptime guarantee.๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Deconstruct a Monolithic Product Landing Page
Instructions:
- Organize a SaaS landing page into three distinct
<section>elements:- Section 1: "Product Capabilities" labeled via
aria-labelledby. - Section 2: "Pricing Tiers" labeled via
aria-labelledby. - Section 3: "Frequently Asked Questions (FAQ)" labeled via
aria-labelledby.
- Section 1: "Product Capabilities" labeled via
- Provide each section with an
<h2>heading and anidthat matches the section'saria-labelledby. - Use
<div>containers strictly for layout styling wrappers inside the sections.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Using
<section>for Visual Styling Only: Replacing every<div>with a<section>simply to apply CSS background colors or borders creates a bloated, meaningless document outline. - Creating Headless Sections: Writing
<section>without an identifying<h2>-<h6>heading violates the core specification guideline that sections must represent outlined topics. - Forgetting
aria-labelledbyfor Landmark Regions: An unlabeled<section>does not produce a landmark in the accessibility tree. If you want assistive tech users to jump between sections, you must label them.
๐ก Pro Tips
- Maintain Consistent Heading Levels: Avoid resetting heading levels to
<h1>inside every<section>. Although HTML5 originally proposed an automatic outline algorithm for nested<h1>tags, browsers never implemented it. Always follow a flat, explicit heading hierarchy (<h1>-><h2>-><h3>). - Combine
<section>with In-Page Navigation: If your page has a Table of Contents (<nav>), make sure each anchor link#section-idtargets a<section id="section-id">for intuitive keyboard and scroll interactions.
๐ Key Takeaways
- The
<section>element represents a thematic grouping of content, typically with a heading. <section>is promoted to an accessiblerole="region"landmark only when labeled witharia-labelledbyoraria-label.- Every
<section>should almost always contain an explicit heading tag (<h2>-<h6>). - Do not use
<section>as a generic styling wrapper; use<div>for pure layout or presentation needs. - Maintain an explicit heading hierarchy rather than relying on hypothetical outline algorithms.
- --