HTML Main Tag: Syntax, Uses, and Examples
What is HTML Main Tag: Syntax, Uses, and Examples? The HTML tag designates the dominant, central content unique to an individual document. It directly excludes content repeated across multiple pages such as sit...
What is the role of the HTML <main> tag and what rules govern its usage?
Explanation & In-Depth Details
2) The Strict Singularity Rule: A document must not have more than one <main> element without the 'hidden' attribute. Having multiple visible <main> tags violates W3C validation.
3) What Must NOT Be Inside <main>: Never place global headers, primary navigation menus, global footers, legal copyrights, or site-wide advertising banners inside <main>.
4) Web Accessibility Landmark: Assistive technologies identify <main> as the primary 'main' landmark. Screen reader users often configure their software to skip directly to <main>, bypassing dozens of repetitive navigation links.
5) Skip to Main Content Link: For superior keyboard accessibility, developers add a visually hidden 'Skip to main content' anchor link at the very top of the <body> (<a href="#mainContent" class="skip-link">Skip to Content</a>) that focuses <main> when pressing Tab.
Code Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Main Element Architecture</title>
<style>
.skip-link { position: absolute; top: -40px; left: 0; background: #2563eb; color: #fff; padding: 8px; z-index: 100; text-decoration: none; }
.skip-link:focus { top: 0; }
</style>
</head>
<body>
<!-- Accessible Skip Link for Keyboard Users -->
<a href="#main-content" class="skip-link">Skip to Main Content</a>
<!-- Header & Navigation (NOT in main) -->
<header>
<nav aria-label="Main Site Navigation">
<a href="/">Home</a> | <a href="/about">About</a> | <a href="/blog">Blog</a>
</nav>
</header>
<!-- Unique, Primary Page Content: Strictly ONE per page -->
<main id="main-content">
<h1>Exploring Deep Learning with Python</h1>
<p>This article explores convolutional neural networks and tensor operations...</p>
</main>
<!-- Footer (NOT in main) -->
<footer>
<p>© 2026 TechInsights. All rights reserved.</p>
</footer>
</body>
</html>Interview Question & Tips
A1: No. A <main> element cannot be a descendant of an <article>, <aside>, <footer>, <header>, or <nav> element. It must be a direct or near-direct child of <body>.
Q2: Why is the 'Skip to main content' link considered a WCAG 2.1 Level A requirement?
A2: Keyboard and screen reader users would otherwise have to press the Tab key 20-50 times on every single page load just to bypass the navigation menu to reach the article content.
Q3: Does the <main> tag replace the need for ARIA role="main"?
A3: In all modern browsers, <main> carries an implicit ARIA role of 'main'. Adding role="main" is only needed for legacy support with very old assistive devices.
Best Practices
This study reference for HTML Main Tag: Syntax, Uses, and Examples is curated and verified against recognized curriculum benchmarks, peer-reviewed textbooks, and official technical documentation: