Codectionary / Developer documentation / HTML

<main>

The <main> element represents the dominant, unique content of the document — the content that is directly related to the page's central topic, excluding repeated elements like headers, navigation, sidebars, and footers. There must be no more than one visible <main> element per page, and it should not be nested inside <article>, <header>, <footer>, <nav>, or <aside>.

Syntax

<main>
  <!-- primary page content -->
</main>

Examples

Basic Page Structure

Using main to wrap the primary content of a page.

<header>...</header>
<nav>...</nav>
<main>
  <h1>Product Details</h1>
  <p>This is the main content unique to this page.</p>
</main>
<footer>...</footer>

Main with Multiple Sections

A main element containing several content sections.

<main>
  <section>
    <h2>About Us</h2>
    <p>...</p>
  </section>
  <section>
    <h2>Our Services</h2>
    <p>...</p>
  </section>
</main>

Skip Link Target

Using main as the target for a "skip to content" accessibility link.

<a href="#main-content">Skip to main content</a>
<nav>...</nav>
<main id="main-content">
  <h1>Page Title</h1>
</main>

Best practices

  • Use exactly one <main> element per page, and never nest it inside <header>, <footer>, <nav>, <article>, or <aside>
  • Give <main> an id so it can be used as a target for "skip to content" accessibility links
  • Only include content in <main> that is unique to the current page — repeated site-wide elements belong outside it
  • Screen reader users can jump straight to <main>, so make sure it truly contains the page's primary content

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation