Lesson 8 / 8100%

Lesson 8

Semantic HTML

20 min

header, nav, main, section, footer: give the page a meaningful structure.

Why semantic HTML?

Semantic HTML means using tags that describe the meaning of an area of the page, rather than piling up generic <div> elements everywhere. This improves accessibility (screen readers can jump from one area to another) and search engine optimization (SEO) — Google better understands the outline of your page.

The word "semantic" comes from Greek and refers to what concerns meaning. A semantic tag clearly says what it contains: <nav> contains navigation, <footer> a page footer. Conversely, a non-semantic tag like <div> or <span> says nothing about its content: it is a simple container.

The "div soup" problem

Before HTML5, developers had no tags to describe the main areas of a page. So they used <div> elements everywhere, distinguished only by a class name. The result displays correctly on screen, but for a robot or a screen reader, the page is a succession of anonymous blocks. Compare the two ways of writing the same page:

Div soup (to avoid)

<div class="top">
  <div class="menu">
    <a href="/">Home</a>
  </div>
</div>
<div class="content">
  <div class="title">My article</div>
  <div>Some text...</div>
</div>
<div class="bottom">© 2026</div>

Semantic version

<header>
  <nav>
    <a href="/">Home</a>
  </nav>
</header>
<main>
  <h1>My article</h1>
  <p>Some text...</p>
</main>
<footer>© 2026</footer>

The version on the right is shorter, more readable, and no longer needs class names to be understood. Also notice that the title has become a real <h1>, and the text a real <p>.

Complete example

semantic-page.html
<body>
  <header>
    <h1>My Blog</h1>
    <nav>
      <a href="/">Home</a>
      <a href="/articles">Articles</a>
      <a href="/contact">Contact</a>
    </nav>
  </header>

  <main>
    <section>
      <h2>Latest articles</h2>
      <article>
        <h3>Article title</h3>
        <p>Article content...</p>
      </article>
      <article>
        <h3>Another article</h3>
        <p>More content...</p>
      </article>
    </section>

    <aside>
      <h2>About</h2>
      <p>A few words about the author of the blog.</p>
    </aside>
  </main>

  <footer>
    <p>&copy; 2026 My Blog</p>
  </footer>
</body>

To help you visualize this organization, here is the page outline as a tree:

page-outline.txt
body
├── header
│   ├── h1 (site title)
│   └── nav (menu links)
├── main
│   ├── section (Latest articles)
│   │   ├── article
│   │   └── article
│   └── aside (About)
└── footer

The tags one by one

  • <header> — header of a page or a section (often logo + navigation). A page can have several header elements (one per section).
  • <nav> — block of main navigation links (menu, breadcrumb).
  • <main> — the main, unique content of the page (only once per page).
  • <section> — thematic grouping of content, generally with its own heading.
  • <article> — self-contained content that would make sense on its own (a blog post, a comment, a product card).
  • <aside> — related but secondary content (sidebar, ad box, related links).
  • <footer> — footer of a page or a section (copyright, secondary links, legal notices).

A closer look at header and footer

The <header> and <footer> tags are not reserved for the top and bottom of the page: they apply to their closest parent. Placed directly in the body, they concern the whole page; placed in an article, they concern only that article.

header-footer-article.html
<article>
  <header>
    <h2>My trip to Madagascar</h2>
    <p>Published on <time datetime="2026-03-14">March 14, 2026</time> by Hery</p>
  </header>

  <p>The story of my first week on the island...</p>

  <footer>
    <p>Category: travel — 12 comments</p>
  </footer>
</article>

A closer look at nav and main

The <nav> tag is reserved for important navigation blocks (main menu, table of contents, pagination), not for every small group of links. Footer links, for example, generally don't need their own nav. If a page contains several, tell them apart with an aria-label attribute:

multiple-nav.html
<nav aria-label="Main menu">
  <a href="/">Home</a>
  <a href="/courses">Courses</a>
</nav>

<nav aria-label="Pagination">
  <a href="/page/1">1</a>
  <a href="/page/2">2</a>
</nav>

As for <main>, it contains what is specific to this page: everything that repeats across several pages (menu, logo, footer) stays outside. It must not be placed inside an article, a header or a footer. Screen readers offer a shortcut to jump straight to the main, which saves users from listening to the menu on every new page.

section vs. article vs. div

These three tags look alike visually (none of them does anything by default), but their meaning differs:

<article>

Stands on its own. Would make sense republished elsewhere (article, product, comment).

<section>

Groups a theme, generally with its own heading (e.g. "Our services").

<div>

No particular meaning — only useful for styling or technical structure.

Here are two simple questions to ask yourself when choosing. First test: if I took this block out of the page to publish it on its own (in an RSS feed, a share on a social network), would it make sense? If so, it's an article. Second test: does this block have a theme and naturally a heading (h2, h3...)? If so, it's a section. Otherwise, and only for styling, a div will do.

choosing-the-tag.html
<!-- section: a theme, with its heading -->
<section>
  <h2>Our services</h2>
  <p>Website design, training, consulting.</p>
</section>

