Semantic HTML
Open any website and look at it as a human. You instantly see a header at the top, a menu, the main story, a sidebar, and a footer at the bottom. Your eyes tell you what each part is for.
But a browser, a search engine, or a screen reader has no eyes. It only sees your markup. If every part is just a <div>, they all look the same, and nothing tells the machine what is a menu and what is a story. Semantic HTML fixes that: you choose elements by their meaning, so people and software can understand the page.
This section teaches the elements that give a page its structure, plus three interactive ones (details, summary, and dialog) that give you accordions and pop-ups with no JavaScript.
What You Will Learnβ
In this section, you will be able to:
- Explain what semantic HTML is, and why it matters
- Build page structure with
<header>,<nav>,<main>, and<footer> - Group content with
<section>,<article>, and<aside>, and know which to pick - Mark up contact details with
<address> - Create expandable content with
<details>and<summary> - Open modal and non-modal pop-ups with
<dialog> - Combine everything into a semantic page layout
- Test your structure like a screen reader user would
You should know basic HTML elements, headings, and attributes. If you need a refresher on how pages connect, read Links and Navigation. Forms are covered separately in HTML Forms.
What "Semantic" Meansβ
Semantic means "carrying meaning". A semantic element tells you what its content is, not just how it looks.
| Non-semantic | Semantic |
|---|---|
<div>: "a box", no meaning | <nav>: "navigation links" |
<span>: "some text", no meaning | <address>: "contact details" |
<div class="top"> | <header> |
<div class="menu"> | <nav> |
<div class="story"> | <article> |
<div class="sidebar"> | <aside> |
<div class="bottom"> | <footer> |
<div onclick="..."> | <button> |
Both versions can look identical with CSS. The difference is invisible to the eye, and very visible to everything else.
Div Soup vs Semantic HTMLβ
Compare the same page written two ways:
- Div soup
- Semantic HTML
<div class="top">
<div class="logo">My Site</div>
<div class="menu">
<a href="/">Home</a>
<a href="/about">About</a>
</div>
</div>
<div class="content">
<div class="story">
<div class="title">How to bake bread</div>
<div>Mix flour, water, salt, and yeastβ¦</div>
</div>
<div class="sidebar">Related: sourdough</div>
</div>
<div class="bottom">Β© 2026 My Site</div>
<header>
<p class="logo">My Site</p>
<nav aria-label="Main">
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<article>
<h1>How to bake bread</h1>
<p>Mix flour, water, salt, and yeastβ¦</p>
</article>
<aside>Related: sourdough</aside>
</main>
<footer>Β© 2026 My Site</footer>
The second version is also shorter, clearer to read, and easier to style (you can select nav instead of inventing .menu).
Try It: What a Screen Reader Findsβ
Press the button. A small script scans each page for landmarks, the named regions that screen reader users use to jump around a page, much as you use your eyes to jump to the menu or the main story.
- HTML Code
- Browser Output
<!-- Page A: all divs -->
<div>My Site</div>
<div><a href="/">Home</a> Β· <a href="/about">About</a></div>
<div>
<div>How to bake bread</div>
<div>Mix flour, water, salt, and yeastβ¦</div>
</div>
<div>Related: sourdough</div>
<div>Β© 2026 My Site</div>
<!-- Page B: semantic elements -->
<header>My Site</header>
<nav aria-label="Main"><a href="/">Home</a> Β· <a href="/about">About</a></nav>
<main>
<article>
<h1>How to bake bread</h1>
<p>Mix flour, water, salt, and yeastβ¦</p>
</article>
</main>
<aside>Related: sourdough</aside>
<footer>Β© 2026 My Site</footer>
Page A has no landmarks at all. A screen reader user must listen to the page from top to bottom to find the menu. Page B gives them a list of regions to jump between. That one change is the heart of this section.
Why It Mattersβ
| Benefit | What it means in practice |
|---|---|
| Accessibility | Screen reader users jump between landmarks, skip repeated menus, and understand what each region is. Keyboard users get built-in behaviour from details, dialog, and button |
| Search engines | Crawlers use structure to understand which part of the page is the main content and which is navigation or a footer. (Structure helps them understand your page. It is not a magic ranking switch.) |
| Readable code | <nav> says more than <div class="n1">. Other developers, and your future self, will thank you |
| Easier styling | Select by element name, with fewer invented class names |
| Built-in features | Browser reading modes, translation tools, and assistive technologies rely on structure. details and dialog work with no JavaScript |
| Resilience | A semantic page still makes sense when CSS fails to load, or on a device you did not test |
| Global reach | Clear structure survives translation, voice assistants, and low-bandwidth readers |
The Semantic Elements at a Glanceβ
| Element | Role (what it is announced as) | Use it for | Lesson |
|---|---|---|---|
<header> | banner (page level) | Introduction: site name, logo, intro content | Header |
<nav> | navigation | A block of major navigation links | Nav |
<main> | main | The central content, once per page | Main |
<section> | region (if named) | A themed group of content, with a heading | Section |
<article> | article | A self-contained piece: post, story, product card | Article |
<aside> | complementary | Related but separate content: a sidebar | Aside |
<footer> | contentinfo (page level) | Closing information: copyright, contacts | Footer |
<address> | (none) | Contact details for the page or article | Address |
<details> and <summary> | group | Content the visitor can expand and collapse | Details, Summary |
<dialog> | dialog | Modal and non-modal pop-ups | Dialog |
Try It: The Page Mapβ
Click each region of the wireframe to see which element it should be, and how a screen reader announces it.
- HTML Code
- Browser Output
<body>
<header>β¦</header>
<nav aria-label="Main">β¦</nav>
<main>
<article>β¦</article>
</main>
<aside>β¦</aside>
<footer>β¦</footer>
</body>
<main> is announced as main
The central content of the page, the thing visitors came for. There is exactly one visible main per page.
Which Element Should I Use?β
When you are not sure, ask what the content is:
| The content is... | Use |
|---|---|
| The top of the page or of a section | <header> |
| A set of major links | <nav> |
| The one main thing on the page | <main> |
| A complete piece that could be shared or syndicated on its own | <article> |
| A themed part of a page, with its own heading | <section> |
| Side content, or a tangent | <aside> |
| The closing information | <footer> |
| Contact information | <address> |
| Extra detail the visitor may reveal | <details> with <summary> |
| A pop-up that needs attention | <dialog> |
| Just a hook for styling or scripting, with no meaning | <div> (or <span> inside text) |
div is not evil<div> and <span> are still useful. Use them when no semantic element fits, for example a wrapper for layout. The mistake is using them when a better element exists.
Semantic Elements Do Not Replace Headingsβ
Landmarks (header, main, nav...) mark the regions of a page. Headings (h1 to h6) mark the outline of the content inside them. You need both:
- Landmarks let people jump between regions.
- Headings let people scan topics.
A good page has one <h1>, followed by headings in a logical order, inside the right landmarks. You can see how they work together in Semantic Page Layout.
Your Learning Pathβ
Follow the lessons in order. They go from the big idea, to the page frame, to grouping content, to interactive elements, and finish by putting it all together.
ποΈ Why Semantic HTML
Learn why semantic HTML matters: how browsers turn markup into an accessibility tree, why a real button beats a clickable div, how semantic elements help screen readers, keyboard users, search engines, and teammates, common myths, and a step-by-step refactor from div soup to meaningful markup, with live examples.
ποΈ Header
Learn the HTML header element: introductory content for a page, article, or section, how it becomes a banner landmark only at page level, the difference between header, head, and headings, skip links, sticky headers and keyboard focus, accessible logos, language switchers, and common mistakes, with live examples.
ποΈ Nav
Learn the HTML nav element: marking major navigation blocks as landmarks, building menus with lists, naming several navs with aria-label, showing the current page with aria-current, breadcrumbs and pagination, accessible mobile menu buttons with aria-expanded, which link groups should not use nav, and common mistakes, with live examples.
ποΈ Main
Learn the HTML main element: marking the dominant content of a page, why a page should have only one visible main, what belongs inside and outside it, skip link targets with tabindex, single-page app focus handling, reader modes, layout CSS, and common mistakes, with live examples.
ποΈ Section
Learn the HTML section element: grouping content by theme with a heading, when to use section instead of div, article, or main, naming a section as a region landmark with aria-labelledby, heading levels and why the document outline algorithm does not work, landing page patterns, and common mistakes, with live examples.
ποΈ Article
Learn the HTML article element: marking self-contained content such as blog posts, news stories, comments, and product cards, the stand-alone test for choosing article over section, nesting comments, header and footer inside an article, the time element, clickable cards, user-generated content safety, and common mistakes, with live examples.
ποΈ Aside
Learn the HTML aside element: marking content that is related to the main content but separate from it, such as sidebars, related links, pull quotes, author bios, and advertisements, the remove-it test, the complementary landmark, naming asides, responsive sidebar layouts, safe ads and third-party widgets, and common mistakes, with live examples.
ποΈ Footer
Learn the HTML footer element: closing information for a page, article, or section, how a page-level footer becomes a contentinfo landmark, what belongs in a footer (copyright, legal links, contact, sitemap, social links), the small element, sticky footer layouts, accessibility, privacy and consent links, global legal notes, and common mistakes, with live examples.
ποΈ Address
Learn the HTML address element: marking contact information for a page or an article's author, what it is not for (postal addresses in general), mailto and tel links, line breaks, resetting italic styling, privacy and spam concerns, international phone and address formats, and common mistakes, with live examples.
ποΈ Details
Learn the HTML details element: building expandable and collapsible content with no JavaScript, the open attribute, exclusive accordions with the name attribute, the toggle event, FAQ patterns, styling the marker, accessibility and keyboard behaviour, printing and find-in-page notes, what not to hide, and common mistakes, with live examples.
ποΈ Summary
Learn the HTML summary element: the visible label and toggle control of a details widget, writing clear summary text, what content is allowed inside it, styling or replacing the marker, keyboard and screen reader behaviour, why headings and links inside a summary cause trouble, stable labels, and common mistakes, with live examples.
ποΈ Dialog
Learn the HTML dialog element: modal and non-modal dialogs, showModal() and close(), forms with method dialog, the returnValue, the backdrop, focus handling, closing with Escape or a click outside, alert dialogs, accessibility, security, and common mistakes, with live examples.
ποΈ Semantic Page Layout
Put it all together: build a complete, accessible HTML page layout with header, nav, main, article, section, aside, and footer, add a skip link, style it with CSS grid, keep the reading order sensible, and check it with a practical checklist, with live examples.
How to Check Your Own Pagesβ
You do not need special software to test structure. Try these:
- Turn off CSS. (In your browser's developer tools, or use a reader mode.) Is the page still in a sensible order?
- Tab through the page with only a keyboard. Does focus follow the visual order?
- Look at the outline. Do the headings read like a table of contents?
- Use a screen reader's landmark list. (VoiceOver on Mac and iPhone, NVDA on Windows, TalkBack on Android.) Is there one
main, onebanner, and sensibly named navigation? - Use your browser's accessibility panel in the developer tools to see the roles the browser assigned.
- Run an HTML validator, and an accessibility checker such as Lighthouse or axe. They find only some problems, so always add the manual checks above.
Common Beginner Mistakesβ
| Mistake | What goes wrong | Where you will fix it |
|---|---|---|
Using <div> for everything | No landmarks, no meaning | Why Semantic HTML |
| Using headings for size, not structure | Broken outline for screen readers | Semantic Page Layout |
More than one <main> | Confusing landmarks | Main |
Putting everything in <section> | A section with no heading adds nothing | Section |
Confusing <section> and <article> | Wrong structure | Article |
Using <nav> for every link group | Too many landmarks to jump between | Nav |
Using <aside> just to get a box on the side | Wrong meaning | Aside |
Making a <div> act like a button | No keyboard support | Details, Dialog |
Using <address> for any postal address | It is for contact details of the page or article | Address |
| Using semantic elements only for their default look | Meaning matters, not appearance | Why Semantic HTML |
Semantic HTML for a Global Audienceβ
- Set
langon the<html>element, so screen readers use the right voice, and translation tools know the source language. - Set
dir="rtl"for right-to-left languages such as Arabic and Hebrew. Semantic structure mirrors cleanly, because the order in the HTML is the order people read. - Name your landmarks in the page's language. If you have more than one
nav, give each anaria-labelsuch as "Main" or "Footer", and translate it. - Keep reading order logical in the HTML itself, not only in CSS. People using translation tools, voice assistants, and reader modes get the source order.
- Write short, plain headings and labels that translate well.
- Remember low-bandwidth readers. A semantic page works with little or no CSS and JavaScript, which matters on slow or old devices.
A Note on Security and Privacyβ
Semantic elements describe structure, and they do not protect anything.
<details>and<dialog>hide content visually, but not from the page. Anything inside is still in the HTML that anyone can read. Never put secrets in a collapsed section or a closed dialog.<address>is public. Put only contact details you want public. Publishing a personal email or phone number invites spam and worse.- Escape user content you place inside any of these elements, as you would anywhere else.
Quick Recapβ
Test yourself. Click a question to reveal the answer.
1. What does "semantic" mean in HTML?
It means the element's name carries meaning about its content (a <nav> is navigation, an <article> is a self-contained piece), rather than just how it looks.
2. Why can a page full of <div>s be a problem?
A <div> has no meaning, so browsers, search engines, and screen readers cannot tell a menu from a story from a footer. Screen reader users cannot jump between regions.
3. Which elements form the basic frame of a page?
<header>, <nav>, <main>, and <footer>, with <aside> for related side content.
4. When is <div> still the right choice?
When no semantic element fits, for example a wrapper for layout or a styling hook. The mistake is using it when a better element exists.
5. Do semantic elements replace headings?
No. Landmarks mark the regions of a page, and headings mark the topic outline inside them. A good page uses both.
6. Do <details> and <dialog> keep their content secret?
No. They only hide it visually. The content is still in the page source, so never put secrets in them.
Key Takeawaysβ
- Semantic HTML means choosing elements for their meaning, so people and software understand your page.
<header>,<nav>,<main>,<footer>, and<aside>create landmarks that screen reader users jump between.<section>groups content by theme (with a heading), and<article>marks a self-contained piece.<address>,<details>,<summary>, and<dialog>give you contact markup, accordions, and pop-ups with built-in behaviour.- Use
<div>and<span>only when nothing semantic fits. - Landmarks and headings work together: regions plus outline.
- Test with CSS off, a keyboard, and a screen reader's landmark list.
- Semantic structure helps accessibility, search engines, maintenance, and a global audience, but it is not security.
Ready to begin? Start with Why Semantic HTML.