In the early days of the web, developers used <div> and <span> for everything. While it worked, it gave search engines and assistive technologies zero context about your content. HTML5 semantic elements change that by describing what your content is, not just how it looks.
What Are Semantic Elements?
Semantic elements clearly describe their meaning to both the browser and the developer:
| Non-Semantic | Semantic | Meaning |
|---|---|---|
<div id="header"> |
<header> |
Page/section introduction |
<div id="nav"> |
<nav> |
Navigation links |
<div id="main"> |
<main> |
Primary content |
<div class="post"> |
<article> |
Self-contained content |
<div id="sidebar"> |
<aside> |
Supplementary content |
<div id="footer"> |
<footer> |
Page/section conclusion |
The Complete Semantic Element Reference
<header> — Introduction Content
Contains introductory content or navigation aids. Can be used for the page header or within sections/articles.
<!-- Page header -->
<header>
<h1>My Website</h1>
<nav><!-- Navigation --></nav>
</header>
<!-- Article header -->
<article>
<header>
<h2>Blog Post Title</h2>
<p>Published on <time datetime="2025-12-21">December 21, 2025</time></p>
</header>
<p>Article content...</p>
</article>
<nav> — Navigation Links
Contains major navigation blocks. Not every group of links needs <nav> — use it for primary navigation.
<nav aria-label="Primary navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/products">Products</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
<!-- Multiple navs on one page -->
<nav aria-label="Footer navigation">
<a href="/privacy">Privacy</a>
<a href="/terms">Terms</a>
</nav>
<main> — Primary Content
The dominant content of the <body>. Should be unique to the page (excluding repeated elements like nav, header, footer).
<body>
<header><!-- Site header --></header>
<nav><!-- Primary nav --></nav>
<main>
<h1>Page Title</h1>
<p>This is the main content unique to this page.</p>
</main>
<footer><!-- Site footer --></footer>
</body>
Important: Only one <main> per page.
<article> — Self-Contained Content
Content that makes sense on its own, independent from the rest of the page:
- Blog posts
- News articles
- Forum posts
- User comments
- Product cards
- Interactive widgets
<article>
<header>
<h2>Understanding Flexbox</h2>
<p>By <a href="/author/jane">Jane Doe</a> on <time>Dec 21, 2025</time></p>
</header>
<p>Flexbox is a one-dimensional layout method...</p>
<footer>
<p>Tags: <a href="/tag/css">CSS</a>, <a href="/tag/layout">Layout</a></p>
</footer>
</article>
<section> — Thematic Grouping
Groups related content with a heading. Unlike <article>, a <section> isn't independently distributable.
<article>
<h1>Complete Guide to CSS Grid</h1>
<section>
<h2>Introduction</h2>
<p>CSS Grid changes how layout works...</p>
</section>
<section>
<h2>Basic Syntax</h2>
<p>Grid containers and items...</p>
</section>
<section>
<h2>Advanced Techniques</h2>
<p>Named lines and areas...</p>
</section>
</article>
<aside> — Supplementary Content
Content tangentially related to the surrounding content:
- Sidebars
- Pull quotes
- Advertising
- Related links
- Author bios
<main>
<article>
<h1>JavaScript Closures Explained</h1>
<p>A closure is a function...</p>
<aside>
<h3>Related Reading</h3>
<ul>
<li><a href="/js-scope">Understanding Scope</a></li>
<li><a href="/js-hoisting">Variable Hoisting</a></li>
</ul>
</aside>
</article>
</main>
<!-- Page-level aside (sidebar) -->
<aside>
<h2>Popular Posts</h2>
<ul>...</ul>
</aside>
<footer> — Conclusion Content
Contains information about its parent element: author, copyright, related links.
<!-- Page footer -->
<footer>
<p>© 2025 My Company. All rights reserved.</p>
<nav>
<a href="/privacy">Privacy</a>
<a href="/terms">Terms</a>
</nav>
</footer>
<!-- Article footer -->
<article>
<h2>10 CSS Tips</h2>
<p>Content...</p>
<footer>
<p>Written by John Doe</p>
<p>Share: <a href="#">Twitter</a> | <a href="#">LinkedIn</a></p>
</footer>
</article>
<figure> and <figcaption> — Self-Contained Media
For images, diagrams, code listings, etc. with captions:
<figure>
<img src="chart.png" alt="Sales growth chart showing 50% increase" width="600" height="400">
<figcaption>Fig 1: Quarterly sales growth, Q1-Q4 2025</figcaption>
</figure>
<figure>
<pre><code>
function hello() {
console.log("Hello, World!");
}
</code></pre>
<figcaption>A simple JavaScript greeting function</figcaption>
</figure>
<time> — Machine-Readable Dates
Represents dates and times in human and machine-readable format:
<p>Published on <time datetime="2025-12-21">December 21, 2025</time></p>
<p>Event starts at <time datetime="2025-12-25T19:00:00">7 PM on Christmas Day</time></p>
<p>Duration: <time datetime="PT2H30M">2 hours and 30 minutes</time></p>
<mark> — Highlighted Text
Represents text highlighted for reference purposes:
<p>Search results for "semantic HTML":</p>
<p>Using <mark>semantic HTML</mark> improves accessibility...</p>
<details> and <summary> — Expandable Content
Native HTML accordion without JavaScript:
<details>
<summary>What is semantic HTML?</summary>
<p>Semantic HTML uses tags that describe the meaning of content,
not just its appearance.</p>
</details>
<details open><!-- open by default -->
<summary>Why does it matter?</summary>
<p>SEO, accessibility, and maintainability all improve.</p>
</details>
Why Semantic HTML Matters
1. SEO Benefits
Search engines understand your page structure better:
<!-- Without semantics (harder for Google) -->
<div class="post">
<div class="title">My Article</div>
<div class="content">...</div>
</div>
<!-- With semantics (Google understands this) -->
<article>
<h1>My Article</h1>
<p>...</p>
</article>
Impact:
- Google can identify main content vs. navigation
- Featured snippets extracted more accurately
- Better understanding of content hierarchy
2. Accessibility Benefits
Screen readers use semantic elements to navigate:
| Element | Screen Reader Behavior |
|---|---|
<nav> |
"Navigation region" — skip with hotkey |
<main> |
"Main content" — jump directly |
<article> |
"Article" — browse between articles |
<header> |
"Banner" (page) or "Header" (section) |
<footer> |
"Content info" |
User experience for blind users:
"Navigation region, 5 links: Home, Products, About..."
[User presses shortcut to skip]
"Main content..."
3. Code Maintainability
Compare debugging these:
<!-- Nightmare to maintain -->
<div class="wrapper">
<div class="inner">
<div class="section-1">
<div class="header-area">...</div>
</div>
</div>
</div>
<!-- Self-documenting -->
<main>
<article>
<header>...</header>
</article>
</main>
Common Mistakes to Avoid
❌ Mistake 1: Using Section as a Div Replacement
<!-- Wrong: section without heading -->
<section class="flex-container">
<div>Item 1</div>
<div>Item 2</div>
</section>
<!-- Right: div for non-semantic grouping -->
<div class="flex-container">
<div>Item 1</div>
<div>Item 2</div>
</div>
Rule: If it doesn't have a heading, it probably shouldn't be a <section>.
❌ Mistake 2: Multiple <main> Elements
<!-- Wrong -->
<main>...</main>
<main>...</main>
<!-- Right: only one main -->
<main>
<section>...</section>
<section>...</section>
</main>
❌ Mistake 3: Nav for Every Link Group
<!-- Wrong: using nav for footer links -->
<footer>
<nav>
<a href="/privacy">Privacy</a>
</nav>
</footer>
<!-- Right: nav only for major navigation -->
<footer>
<p><a href="/privacy">Privacy</a> | <a href="/terms">Terms</a></p>
</footer>
❌ Mistake 4: Article vs Section Confusion
<!-- Article: Would this make sense in an RSS feed? -->
<article><!-- Yes: it's a blog post --></article>
<!-- Section: Is it a thematic grouping with a heading? -->
<section>
<h2>Features</h2><!-- Yes: related content grouped -->
</section>
Complete Page Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Semantic HTML Example</title>
</head>
<body>
<header>
<h1>My Website</h1>
<nav aria-label="Primary">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/blog">Blog</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
</header>
<main>
<article>
<header>
<h2>Understanding Semantic HTML</h2>
<p>By <a href="/author/john">John Doe</a>
on <time datetime="2025-12-21">December 21, 2025</time></p>
</header>
<section>
<h3>What Are Semantic Elements?</h3>
<p>Semantic elements describe meaning...</p>
</section>
<section>
<h3>Why They Matter</h3>
<p>SEO and accessibility improve...</p>
</section>
<aside>
<h4>Related Articles</h4>
<ul>
<li><a href="/aria-guide">ARIA Guide</a></li>
</ul>
</aside>
<footer>
<p>Tags: <a href="/tag/html">HTML</a>, <a href="/tag/seo">SEO</a></p>
</footer>
</article>
</main>
<aside>
<h2>Popular Posts</h2>
<ul>
<li><a href="/css-grid">CSS Grid Guide</a></li>
</ul>
</aside>
<footer>
<p>© 2025 My Website</p>
<nav aria-label="Footer">
<a href="/privacy">Privacy</a>
<a href="/terms">Terms</a>
</nav>
</footer>
</body>
</html>
FAQ
Q: Should I still use div and span? A: Yes! Use them for non-semantic grouping (styling, JavaScript targeting). Semantic elements don't replace div; they complement it.
Q: Does semantic HTML affect page load speed? A: No. It's purely semantic — browser rendering is the same.
Q: How does semantic HTML help SEO specifically? A: Google can identify main content, skip navigation, find articles, and understand page hierarchy — leading to better indexing and potential rich snippets.
Q: Is semantic HTML required for accessibility compliance? A: While not strictly required by WCAG, it's strongly recommended. Proper semantics significantly reduce the need for ARIA attributes.
Practice Your HTML Skills
Refactor your old code and see the difference:
- HTML Editor — Practice semantic HTML with AI assistance
- HTML Beautifier — Clean up messy markup
- CSS Editor — Style your semantic elements
Last updated: December 2025 | Written by Muhammed Ajmal U K