LEARNING OBJECTIVES โต
- Master the semantic definition and ARIA landmark behavior of the
<main>element (role="main"). - Enforce the "Single Visible Main" rule across multi-view single-page applications and static sites.
- Understand prohibited ancestor hierarchies that invalidate the
<main>element. - Implement a fully functional, keyboard-accessible "Skip to Main Content" bypass mechanism meeting WCAG 2.4.1 (Level A).
๐ The Mental Model & Story (Intuitive Foundation)
Imagine attending a Broadway musical.
Before you reach your seat, you navigate the theater's outer infrastructure: you walk through the decorative Foyer (<header>), read the Directional Signage to find your balcony aisle (<nav>), glance at the Merchandise Booth in the side corridor (<aside>), and check the Box Office Policies on the back of your ticket (<footer>).
All of these areas support your journey, but none of them are the reason you bought the ticket.
The moment the lights dim and the velvet curtains part, the spotlight focuses entirely on the Center Stage. The central performance unfolds right there.
+-----------------------------------------------------------------------------------+
| THE BROWSER VIEWPORT |
| |
| +-----------------------------------------------------------------------------+ |
| | GLOBAL BANNER / HEADER (Outer Foyer) | |
| | [Logo] [Search] [Navigation Links] [User Profile] | |
| +-----------------------------------------------------------------------------+ |
| |
| +-----------------------------------------------------------------------------+ |
| | CENTER STAGE (<main>) | |
| | | |
| | The primary, unique content of this specific document URL. | |
| | (Does NOT repeat across pages. Central focus of the user's intent.) | |
| | | |
| | <h1>Quantum Cryptography Protocols</h1> | |
| | <article>...</article> | |
| +-----------------------------------------------------------------------------+ |
| |
| +-----------------------------------------------------------------------------+ |
| | GLOBAL CONTENTINFO / FOOTER (Legal Colophon & Exit Doors) | |
| +-----------------------------------------------------------------------------+ |
+-----------------------------------------------------------------------------------+
In HTML5, the <main> element is the Center Stage. It isolates the core, unique content of the page from repeated peripheral chrome like global headers, footers, search bars, and side navigation rails.
Technical Deep Dive & Specifications
WHATWG Specification & ARIA Mapping
- Implicit ARIA Role:
role="main". - Accessibility Landmark: Yes. Screen readers provide dedicated shortcuts to jump immediately to the main content (e.g.,
Mkey in JAWS/NVDA, rotor landmark menu in VoiceOver). - Core Definition:
<main>represents the dominant contents of the<body>of a document. Content that is repeated across a set of documents (such as site navigation links, copyright notices, site logos, and search bars) must not be included directly within<main>, unless that search bar is the main purpose of the page (e.g., Google homepage).
The Single Visible Main Rule
The HTML5 specification allows multiple <main> elements in the DOM only if at most one is visible at any given time. All others must carry the boolean hidden attribute:
<!-- VALID: Single Page Application Tab System -->
<main id="view-dashboard">...</main>
<main id="view-settings" hidden>...</main>
<main id="view-billing" hidden>...</main>
<!-- INVALID SPEC VIOLATION: Multiple Visible Main Elements -->
<main>...</main>
<main>...</main> <!-- ERROR: Violates single visible main landmark rule -->
Prohibited Ancestor Constraints
The <main> element must never be a descendant of:
<header><footer><nav><aside><article>
VALID HIERARCHY:
<body>
<header>...</header>
<nav>...</nav>
<main id="main-content"> <--- Direct child of <body> or valid non-sectioning wrapper
<article>...</article>
</main>
<footer>...</footer>
</body>
INVALID SPEC VIOLATION:
<article>
<main>...</main> <--- ERROR: <main> nested inside <article>
</article>
WCAG 2.4.1 Bypass Blocks (Level A) & The Skip Link Pattern
Power keyboard users and screen reader users must tab through dozens of navigation links on every page load unless a bypass mechanism is provided.
The industry-standard, accessible Skip Link pattern:
- An anchor tag placed at the very top of
<body>:<a href="#main-content" class="skip-link">Skip to main content</a>. - Visually hidden by default using off-screen CSS, but immediately visible when focused via
Tab. - Points to
<main id="main-content" tabindex="-1">. tabindex="-1"ensures that when the browser jumps to the anchor, programmatic focus shifts to<main>, allowing subsequentTabkeystrokes to start from inside the main content rather than bouncing back to the top of the page.
๐ป Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Line 33 (
<a href="#main-content" class="skip-link">): Placed as the first focusable element inside<body>. A keyboard user pressingTabimmediately upon page load focuses this link. - Line 7โ25 (
<style>... .skip-link:focus ...): Offsets the link off-screen (top: -100px) until it receives:focus, at which point it slides down into full view (top: 0). - Line 47 (
<main id="main-content" tabindex="-1">): The central landmark.id="main-content"provides the target for the skip link.tabindex="-1"allows the container to receive programmatic focus upon anchor click without adding it to the natural keyboard tab sequence. - Line 28 (
main:focus { outline: none; }): Suppresses unnecessary visual focus rings on the container itself when focused programmatically, while child interactive elements retain their focus indicators.
Expected Browser Render Output
[When Page Loads]:
NovaCloud | [Products] [Solutions] [Pricing] [Enterprise] [Contact]
-------------------------------------------------------------------
Serverless Kubernetes Clusters
Deploy autoscale container pods in seconds without cluster overhead.
Architecture Highlights
โข Instant cold-start provisioning in under 200ms
โข Micro-VM hardware isolation per pod
โข Integrated service mesh telemetry
-------------------------------------------------------------------
ยฉ 2026 NovaCloud Infrastructure Inc.
[When User Presses 'Tab' Key]:
+---------------------------+
| [Skip to main content] | <-- Blue focus banner drops down at top left
+---------------------------+๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Implement a Resilient Skip-Link System
Instructions:
- Construct an HTML5 page with a global
<header>containing a 5-item<nav>menu. - Place a keyboard-accessible "Skip to content" anchor tag before the
<header>. - Add the
<main>element withid="main-content"andtabindex="-1". - Include an
<article>inside<main>with an<h1>heading and body paragraphs. - Add a
<footer>at the end of the document. - Verify that
<main>is not placed inside<header>,<nav>, or<article>.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Nesting
<main>inside<article>or<header>: Placing<main>inside sectioning content violates the HTML5 specification and breaks the accessibility tree hierarchy. - Multiple Visible
<main>Elements on One Page: Having more than one un-hidden<main>tag in a document creates conflicting primary landmarks for screen reader users. - Forgetting
tabindex="-1"on the Main Landmark: In some browser and screen-reader combinations (like WebKit/Safari), clicking a hash link scrolls the page visually but fails to shift focus unless the target container hastabindex="-1".
๐ก Pro Tips
- Single-Page App View Transitions: When building client-side SPAs (React, Vue, Svelte), ensure that upon route change, focus is programmatically shifted to
<main>viadocument.querySelector('main').focus()so screen readers announce the new page content. - Exclude Global Search from
<main>(Except on Search-Centric Pages): Global search belongs in the<header role="banner">. Only include search in<main>if search is the primary and sole function of the page (such as a search engine landing page).
๐ Key Takeaways
<main>represents the dominant, non-repeating content of the document (role="main").- Only one visible
<main>element is permitted per document at any given time. <main>cannot be nested inside<header>,<footer>,<nav>,<aside>, or<article>.- WCAG 2.4.1 mandates bypass mechanisms; pairing a top-of-body skip link with
<main id="..." tabindex="-1">is the gold standard implementation. - Repeated UI elements like global logos, site menus, and copyright bars must remain outside
<main>. - --