liveBook · Manning

Main

As explained in Web Design Playground, Second Edition

Main content is the primary subject matter of a web page, excluding shared navigation and peripheral regions.

The <main> element marks the part of a web page that is unique to the current page: its primary, one-of-a-kind content. Think of it as the page’s main event, while the header, navigation, sidebar, and footer handle the familiar supporting cast. section 11.6 section 11.11

Use one <main> element per page. It commonly comes after <header> and <nav>, then holds the content visitors came to see. Semantic elements give that structure a name that screen readers and other software can interpret more easily than a pile of anonymous <div> tags. section 11.6 section 11.3

PLAY: Mark the unique content

Put shared branding and links outside <main>, then place the page-specific material inside it. Here, the header and navigation can recur across a site, but the content inside <main> belongs to this page alone. section 11.6

<header>
    <img src="/images/SD-logo.png" alt="Semantics Depot logo">
    <h1>Semantics Depot</h1>
</header>
<nav>
    <a href="#">Home</a>
    <a href="#">Blog</a>
    <a href="#">Contact</a>
    <a href="#">About Us</a>
</nav>
<main>                           #1
    Unique content goes here
</main>                          #1

This small layout shows <main> after the shared header and navigation, with a clear placeholder for unique content. section 11.6

What goes inside depends on the page. A photo gallery can use <main> for linked thumbnail images. A portfolio page can use it for several <section> elements, each containing a distinct part of the portfolio. One container, many possibilities—no cape required. section 15.6 section 20.5

REMEMBER: <main> is for content that is:

How Web Design Playground, Second Edition covers it

How deep it goes
Defines placement and single-use rules, then applies main to gallery and portfolio layouts without detailing browser internals.
Examples
Uses a header-and-navigation layout, a thumbnail photo gallery, and a portfolio containing several sections.
What you can do after
Build it from scratch by wrapping page-specific content in one semantic main element.
How it connects
Connects semantic page layout with header, nav, article, section, aside, footer, accessibility, Flexbox, and CSS Grid.

Also explained in

Compare how 3 books explain main →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.