HTML Semantic Elements

Introduction:
In the lesson HTML – Layouts we split a page into a header, a menu, the content and a footer. A lot of older websites build those parts with nothing but <div> tags, like this:
<div class="header">...</div>
<div class="nav">...</div>
<div class="main">...</div>
<div class="footer">...</div>
This works, and the page can look perfect. But a <div> means nothing. It is just a box. The class names help you, but the browser, a screen reader or Google cannot understand them.
Semantic elements fix this. A semantic element is a tag whose name tells what its content is. <nav> holds navigation links. <article> holds a complete article. <footer> holds footer content. In this lesson you will learn each of these elements, when to use them, and why they matter.
What Does “Semantic” Mean?
“Semantic” means “related to meaning”. Compare these two tags:
<div>and<span>are non-semantic. They say nothing about their content.<nav>,<article>,<time>and<figure>are semantic. Their name describes their content.
You already know some semantic tags from earlier lessons: <h1> to <h6> mean headings, <p> means a paragraph, <ul> means a list, and <strong> means important text. HTML5 added many more tags to describe the bigger parts of a page.
Why Use Semantic Elements?
1. Accessibility:
People who are blind use screen readers, which read the page out loud. Screen readers let the user jump straight to the main content or to the menu, but only if the page tells them where those parts are. Semantic elements do exactly that.
2. SEO:
Search engines read your HTML to understand the page. A clear <main> and <article> help them find the real content and ignore the menu and footer.
3. Cleaner code:
<nav> is easier to read than <div class="nav-wrapper-outer">. When you open the file six months later, you understand the structure at a glance.
A Complete Semantic Page:
Here is a small blog page built only with semantic elements. We will go through each part below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Learn Web Basics</title>
</head>
<body>
<header>
<a href="/">Learn Web Basics</a>
<nav aria-label="Main">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/articles">Articles</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
</header>
<main>
<article>
<header>
<h1>How the Browser Loads a Page</h1>
<p>By Aisha · <time datetime="2026-12-03">3 December 2026</time></p>
</header>
<section>
<h2>Step 1: The HTML</h2>
<p>The browser downloads the HTML and builds the DOM.</p>
<figure>
<img src="dom-tree.png" alt="A tree of nested HTML elements">
<figcaption>The DOM is a tree of nodes.</figcaption>
</figure>
</section>
<section>
<h2>Step 2: The CSS</h2>
<p>Next it reads the CSS and builds the CSSOM.</p>
</section>
<footer>
<p>Tags: <a href="/tags/html">HTML</a>, <a href="/tags/browser">Browser</a></p>
</footer>
</article>
<aside aria-label="Related">
<h2>Related articles</h2>
<ul>
<li><a href="/articles/css-basics">CSS Basics</a></li>
</ul>
</aside>
</main>
<footer>
<p>© 2026 Learn Web Basics</p>
</footer>
</body>
</html>
The Semantic Elements One by One:
1. The header element:
<header> holds the introduction of the page or of a section: usually a logo, a site name, a search box or the main menu.
A page can have more than one <header>. In our example, the page has a header at the top, and the article has its own header with the title and the date. Only the top one counts as the site banner. A header inside an <article> is just the article’s header.
2. The nav element:
<nav> holds a block of main navigation links, like the top menu, a table of contents or pagination.
Do not wrap every group of links in <nav>. The few links in a footer, or the tag links at the end of a post, do not need it. Use it for the menus a visitor would use to move around the site.
If a page has two menus, give each one a name with aria-label (for example "Main" and "Footer"), so a screen reader user can tell them apart.
3. The main element:
<main> holds the main content of the page, the part that is unique to this page. The menu, the logo and the copyright line repeat on every page, so they stay outside.
There should be only one visible <main> on a page, and it should not be inside <header>, <footer>, <nav>, <aside> or <article>.
4. The article element:
<article> holds content that makes sense on its own. Ask yourself: “Could I copy this into another website or an RSS feed and still understand it?” If yes, it is an article.
Good examples are a blog post, a news story, a product card, a forum post or a user comment. An article can even contain other articles, like a blog post with comments inside it.
5. The section element:
<section> groups content about one topic, usually with its own heading. In our example the article has a section for each step.
A simple test: if the part would appear as a heading in a table of contents, it can be a section. If you only need a box for styling, use a <div> instead. Without a heading, a section adds no real meaning.
6. The aside element:
<aside> holds content that is related, but not essential: a sidebar, related links, an ad, a “Did you know?” box or an author bio. If you removed it, the main content would still make complete sense.
7. The footer element:
<footer> holds the closing information of the page or of a section: copyright, contact links, privacy policy, or, inside an article, the author and the tags.
Like the header, only the footer of the page (not one inside an article or section) counts as the page’s content info area.
8. The figure and figcaption elements:
<figure> wraps an image, a chart, a code sample or a diagram that is referenced from the main text. <figcaption> adds a caption to it:
<figure>
<img src="dom-tree.png" alt="A tree of nested HTML elements">
<figcaption>The DOM is a tree of nodes.</figcaption>
</figure>
The alt text describes the image for people who cannot see it. The caption is visible to everyone. You need both.
9. The time element:
<time> marks a date or a time. People read the text, and the datetime attribute gives computers the exact value in a standard format:
<time datetime="2026-12-03">3 December 2026</time>
<time datetime="18:30">6:30 PM</time>
<time datetime="2026-12-03T18:30+05:30">3 Dec, 6:30 PM IST</time>
10. A few smaller semantic tags:
<mark>highlights text, like a search match:Use <mark>semantic</mark> tags.<address>holds contact information for the author or the page owner.<details>and<summary>create a box that opens and closes without any JavaScript:
<details>
<summary>What is the DOM?</summary>
<p>The DOM is the tree of elements the browser builds from your HTML.</p>
</details>
Seeing the Difference:
Browsers turn semantic elements into landmarks in the accessibility tree. This tree is what screen readers use. We loaded both versions of the page in Chromium and printed the tree with Playwright. Here is the semantic version (shortened):
- banner:
- link "Learn Web Basics"
- navigation "Main":
- list: Home, Articles, About
- main:
- article:
- heading "How the Browser Loads a Page" [level=1]
- time: 3 December 2026
- heading "Step 1: The HTML" [level=2]
- figure "The DOM is a tree of nodes."
- heading "Step 2: The CSS" [level=2]
- complementary "Related":
- heading "Related articles" [level=2]
- contentinfo:
- paragraph: © 2026 Learn Web Basics
And here is the version built only with <div> tags:
- text: Learn Web Basics
- link "Home"
- link "Articles"
- text: How the Browser Loads a Page The browser downloads the HTML and builds the DOM. © 2026 Learn Web Basics
The div version is one flat line of text. There is no menu, no main area and no headings for a screen reader to jump to. In the semantic version, <header> became banner, <nav> became navigation, <aside> became complementary and <footer> became contentinfo.
Look closely and you will notice two details we explained above:
- The
<header>and<footer>inside the article did not become a banner or contentinfo. Only the page-level ones did. - The
<section>elements did not become landmarks, because they have no name. Their headings still give the structure.
Converting a Div Layout:
If you have an old page full of divs, the change is simple. Replace each div with the tag that matches its job:
<!-- Before -->
<div class="header">
<div class="logo">Learn Web Basics</div>
<div class="nav">...</div>
</div>
<div class="main">
<div class="post">...</div>
</div>
<div class="footer">...</div>
<!-- After -->
<header>
<a href="/">Learn Web Basics</a>
<nav aria-label="Main">...</nav>
</header>
<main>
<article>...</article>
</main>
<footer>...</footer>
You can keep your class names if your CSS uses them. Semantic tags have almost no default styles (they display as blocks, like a div), so the page will look the same.
If the old file is messy and badly indented, run it through a formatter first, like the Eskillsfy HTML Beautifier. With clean nesting it is much easier to see which div is the header and which is the menu.
Common Mistakes to Avoid:
1. Replacing every div:
Semantic tags are not “better divs”. When you only need a wrapper for styling or layout, a <div> is the right choice.
2. Choosing a tag for its look:
Pick tags by meaning, not by how they look. Never use <h3> just because you want smaller text. Use the correct heading level and change the size with CSS.
3. Skipping heading levels:
Go from <h1> to <h2> to <h3> in order. Screen reader users often move through a page by its headings, so a clear order matters.
4. More than one main:
Keep one <main> per page. It tells everyone where the real content begins.
5. Using section without a heading:
If a section has no heading, it is probably just a <div>.
Conclusion:
Semantic elements describe what each part of the page is. <header>, <nav>, <main>, <article>, <section>, <aside> and <footer> give your page a clear structure, and smaller tags like <figure>, <time> and <details> add meaning to the content inside it.
The page looks the same, but screen readers can jump straight to the menu or the content, search engines understand your page better, and your code is easier to read. Use a semantic tag when one fits the job, and use a <div> only when you just need a box.
In the next HTML lesson, we will build HTML Forms and Input Validation.


