Skip to content
Tutorials Center
My learning

Topics

Lesson 47 of 122 ยท Page Structure and Layout

Semantic Elements

Learn the HTML semantic elements header, nav, main, article, section, aside, footer, hgroup and search, and how they create landmarks for assistive tech.

You could build an entire page out of <div> elements, and it would look fine. But a pile of identical boxes tells nobody what each box is. Semantic elements are containers with a meaning: this is the site header, this is the main content, this is a self-contained article, this is the footer.

That meaning is not decoration. Screen readers use it to offer shortcuts like "jump to main content". Search engines use it to tell your article apart from the menu around it. And other developers (including you, six months from now) can read the structure at a glance instead of decoding a forest of class names.

Why not just use div?

Compare two versions of the same page skeleton:

HTML
<!-- Generic boxes -->
<div class="top">โ€ฆ</div>
<div class="menu">โ€ฆ</div>
<div class="content">โ€ฆ</div>
<div class="bottom">โ€ฆ</div>

<!-- Semantic elements -->
<header>โ€ฆ</header>
<nav>โ€ฆ</nav>
<main>โ€ฆ</main>
<footer>โ€ฆ</footer>

Both render the same, because none of these elements has much default styling. The difference is that the browser understands the second version. Class names like menu mean something to humans, but the browser treats them as arbitrary labels. As you saw in Div and Span, <div> is the right choice only when no element with a better meaning exists.

The page-level elements

These elements describe the big regions of a page.

Element Meaning
<header> Introductory content: a logo, site name, page title, maybe a search form or navigation.
<nav> A block of major navigation links.
<main> The dominant content of the page โ€” the reason the visitor came.
<aside> Content related to the surrounding content but separate from it: a sidebar, a glossary box, related links.
<footer> Closing information: author, copyright, contact links, related documents.
A semantic page skeleton

The dashed borders and labels come from the <style> block, so you can see each region. Without them, the page would look like plain text โ€” semantic elements carry meaning, not looks.

Rules worth remembering

  • One visible <main> per page. It must not sit inside <header>, <nav>, <article>, <aside> or <footer>. (You may have extra <main> elements only if all but one are hidden, which single-page apps sometimes do.)
  • <header> and <footer> are not only for the page. An <article> or <section> can have its own header and footer too. They just cannot contain another <header> or <footer>.
  • Not every group of links needs <nav>. Use it for the main menu, a table of contents or breadcrumbs. A couple of links in a footer usually do not need it.

article and section

These two cause the most confusion, so here is the key test:

  • <article> is a self-contained piece that would still make sense if you lifted it out and put it somewhere else: a blog post, a news story, a product card, a forum reply, a comment.
  • <section> is a thematic part of something bigger, normally with its own heading: the "Ingredients" part of a recipe, the "Pricing" part of a landing page.

Ask yourself: "Could this be published on its own, for example in a news feed?" If yes, use <article>. If it only makes sense as a chapter of the whole, use <section>. If you only need a box for styling, use <div>.

Articles and sections

Notice that articles can nest: each comment is its own <article> inside the post, because a comment is a self-contained piece of content written by someone else.

Give every <section> a heading. If you cannot think of a sensible heading for a section, it is probably not a section โ€” it is a styling wrapper, and <div> is the better element.

hgroup: a heading with a subtitle

Sometimes a heading comes with a tagline or subtitle. Wrap the heading and one or more paragraphs in <hgroup> to show they belong together:

HTML
<hgroup>
  <h1>Night Trains of Europe</h1>
  <p>Sleeping your way from Lisbon to Lviv</p>
</hgroup>

The paragraph is not a heading itself, so it does not appear in the document outline โ€” only the <h1> does. (Older tutorials put a second heading inside <hgroup>; the current standard uses a <p> instead.)

search: a search region

The <search> element wraps a search or filtering feature, usually a small form:

HTML
<search>
  <form action="/search">
    <label for="q">Search recipes</label>
    <input id="q" name="q" type="search">
    <button>Search</button>
  </form>
</search>

It is one of the newest elements in HTML. Browsers that do not know it yet simply treat it like a <div>, so it is safe to use today. You will learn how the form itself works in the Forms lesson.

Landmarks: how assistive technology uses all this

Screen readers build a list of landmarks from your semantic elements and let users jump straight to one. That is like a sighted visitor glancing at a page and spotting the menu. The mapping looks like this:

Element Landmark role Notes
<header> banner Only when it is the page header, not inside <article>, <section> and so on.
<nav> navigation
<main> main
<aside> complementary
<footer> contentinfo Only when it is the page footer.
<section> region Only when it has an accessible name, for example via aria-labelledby.
<search> search
<form> form Only when it has an accessible name.

When a page has more than one <nav>, give each a label so users can tell them apart:

HTML
<nav aria-label="Main">โ€ฆ</nav>
โ€ฆ
<nav aria-label="Footer">โ€ฆ</nav>

You will dig deeper into this in Accessibility Basics and ARIA Roles, States and Properties. The short version: if you use the right elements, you get most landmarks for free, with no ARIA at all.

Practice: give a page some meaning

The page below is built only from <div> elements. Replace each one with the most fitting semantic element. Then compare your answer with the hints in the comments.

Your turn: replace the divs

Common mistakes

  • Using <section> as a generic wrapper. If there is no heading and no theme, use <div>.
  • Wrapping every link list in <nav>. Save it for major navigation blocks.
  • Putting <main> inside <header> or <article>. It belongs at the top level of the body (or inside a plain <div> wrapper).
  • Choosing elements for their looks. None of these elements has special styling worth relying on. Pick them for meaning, then style them with CSS.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which element fits a single customer review that could appear on its own in a "latest reviews" feed?

    A review is self-contained and makes sense outside its page, which is exactly what <article> means.
  2. 2. How many visible <main> elements should a page have?

    <main> marks the dominant content of the whole page, so there is one visible <main>. Extra ones are only allowed if they are hidden.
  3. 3. A box that only exists so you can give a group of elements a background color should be aโ€ฆ

    When an element has no meaning beyond styling, <div> is the honest choice. A <section> should have a theme and a heading.
  4. 4. A page has a main menu and a separate menu of legal links in the footer, both in <nav>. What should you add?

    Both appear as navigation landmarks. Labels like aria-label="Main" and aria-label="Legal" let users tell them apart.

Summary

  • Semantic elements describe what a region is; <div> describes nothing.
  • <header>, <nav>, <main>, <aside> and <footer> mark the big regions of a page.
  • Use <article> for self-contained content and <section> for a themed part with a heading.
  • <hgroup> pairs a heading with a subtitle paragraph; <search> wraps search and filter features.
  • These elements create landmarks that let assistive technology users jump around the page.

Next lesson: Page Layout โ€” arranging these elements on screen with Flexbox and Grid.