IntermediateLesson 15 of 307 min read

Semantic HTML: header, nav, main, section, article and footer

Give your page a meaningful structure with header, nav, main, section, article, aside, footer and figure.

In this lesson you will

  • Build a page skeleton with semantic elements
  • Choose between section, article and div
  • Caption images with figure
  • Explain why meaning matters

About 13 minutes

A page that explains itself

Open a newspaper and you instantly know what is what: a masthead at the top, sections, articles, a sidebar of related stories, a footer with the small print. You do not need labels to tell you, because position and shape carry meaning. Web pages can work the same way, but only if you tell the browser which part is which. That is the job of semantic elements.

In lesson 9 you built a page from div boxes. A browser sees a heap of unnamed boxes. A search engine sees no hint of what is important. A person using a screen reader cannot jump to the main content. Semantic elements fix all three problems with almost no extra work.

The page-level elements

<body>
  <header>
    <h1>Priya's Bakery</h1>
    <nav>
      <a href="index.html">Home</a>
      <a href="menu.html">Menu</a>
      <a href="contact.html">Contact</a>
    </nav>
  </header>

  <main>
    <h2>Fresh bread every morning</h2>
    <p>Come early, the sourdough goes fast.</p>
  </main>

  <footer>
    <p>&copy; 2026 Priya's Bakery</p>
  </footer>
</body>
  • <header> holds introductory content: the logo, the site title and often the navigation.
  • <nav> marks a block of main navigation links. Not every group of links needs it, only the major ones.
  • <main> contains the central content of the page. Use it once per page.
  • <footer> holds closing information such as copyright, contact details and secondary links.

Sections, articles and asides

Inside the main area, three elements help you divide the content.

  • <section> is a themed group of content, almost always with a heading. Think of a chapter of a book.
  • <article> is content that makes sense on its own, such as a blog post, a news story or a product card. If you could lift it out and place it on another site, it is an article.
  • <aside> is content only loosely related to what surrounds it: a sidebar, a pull quote, a tip box.
<main>
  <h1>Baking tips</h1>

  <article>
    <h2>Why sourdough needs patience</h2>
    <p>A good starter takes a week to build...</p>
  </article>

  <article>
    <h2>Keeping bread fresh</h2>
    <p>Wrap it in cloth, never plastic...</p>
  </article>

  <aside>
    <h2>Did you know?</h2>
    <p>Rye flour ferments faster than wheat.</p>
  </aside>
</main>
section or div?

Ask yourself whether the group has a heading and a clear theme. If yes, it is a section. If you are only grouping things so CSS can style them, use div.

Replace the div wrappers with the correct semantic elements: the top part is a header, the middle is main, and the bottom is a footer.

<div>
  <h1>My Portfolio</h1>
</div>
<div>
  <p>Welcome to my work.</p>
</div>
<div>
  <p>Contact me by email.</p>
</div>

Change the first div to header, the second to main and the third to footer, including the closing tags.

<header>
  <h1>My Portfolio</h1>
</header>
<main>
  <p>Welcome to my work.</p>
</main>
<footer>
  <p>Contact me by email.</p>
</footer>

Figures, captions and more

Other semantic elements are small but useful.

<figure>
  <img src="images/loaf.jpg" alt="A golden sourdough loaf on a board" width="600" height="400">
  <figcaption>Our signature sourdough, baked at 5 a.m.</figcaption>
</figure>

<p>Published <time datetime="2026-10-31">31 October 2026</time></p>
<p>Use <mark>whole-grain flour</mark> for best results.</p>
  • <figure> and <figcaption> tie an image or code sample to its caption.
  • <time> gives dates a machine-readable form through the datetime attribute.
  • <mark> highlights text that is relevant right now, like a search match.
  • <address> marks contact information for the nearest article or the page.

