HTML5 Semantic Elements: A Complete Guide with Examples
Semantic HTML improves accessibility, SEO, and code readability. Learn how to use header, nav, main, article, section, aside, and footer correctly.
HTML5 Semantic Elements: A Complete Guide
Before HTML5, web pages were built with generic <div> and <span> tags everywhere. While they work, they tell nothing about the content's meaning. Semantic HTML changes that.
Why Semantic HTML Matters
- Accessibility: Screen readers navigate semantic landmarks easily
- SEO: Search engines understand your page structure better
- Maintainability: Other developers can read your code faster
- Default styling: Browsers apply sensible defaults
The Main Semantic Elements
<header> — Introductory content
Used for the top of a page OR the top of an article. Can contain logo, navigation, title, search.
<header>
<h1>My Blog</h1>
<nav>...</nav>
</header><nav> — Navigation links
Reserved for major navigation blocks. Don't wrap every list of links in <nav>.
<nav aria-label="Main navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/blog">Blog</a></li>
</ul>
</nav><main> — The main content
The most important content of the page. There should be only one <main> per page.
<main>
<h1>Welcome to w3primecode</h1>
<p>Learn to code in your language.</p>
</main><article> — Self-contained content
A blog post, news article, forum post, or product card. Should make sense on its own.
<article>
<h2>10 Modern CSS Techniques</h2>
<p>CSS has evolved dramatically...</p>
</article><section> — Themed grouping
A thematic grouping of content, usually with a heading. Less standalone than <article>.
<section>
<h2>Features</h2>
<p>Our product includes...</p>
</section><aside> — Side content
Content tangentially related to the main content — sidebars, pull quotes, ads.
<aside>
<h3>Related Posts</h3>
<ul>...</ul>
</aside><footer> — Footer content
Copyright, contact info, related links. Can be used at page level OR within <article>.
<footer>
<p>© 2026 w3primecode. All rights reserved.</p>
</footer>A Complete Page Structure
<body>
<header>
<nav aria-label="Main">...</nav>
</header>
<main>
<article>
<h1>Blog Post Title</h1>
<section>
<h2>Introduction</h2>
<p>...</p>
</section>
<section>
<h2>Main Content</h2>
<p>...</p>
</section>
</article>
<aside>
<h2>Related</h2>
...
</aside>
</main>
<footer>...</footer>
</body>Common Mistakes
- **Using
<div>instead of<section>** — if it has a heading, use<section> - **Wrapping every
<ul>in<nav>** — only major navigation blocks - **Multiple
<main>elements** — only one per page - **Using
<header>for non-intro content** — it's not just a styled div
Accessibility Tips
- Use
aria-labelon<nav>when there are multiple navs:<nav aria-label="Footer"> - Use
<figure>and<figcaption>for images with captions - Use
<time datetime="2026-01-15">January 15, 2026</time>for dates
Conclusion
Semantic HTML is the foundation of accessible, SEO-friendly web pages. Start using these elements today — your users (and search engines) will thank you.