<!-- article: self-contained content -->
<article>
  <h2>How to choose your first language</h2>
  <p>My experience after a year of learning...</p>
</article>

<!-- div: a simple container for styling -->
<div class="card-grid">
  <article>...</article>
  <article>...</article>
</div>

aside, content set apart

The <aside> tag holds content that is related to the main content, but that could be removed without hindering reading: a sidebar, a "Did you know?" box, an author biography, links to neighboring articles. In an article, a box that extends the discussion is an aside. On the other hand, if the content is essential to understanding, it is not anaside.

figure and figcaption

To caption an image, a diagram or a code snippet in a semantic way, you use <figure> and <figcaption>.

figure.html
<figure>
  <img src="/images/chart.png" alt="Chart of 2024 sales" />
  <figcaption>Sales trend over the year 2024</figcaption>
</figure>

A figure is not limited to images: it can contain a code snippet, a table, a quotation or a diagram, as long as the content is self-contained and referenced by the text ("see figure 2").

Other tags that add meaning

Semantics is not limited to the main areas of the page. Several smaller tags give meaning to a specific piece of content:

other-semantic-tags.html
<!-- time: a machine-readable date or time -->
<p>See you on <time datetime="2026-12-24T18:00">December 24 at 6 p.m.</time>.</p>

<!-- address: contact details for the author or the site -->
<address>
  Write to <a href="mailto:contact@example.com">contact@example.com</a><br />
  Antananarivo, Madagascar
</address>

<!-- details and summary: collapsible content, without JavaScript -->
<details>
  <summary>What is semantic HTML?</summary>
  <p>It is the use of tags that describe the meaning of the content.</p>
</details>

<!-- blockquote and cite: a quotation and its source -->
<blockquote cite="https://example.com/source">
  <p>The web is for everyone.</p>
</blockquote>
  • <time> — the datetimeattribute gives a standard format that search engines understand, even if the displayed text is written out in words.
  • <address> — reserved for contact details, not for just any postal address.
  • <details> and <summary> — a block that expands on click, ideal for an FAQ, with keyboard and screen reader support built in.
  • <blockquote> — a long quotation, with the cite attribute for the source.

Headings in a semantic page

Semantic tags and the h1 to h6headings work together to draw the outline of the page. Each section and each article should start with a heading of the right level. A section without a heading is often a sign that a simple div would have been enough. In this course's example, the h1 gives the site name, the h2 elements open each section, and the h3 elements title each article.

What screen readers see

The header, nav, main, aside and footer tags are recognized as landmarks: screen readers offer the user a list of these areas and a shortcut to move from one to another. (A header orfooter counts as a page-level landmark only when it is placed directly in the body.) For a blind person, this is the equivalent of the glance a sighted visitor casts at the page to spot the menu, the content and the footer.

With a soup of div elements, these landmarks don't exist: the user has to listen to the page from top to bottom, including the menu, on every new page. That is why a golden rule of accessible HTML is to always prefer the appropriate native tag rather than rebuilding its role with div elements and special attributes.

Tip

A good rule: if you can replace a <div>with a semantic tag that correctly describes its role, do it. When in doubt (just a technical container for styling), <div>remains perfectly legitimate.

How to check your structure

There are several simple ways to test whether your page is well structured:

  • The "no CSS" test — in the developer tools (F12), disable the stylesheets: if the page remains readable and logical, your structure is good.
  • The keyboard test — navigate the page with the Tab key: the order of focus should follow the logical reading order.
  • The heading outline — read only your headings: they should tell the story of the page.
  • The HTML validator — the W3C's online service (validator.w3.org) detects misplaced or unclosed tags.
  • A screen reader — try NVDA (free on Windows) or VoiceOver (built into Mac and iPhone) to hear your page the way its users do.

Common beginner mistakes

  • Replacing every div with a section without thinking: a section must have a theme and a heading.
  • Writing several main elements in the same page: you only need one.
  • Using nav for every small group of links, which drowns out the important landmarks.
  • Choosing a tag for its appearance ("aside puts the text on the side") instead of its meaning: appearance is set with CSS.
  • Putting an h1 in every section: keep a single h1 per page and go down through the levels.
  • Thinking that semantics is "optional" because the page looks the same: the benefit is invisible on screen, but very real for accessibility and SEO.

Key takeaways

  • A semantic tag describes the meaning of its content; a div has none
  • header, nav, main, aside and footer are landmarks for screen readers
  • article = self-contained content, section = theme with a heading, div = simple styling container
  • header and footer apply to their parent: the whole page or just an article
  • A single main and a single h1 per page
  • Choose a tag for its meaning, never for its appearance, and always prefer the appropriate native tag

Exercise

Take your "About me" page and restructure it with header, main and footerinstead of plain div elements.

Going further

Add a <nav> tag in your header with 2-3 links, then use figure/figcaption to caption your image.

Challenge: turn a div soup into a real page

Take the "div soup" code seen above and build on it to make a real blog page: add two <article> elements, each with its own<header> containing a title and a date in a<time> tag, an <aside> "About the author", and an FAQ with <details> and <summary>. Then draw your page's tree on paper, and check that it remains readable when you disable CSS in the developer tools.