Why this matters beyond tidiness

  • Accessibility. Screen reader users can jump straight to the navigation or the main content, and skip the rest.
  • Search engines. Clear structure helps Google understand which part is the real content and what each section is about.
  • Maintenance. Months later, <footer> tells you more than the tenth <div class="box7">.
  • Reader modes and tools. Browsers and apps use these elements to build simplified views.
Common mistake

Do not stack semantic elements for decoration. Putting <article> around every paragraph, or using several <main> elements, makes the page worse for assistive technology. Choose each element for its meaning, not its looks.

Build a blog page outline: a header with an h1 and a nav containing two links, a main with one article that has a heading and a paragraph, and a footer.

<!-- write the whole structure here -->

Order: header (h1, nav with two a tags), main (article with h2 and p), footer (p).

<header>
  <h1>My Blog</h1>
  <nav><a href="#">Home</a> <a href="#">About</a></nav>
</header>
<main>
  <article>
    <h2>My first post</h2>
    <p>Hello, world.</p>
  </article>
</main>
<footer>
  <p>&copy; 2026 My Blog</p>
</footer>

A worked example: tidying a div page

Here is the kind of code beginners often write, and how to improve it step by step. Read the first version, then ask yourself what each box really is.

<div class="top">
  <div class="logo">Priya's Bakery</div>
  <div class="menu"><a href="/">Home</a> <a href="/menu">Menu</a></div>
</div>
<div class="content">
  <div class="post">
    <div class="post-title">Why sourdough needs patience</div>
    <div>A good starter takes a week to build.</div>
  </div>
</div>
<div class="bottom">2026 Priya's Bakery</div>
<header>
  <a href="/" class="logo">Priya's Bakery</a>
  <nav><a href="/">Home</a> <a href="/menu">Menu</a></nav>
</header>
<main>
  <article>
    <h1>Why sourdough needs patience</h1>
    <p>A good starter takes a week to build.</p>
  </article>
</main>
<footer>2026 Priya's Bakery</footer>

The visible result is identical. But the second version has a real heading instead of a styled div, a real paragraph, and landmarks that screen readers and search engines understand. Also, the class names have almost disappeared, because the elements themselves now say what they are. That is a sign of good HTML: fewer classes needed to explain the page.

Refactor old pages one region at a time

You do not have to rewrite a whole site. Change the header first, then the footer, then the main content. After each step, reload the page and check that nothing moved.

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

How many <main> elements should a page have?

  1. As many as you like
  2. One
  3. Two, header and footer
  4. None

main marks the single central content of the page.

Which element suits a blog post that could stand alone?

  1. <aside>
  2. <article>
  3. <nav>
  4. <mark>

An article is self-contained content that makes sense on its own.

What does <figcaption> do?

  1. Adds a caption to a figure
  2. Makes text bold
  3. Creates a table
  4. Starts a form

figcaption gives a caption to the figure that contains it.

Why use semantic elements instead of divs?

  1. They run faster
  2. They tell browsers, search engines and screen readers what each part is
  3. They are required by law
  4. They add colour automatically

Meaning helps accessibility, search and maintenance.

Which is the correct place for the main navigation links?

  1. Inside <nav>
  2. Inside <aside> only
  3. Inside <mark>
  4. Outside the body

nav is for the major navigation blocks, usually inside the header.

Summary

  • Semantic elements describe the role of each part of the page.
  • Use header, nav, main and footer for the skeleton.
  • Choose section, article or aside for content groups.
  • Do not overuse them. Pick by meaning.

Next lesson

You know the pieces. Next you will assemble them into complete, professional page layouts.

Questions

Do semantic elements change how the page looks?

Barely. Browsers give them a plain default style. Their value is in meaning, and you control the look with CSS.

Can I use more than one header?

Yes. A page has a main header, and each article or section may have its own header too.

Is semantic HTML good for SEO?

It helps search engines understand your page, and it supports accessibility, which is closely linked to quality signals. It is not a magic ranking switch, but it is a solid foundation.

Progress is saved in this browser.