Course contentsShow
← Web Development
Lesson 49 of 2,9822. HTML FundamentalsFree lesson

The <main> Element

Identifying the primary content of a document with <main> and understanding its uniqueness constraint.

The <main> Element

What you'll learn: How to mark the primary content of your web page using the <main> element, and why there can only be one per page.

What Is <main>?

The <main> element wraps around the main content of your document — the stuff that's directly related to what your page is actually about. Think of it as the star of the show: while <header> and <nav> provide context and navigation, <main> contains the reason someone came to your page in the first place.

The Uniqueness Constraint

Here's the crucial rule: you can only have ONE visible <main> element per page. Why? Because there should only be one primary focus on any given document.

If <header> is like the title page of a book and <nav> is the table of contents, then <main> is the actual chapter you're reading — and you can only read one chapter at a time.

When to Use <main>

Use <main> to wrap:

  • Article content on a blog post
  • Product details on an e-commerce page
  • Search results on a search page
  • The actual game area on a game site

Don't include repeated elements like site headers, navigation bars, footers, or sidebars inside <main> — those are supporting actors, not the main content.

Simple Example

<header>
  <h1>My Cooking Blog</h1>
</header>

<nav>
  <a href="/recipes">Recipes</a>
  <a href="/about">About</a>
</nav>

<main>
  <h2>Perfect Chocolate Chip Cookies</h2>
  <p>This recipe will change your life...</p>
</main>

Notice how the recipe content goes in <main>, while the site title and navigation stay outside.

Key Takeaway: The <main> element identifies your page's primary content and can only appear once per page, helping both browsers and assistive technologies understand what matters most.