Skip to main content
HTML Validation

The “main” element must not appear as a descendant of the “section” element.

About This HTML Issue

The <main> element serves a specific structural role: it identifies the primary content of the page, distinct from repeated elements like headers, footers, and navigation. Because of this unique purpose, the HTML specification strictly limits where <main> can appear in the document tree. Nesting <main> inside a <section> element violates these rules because <section> represents a thematic grouping of content — placing <main> inside it implies that the dominant page content is merely a subsection of something else, which is semantically contradictory.

According to the WHATWG HTML living standard, a hierarchically correct <main> element is one whose ancestor elements are limited to <html>, <body>, <div>, <form> (without an accessible name), and autonomous custom elements. This means <main> cannot be a descendant of <article>, <aside>, <footer>, <header>, <nav>, or <section>.

Why this matters

  • Accessibility: Screen readers and assistive technologies use the <main> element as a landmark to let users skip directly to the primary content. When <main> is incorrectly nested inside <section>, assistive technologies may misinterpret the document structure, making navigation harder for users who rely on landmarks.
  • Standards compliance: Browsers are lenient and will render the page regardless, but the semantic meaning is broken. Future browser features or tools that depend on correct document structure may not work as expected.
  • Document structure clarity: The <main> element should clearly sit at the top level of your content hierarchy, making it immediately obvious to both developers and machines which part of the page is the primary content.

Additional rules for <main>

Beyond the ancestor restriction, remember that a document must not have more than one visible <main> element. If you use multiple <main> elements (for example, in a single-page application), all but one must have the hidden attribute specified.

Examples

Incorrect: <main> nested inside <section>

This structure places <main> as a descendant of <section>, which triggers the validation error:

<body>
  <header>
    <h1>My Website</h1>
  </header>
  <section>
    <main>
      <h2>Welcome</h2>
      <p>This is the primary content of the page.</p>
    </main>
  </section>
</body>

Correct: <main> as a sibling of <section>

Move <main> out of the <section> so it is a direct child of <body>:

<body>
  <header>
    <h1>My Website</h1>
  </header>
  <main>
    <h2>Welcome</h2>
    <p>This is the primary content of the page.</p>
  </main>
  <section>
    <h2>Related Topics</h2>
    <p>Additional thematic content goes here.</p>
  </section>
</body>

Correct: <section> elements inside <main>

If your primary content is divided into thematic sections, nest the <section> elements inside <main> — not the other way around:

<body>
  <header>
    <h1>My Website</h1>
  </header>
  <main>
    <section>
      <h2>Introduction</h2>
      <p>An overview of the topic.</p>
    </section>
    <section>
      <h2>Details</h2>
      <p>A deeper dive into the subject.</p>
    </section>
  </main>
  <footer>
    <p>© 2024 My Website</p>
  </footer>
</body>

Correct: <main> wrapped in a <div>

If your layout requires a wrapper element around <main>, a <div> is a valid ancestor:

<body>
  <div class="layout-wrapper">
    <header>
      <h1>My Website</h1>
    </header>
    <main>
      <h2>Welcome</h2>
      <p>This is the primary content of the page.</p>
    </main>
  </div>
</body>

The key principle is simple: <main> defines the dominant content of the entire document, so it belongs at the top level of your content hierarchy. Sectioning elements like <section>, <article>, <aside>, <nav>, <header>, and <footer> should never wrap <main> — instead, they should be placed as children or siblings of it.

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?

Ready to validate your sites?
Start your free trial today.