HTML Semantic Elements
Before HTML5, developers built entire pages using only <div> and <span> — elements
with no inherent meaning. HTML5 introduced a rich set of semantic elements that describe
the role of their content. In this chapter you'll learn every semantic element, why they matter for SEO and
accessibility, and how to structure a real web page with them.
<header>, <nav>, <main>, <footer><article>, <section>,
<aside>
<figure>, <time>, <address><details>
& <summary><div>What is Semantic HTML?
A semantic element clearly describes its meaning to both the browser and the developer. Compare these two lines — they look identical in the browser, but carry completely different meaning:
<nav> tells Google it's navigation, an <article> tells it there's a standalone piece of content worth
indexing. This directly improves your search ranking.
<header>, <main>, <nav>, <footer>) to let
keyboard users jump directly to sections of a page without reading every element. This
is critical for WCAG compliance.<aside> immediately communicates "sidebar
content" — whereas <div class="sidebar"> requires reading the
CSS to understand it.Semantic Page Layout — Visual Diagram
Here is how semantic elements map to a typical web page layout. Each element has a specific role in the document structure:
All Semantic Elements — Reference Cards
Here is every HTML5 semantic element with its purpose, category, and usage example:
<header> elements —
one
for the site, one inside an <article>.
<nav>.
<main>. Screen readers jump
directly
to it. Do not put navigation, headers, or footers inside it.
<article>.
<section> should
always have a heading. If there's no heading, use <div>
instead.
<figcaption>. The content can be moved elsewhere in the
document
without affecting the main flow. Google uses the caption for image indexing.
datetime attribute provides a machine-readable format (ISO 8601)
while
the content shows the human-friendly version. Used by search engines for event and article date
indexing.
<article> or the whole
document — email, phone, physical address, or social links. Renders in italic by default. Used by search
engines and browsers for local SEO and contact card extraction.
<summary> is the clickable header. The rest of the content
toggles. Add the open attribute to start it expanded.
<strong> (importance) —
<mark> signals relevance or attention.
<details> & <summary> — Live Demo
The <details> element creates a fully
functional accordion with zero JavaScript. Click any item below to expand it:
What is the difference between <article> and <section>?
<article> is self-contained — it makes
sense on its own if taken out of context (a blog post, a product card). A <section> is a themed group that is part of a
larger whole. An article can contain multiple sections, and a section can contain multiple articles.
Can I have multiple <main> elements on one page?
<main>
element. The <main> represents the dominant, unique content of
the page. Multiple <main> elements would confuse both search
engines and screen readers about which content is primary. If you have additional content, wrap it in
<section> or <aside>
instead.
When should I use <div> instead of a semantic element?
<div> when no semantic element fits — for pure CSS
layout containers (flexbox row, grid wrapper, card border), JavaScript hook targets, or
grouping elements that don't represent a meaningful document structure. If you find yourself adding a
class like class="article" or class="navigation", that's a signal to use the semantic tag instead.
<!-- Collapsed by default -->
<details>
<summary>What is HTML?</summary>
<p>HTML stands for HyperText Markup Language. It is the foundation of every web page.</p>
</details>
<!-- Open by default — add the "open" attribute -->
<details open>
<summary>Course Prerequisites</summary>
<ul>
<li>No prior experience required</li>
<li>A laptop with a browser</li>
</ul>
</details>
Common Mistakes — Do's & Don'ts
These are the most frequent semantic HTML mistakes beginners make:
<!-- Use semantic elements for structure -->
<header>
<nav>...</nav>
</header>
<main>
<article>
<h1>HTML Tutorial</h1>
<section>
<h2>What is HTML?</h2>
</section>
</article>
</main>
<footer>© 2026 K2infocom</footer>
<!-- All divs — no meaning for anyone -->
<div class="header">
<div class="nav">...</div>
</div>
<div class="main">
<div class="article">
<div class="title">HTML Tutorial</div>
<div class="section">....</div>
</div>
</div>
<div class="footer">...</div>
<div> freely for
CSS layout containers — flexbox rows, grid cells, card borders, animation wrappers —
wherever you need a container that carries no document meaning. The rule is: if a semantic element fits, use
it; if none fits, <div> is perfect.
Complete Example — Semantic Blog Page
Here is a realistic, fully semantic HTML blog page structure using every major element:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>K2infocom HTML Tutorial Blog</title>
</head>
<body>
<!-- Site-level header -->
<header>
<img src="logo.png" alt="K2infocom Logo">
<nav>
<a href="/">Home</a>
<a href="/courses">Courses</a>
<a href="/blog">Blog</a>
</nav>
</header>
<!-- Main page content -->
<main>
<!-- Self-contained blog post -->
<article>
<header>
<h1>Getting Started with HTML5</h1>
<p>By K2infocom ·
Published <time datetime="2026-06-01">June 1, 2026</time>
</p>
</header>
<!-- Article image with caption -->
<figure>
<img src="html5.webp"
alt="HTML5 logo on a laptop screen">
<figcaption>HTML5 — the foundation of modern web pages</figcaption>
</figure>
<!-- Themed section inside article -->
<section>
<h2>What is HTML?</h2>
<p>HTML stands for <mark>HyperText Markup Language</mark>.</p>
</section>
<section>
<h2>FAQ</h2>
<details>
<summary>Is HTML a programming language?</summary>
<p>No, HTML is a markup language, not a programming language.</p>
</details>
</section>
<footer>
<address>
Written by K2infocom ·
<a href="mailto:hello@k2infocom.com">hello@k2infocom.com</a>
</address>
</footer>
</article>
</main>
<!-- Sidebar with related links -->
<aside>
<h2>Related Tutorials</h2>
<nav>
<a href="/css">CSS Tutorial</a>
<a href="/js">JavaScript Tutorial</a>
</nav>
</aside>
<!-- Site-level footer -->
<footer>
<p>© <time datetime="2026">2026</time> K2infocom, Vadodara</p>
</footer>
</body>
</html>
Try It Yourself
Edit the semantic page below and click Open in Editor to see the structure and styling rendered live in full screen.
<details> and <summary>
elements. Try replacing <article> with <div> and see how the visual result is identical — but the semantic
meaning is completely lost.
Quick Check — Chapter 13
Expand each question to check your understanding before moving on to the multiple choice quiz.
<article> is a self-contained piece of
content that makes sense on its own and could be syndicated or distributed independently — a
blog post, news article, product card, forum reply. A <section> is a thematically related group that
belongs to a larger whole — it cannot stand alone. Think of an article as a chapter in a magazine, and a
section as a subheading within that chapter. An article can contain multiple sections, and sections can
contain multiple articles.
<main> is a landmark element that signals the
dominant, unique content of the page. Screen readers provide a shortcut key for users to jump directly
to <main>, bypassing all navigation and headers. If there were
multiple <main> elements, this shortcut would be ambiguous.
Search engines also use it to identify the primary indexable content. A page with two <main> elements is technically invalid HTML5.
datetime attribute provides a machine-readable
version of the date or time in ISO 8601 format — for example datetime="2026-06-15" or datetime="14:30". The human-readable text sits between the tags as
usual. This allows search engines to precisely understand publication dates and event times — improving
rich result eligibility for events and articles in Google Search. Browsers and calendar apps can also
use it to parse dates programmatically.
<details> is a native browser disclosure widget. The browser
implements the expand/collapse behaviour entirely in its own rendering engine — no JavaScript needed.
<summary> must be the first child — it renders as the
always-visible, clickable header. Everything else inside <details> is hidden by default and toggles on click. Adding the
boolean open attribute on <details> makes it start expanded. You can still listen for the
toggle event in JavaScript if you want to react to open/close.
<article> tells Google the page contains a
standalone, indexable piece of content. <nav> helps it
identify navigation links to follow. <time datetime> enables
accurate article date indexing for news results. <address>
helps with local business indexing. <figure> + <figcaption> improves image search indexing. Structured semantic
HTML pages consistently rank better than equivalent div-soup pages, all other factors being equal.
<div> is the right choice when you need a generic
container purely for CSS layout or JavaScript targeting — with no document meaning attached.
Common valid uses: a flexbox row wrapper, a CSS grid cell, a card border container, a JS modal overlay,
an animation wrapper, or any grouping where no semantic element accurately describes the content's role.
The signal is: if you're adding a class like class="nav" or class="section", that's a hint to use the actual semantic tag. If you're
adding class="flex-row" or class="card-wrapper", a <div>
is exactly right.
datetime attribute on <time> provide?- Semantic HTML gives meaning to structure — improving SEO (search engine understanding), accessibility (screen reader navigation), and code clarity (self-documenting markup).
- Layout elements:
<header>(intro),<nav>(navigation),<main>(primary content — one per page),<aside>(sidebar),<footer>(closing info). - Content elements:
<article>(self-contained — a blog post, product card),<section>(themed group within a larger whole — always needs a heading). <figure>+<figcaption>wrap media with a caption.<time datetime>provides machine-readable dates.<address>wraps contact information.<details>+<summary>creates a native expand/collapse disclosure widget — no JavaScript needed. Addopenattribute to start expanded.<mark>highlights relevant text (yellow background, no semantic importance weight). Use<div>for pure CSS layout containers with no document meaning.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions, and stay updated with new tutorials.