Reading history

HTML Semantic Elements: header, nav, main, footer

4 min read Updated 3 views

Learn HTML semantic elements: header, nav, main, article, section, aside and footer, and how they improve accessibility and SEO.

A page built only from <div> elements may look fine, but it tells browsers, search engines and screen readers nothing about its structure. Semantic elements such as <header>, <nav>, <main> and <footer> say what each part of the page is. They make pages more accessible, help search engines understand your content and make your own code easier to read.

In this lesson you will learn

  • What “semantic” means in HTML
  • The main layout elements and when to use each
  • The difference between <article> and <section>
  • Smaller semantic elements such as <time>
  • How semantics help accessibility and SEO

A Semantic Page Layout

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Semantic layout</title>
  <style>
    body { font-family: sans-serif; margin: 0; }
    header, nav, main, aside, footer { padding: 6px 10px; margin: 4px; border-radius: 6px; }
    header { background: #b2dfdb; } nav { background: #e0f2f1; }
    main { background: #fff8e1; } aside { background: #f3e5f5; } footer { background: #eceff1; }
  </style>
</head>
<body>
  <header><strong>Core Tech ED</strong></header>
  <nav><a href="#">Home</a> | <a href="#">Courses</a></nav>
  <main>
    <article>
      <h2>Learning HTML</h2>
      <p>Published <time datetime="2026-11-15">15 November 2026</time></p>
    </article>
  </main>
  <aside>Related: CSS basics</aside>
  <footer>&copy; 2026 Core Tech ED</footer>
</body>
</html>

Result

  • <header>: introductory content, usually the logo and site title.
  • <nav>: a block of main navigation links.
  • <main>: the unique main content of the page. Use only one per page.
  • <article>: a self-contained piece that would make sense on its own, such as a blog post or news story.
  • <aside>: related but secondary content, such as a sidebar.
  • <footer>: closing information: copyright, contact and policy links.
  • <time datetime="2026-11-15"> gives a machine-readable date while showing a friendly one.

The background colours come from CSS and are only there to show where each element sits.

Semantic Elements Reference

ElementMeaning
<section>A themed group of content, normally with its own heading
<article>Independent, reusable content
<figure> / <figcaption>An image, chart or code sample with its caption
<address>Contact information
<details> / <summary>A box the reader can open and close
<mark>, <time>, <abbr>Highlighted text, dates and abbreviations

Why Semantics Matter

  • Accessibility: screen-reader users can jump straight to the navigation or main content.
  • SEO: search engines can tell your main content apart from menus and footers.
  • Maintainability: <nav> is easier to understand than <div class="nav-wrapper-2">.

Keep using <div> and <span> where nothing more meaningful fits, such as wrappers that exist only for styling.

Common Mistakes

  1. Several <main> elements on one visible page.
  2. Using <section> as a styling wrapper where a <div> belongs.
  3. Choosing headings by size. Pick <h2> or <h3> by structure and change the size with CSS.
  4. Wrapping every group of links in <nav>. Keep it for major navigation.

Practice Exercises

Exercise 1. Mark up a blog post with a title, a date and two paragraphs.

Show answer
<article>
  <h2>My First Python Program</h2>
  <p><time datetime="2026-11-15">15 Nov 2026</time></p>
  <p>Today I printed my first line of output.</p>
  <p>Next I will learn loops.</p>
</article>

Exercise 2. Create a question that reveals its answer when clicked, without JavaScript.

Show answer
<details>
  <summary>What does HTML stand for?</summary>
  <p>HyperText Markup Language.</p>
</details>

Frequently Asked Questions

What is the difference between article and section?

An <article> makes sense on its own, such as a post you could share. A <section> is one part of something larger, such as the “Pricing” part of a page.

Do semantic elements look different from div?

Mostly no. Their value is meaning, not appearance; use CSS to style them.

Summary

  • Semantic elements describe what content is, not how it looks.
  • Build pages from <header>, <nav>, <main>, <article>, <aside> and <footer>.
  • Semantics improve accessibility, SEO and readability.

Next: style your pages with CSS Selectors.

Lessons are also marked complete when you click Next.

Leave a Reply

Your email address will not be published. Required fields are marked *