Sub topic 12
Semantic layout elements
This chapter assumes you can write a complete HTML document with a doctype, html, head and body. It also assumes you know how elements, attributes, headings, paragraphs and links work, and that you understand block-level and inline content. Here you will learn to divide a page into meaningful regions with layout elements that describe their purpose.
What "semantic" means
A semantic element tells browsers, search engines and assistive technology what its content is, not only how it looks. A div says nothing about its content. A nav says "this is a group of navigation links".
Semantic layout elements have no built-in visual style beyond being block-level. You can build the same appearance with div elements and CSS. The benefit is meaning:
- Screen reader users can jump between regions, such as the main content or the navigation.
- Search engines and other tools can find the primary content of a page.
- Other developers can read the structure of the markup quickly.
The core layout elements
| Element | Purpose |
|---|---|
| `header` | Introductory content for the page or for a section: a title, a logo, a nav. |
| `nav` | A block of major navigation links. |
| `main` | The central content unique to this page. |
| `section` | A thematic grouping of content, normally with its own heading. |
| `article` | A self-contained item that makes sense on its own, such as a post or a news story. |
| `aside` | Content related to the surrounding content but separable from it, such as a sidebar or a tip. |
| `footer` | Closing content for the page or a section: authorship, copyright, related links. |
A complete page
The following page uses every element in the table except section.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Garden Notes</title>
</head>
<body>
<header>
<h1>Garden Notes</h1>
<nav aria-label="Primary">
<a href="/">Home</a>
<a href="/articles">Articles</a>
</nav>
</header>
<main>
<article>
<h2>Growing tomatoes</h2>
<p>Tomatoes need sun and regular watering.</p>
</article>
<aside>
<h2>Quick tip</h2>
<p>Water in the morning.</p>
</aside>
</main>
<footer>
<p>© 2026 Garden Notes</p>
</footer>
</body>
</html>The next diagram shows how those regions nest inside body.
Landmarks and accessibility
Browsers expose several layout elements to assistive technology as landmarks. A landmark is a named region that a screen reader can list and jump to.
| Element | Landmark role | Condition |
|---|---|---|
| `header` | banner | Only when it is not inside `article`, `section`, `main`, `aside` or `nav`. |
| `nav` | navigation | Always. |
| `main` | main | Always. |
| `aside` | complementary | Always. |
| `footer` | contentinfo | Only when it is not inside `article`, `section`, `main`, `aside` or `nav`. |
| `section` | region | Only when it has an accessible name. |
The conditions matter. A header inside an article is only the introduction to that article. It is not the page banner, so it does not become a landmark.
Rules for each element
main
Use one visible main per page. It should hold the content that is unique to this page, so repeated site-wide blocks such as the primary navigation and footer belong outside it. Do not nest main inside article, aside, header, footer or nav.
header and footer
You can use these more than once. A page can have a top-level header, and each article can have its own header with a title and publication date. The same applies to footer, for example an author line at the end of an article.
<article>
<header>
<h2>Pruning roses</h2>
<p>Published on <time datetime="2026-03-14">14 March 2026</time></p>
</header>
<p>Prune in late winter, just as new buds begin to swell.</p>
<footer>
<p>Written by Sam Okafor</p>
</footer>
</article>nav
Use nav for major blocks of navigation, such as the main menu, a table of contents or pagination. You do not need it for every group of links. A short list of links in a footer can stay a plain list.
If a page has more than one nav, give each an accessible name with aria-label, as in aria-label="Primary". Screen readers then announce which navigation is which.
section versus article versus div
Choosing between these three causes most layout mistakes. Ask these questions in order:
- Would the content make sense if it were copied alone into a feed reader or another site? If yes, use
article. - Is it a thematic group that would normally have a heading? If yes, use
section. - Do you need a wrapper only for styling or scripting? Use
div.
<main>
<h1>Sourdough guide</h1>
<section>
<h2>Ingredients</h2>
<p>Flour, water, salt and a live starter.</p>
</section>
<section>
<h2>Method</h2>
<p>Mix, rest, fold, shape and bake.</p>
</section>
<div class="print-spacer"></div>
</main>Here the two topics are section elements, and the spacer has no meaning, so it stays a div.
aside
aside holds content that is tangentially related to its surroundings: a pull quote, a glossary note, a related-links list. Inside an article, it relates to that article. As a direct child of main or body, it relates to the whole page. Do not use it just because something sits on the side. Position is a CSS concern.
Headings inside layout elements
Semantic elements do not replace heading structure. Each region should still have a sensible heading, and levels should not skip. In the Garden Notes page, h1 names the site, and each region inside main starts at h2.
HTML allows several h1 elements, but browsers do not yet compute an outline from nested sections. Choose heading levels yourself, based on how the content is organized. A single h1 that names the page's topic is the safest convention.
Common errors
- Multiple visible
mainelements. A page has one primary content area. If you must have more than one in the markup, such as in a single-page app, all but one must carry thehiddenattribute. sectionas a generic wrapper. Asectionwithout a heading is usually adivin disguise. Replace it.- Wrapping the whole page in
article. Anarticleis a single self-contained item. A page with a list of posts has onearticleper post. - Putting the site navigation inside
main. Repeated blocks belong outsidemain, so users can skip straight to it. - Using
asidefor layout. If the element is not tangential content, it should not be anaside, whatever the column it ends up in. - Putting a block-level layout element inside a
p. The browser closes the paragraph early when it meets aheader,sectionordiv, which produces a different structure from the one you wrote.
<!-- Invalid: the browser ends the p before the section starts -->
<p>Intro text <section><h2>Topic</h2></section></p>- Nesting an
ainside anothera, or anavinside anavfor no reason. Keep each landmark distinct.
Edge cases and trade-offs
Semantic elements are not strictly necessary on small pages, but they cost nothing and help users. There are limits:
- Do not add roles that duplicate the element, such as
role="navigation"onnav. The role is already implied. - Older browsers that lack HTML5 support treat unknown elements as inline. Every browser in current use handles them correctly, so you rarely need to worry. If you do style them, set
display: blockexplicitly. - A
sectionwitharia-labeloraria-labelledbybecomes a landmark. Add a name only to sections that deserve to appear in a landmark list, since too many landmarks add noise.
Checklist
- Exactly one visible
main, holding page-specific content. - Page-level
headerandfootersit outsidemainand outsidearticleorsection. - Every
navis a major navigation block, and extra ones have anaria-label. - Each
articleis self-contained, and eachsectionhas a heading. divis used only where no other element fits.- Heading levels descend in order without skipped levels.
Exercise
A page has a site-wide menu at the top, a list of three blog posts, a "Popular tags" box beside them, and a copyright line at the bottom. Which elements would you use for each part, and where would you put main?
Show answer
Put the menu links in a nav inside a page-level header, outside main. Wrap the three posts and the tags box in one main. Mark each post as its own article, since each makes sense alone. Use an aside with a heading for "Popular tags". Place the copyright line in a page-level footer after main.
Exercise
This markup has two problems. Name them and fix them. <main> <section> <p>Welcome to the shop.</p> </section> </main> <main> <p>Contact us at the address below.</p> </main>
Show answer
First, the page has two visible main elements, but a page may have only one. Merge the content into a single main. Second, the section has no heading, so it is not a real thematic section. Either add a heading such as <h2>Welcome</h2> or replace the section with a div, or with plain paragraphs.