HTML · Modern HTML

Semantic HTML

Two pages can look identical yet be very different underneath. Semantic HTML uses elements that describe their purpose, which helps screen readers, search engines and other developers.

Intermediate 5 min Lesson 13 of 22 Runnable examplesFollows the WHATWG HTML Living Standard.
Before you start:Introduction to HTML
0/22 in HTML
On this page · 5 min · Intermediate

Learning objectives#

  • Explain what “semantic” means
  • Use landmark elements: header, nav, main, aside, footer
  • Choose between article, section and div
  • Understand how semantics help accessibility and SEO

Explanation#

A <div> says nothing about its contents. A <nav> says “this is a group of navigation links”. That extra meaning is semantics.

Screen readers expose landmark elements (header, nav, main, aside, footer) so users can jump straight to the main content or navigation.

Use <article> for self-contained content that makes sense on its own (a blog post, a product card). Use <section> for a themed group of content with its own heading. Use <div> when you only need a styling hook.

Code example: A semantic page layout#

HTMLA semantic page layout Runnable
<header>
  <h1>Techie Blog</h1>
  <nav aria-label="Main">
    <a href="/">Home</a> | <a href="/posts">Posts</a>
  </nav>
</header>


<main>
  <article>
    <h2>Understanding Flexbox</h2>
    <p><time datetime="2026-10-01">1 October 2026</time></p>
    <p>Flexbox lays items out in one dimension…</p>
  </article>
</main>


<aside>
  <h2>Related</h2>
  <a href="/posts/grid">CSS Grid basics</a>
</aside>


<footer>
  <p>&copy; 2026 Techie Blog</p>
</footer>
Expected output
A page with a header and navigation, a blog article in the main area, a related-links sidebar and a footer.
Opens this example in the full playground

Step-by-step explanation#

  1. <header> contains introductory content: the site title and navigation.
  2. <nav aria-label="Main"> marks the primary navigation. The label distinguishes it if the page has more than one nav.
  3. <main> wraps the unique content of the page. Use it only once per page.
  4. <article> holds the blog post because it would make sense on its own.
  5. <time datetime> gives machines an exact date while people see a friendly one.
  6. <aside> holds content related to, but separate from, the main content.

Real-world use case#

News sites, blogs and documentation (like this page) use semantic landmarks so assistive-technology users can navigate quickly and search engines can understand which part is the main content.

Common mistakes#

“Div soup”

Building everything from <div> and <span> works visually but removes all meaning. Reach for a semantic element first.

Clickable divs

A <div onclick> is not keyboard-focusable and is not announced as a button. Use <button> for actions and <a href> for navigation.

Multiple <main> elements

Only one <main> should be visible per page.

Best practices#

  • Use one <main> per page
  • Give every <section> a heading
  • Label repeated landmarks with aria-label
  • Prefer native elements over ARIA roles — the first rule of ARIA

Remember this#

Use elements for meaning: header, nav, main, article, footer.

Semantic HTML helps screen readers and SEO.

Use <button> for actions, <a> for navigation.

Practice exercise#

Your task: Convert this layout to semantic HTML: <div class="top"><div class="menu">…</div></div><div class="content">…</div><div class="bottom">…</div>

Show solution
HTML Illustrative
<header>
  <nav aria-label="Main">…</nav>
</header>
<main>…</main>
<footer>…</footer>

Mini quiz#

Semantic HTML quizMultiple choice Question 1 of 3

Which element should wrap the primary, unique content of a page?

Score so far: 0/0

Want more? Practise all HTML MCQs · HTML interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.