Lesson 5 of 52HTML
Semantic HTML
Replace div soup with header, nav, main, article, section, aside and footer, and learn why meaningful structure helps people, search engines and you.
You can build an entire page out of div elements, and it will look fine once it is styled. But to a screen reader, a search engine, or the developer who opens your code next year, a page of plain divs says nothing about what anything is. Semantic HTML means choosing elements for their meaning: this is the navigation, this is the main content, this is a self-contained article. It costs nothing extra to write, and it makes your pages easier to use, easier to find and easier to maintain. This lesson rounds off the HTML basics by giving your pages a proper structure.
Div soup
Here is the top of a blog page written the way many beginners (and plenty of professionals) write it. Every box is a div with a class name describing what it is:
<div class="header">
<div class="logo">Crumbs</div>
<div class="menu">
<div><a href="/">Home</a></div>
<div><a href="/recipes">Recipes</a></div>
</div>
</div>
<div class="content">
<div class="post">
<div class="post-title">The Perfect Scone</div>
<div class="date">12 March 2026</div>
<div class="text">Cold butter is the secret...</div>
</div>
</div>
<div class="footer">Copyright 2026 Crumbs</div>This is called div soup. The class names help a human reading the code a little, but the browser does not read class names for meaning. To assistive technology, this is a pile of unlabelled boxes with some text inside. Even post-title is not a heading, so it will not appear in a screen reader's list of headings.
The semantic version
Now the same content with elements that describe their job:
Preview
The dashed labels come from the CSS at the top, so you can see each element's box. Try deleting the <main> and </main> lines: the content itself does not change at all, only the dashed debug box drawn by our CSS disappears. That is the point. Semantic elements change what the page means, not how it looks. Then change the article to a div (both the opening and closing tag) and notice its label disappears, just as its meaning would for a screen reader.
The structural elements
| Element | Use it for | Notes |
|---|---|---|
header | Introductory content: logo, site title, sometimes the nav | Can also be used inside an article for its title and date |
nav | A major block of navigation links | Main menu, table of contents. Not every group of links |
main | The main content of the page, unique to this page | Only one visible main per page, not inside header or footer |
article | Self-contained content that makes sense on its own | A blog post, a news story, a product card, a comment |
section | A themed group of content, usually with its own heading | Chapters of a long page, "Ingredients" and "Method" |
aside | Content related to, but separate from, the main flow | A sidebar, a "related recipes" box, a pull-out tip |
footer | Closing content: copyright, contact, related links | Also works at the end of an article (author, tags) |
A few smaller elements add meaning to bits of text:
timemarks a date or time. Itsdatetimeattribute holds a machine-readable version, like2026-03-12or2026-03-12T18:00, while the visible text can be in any friendly format:<time datetime="2026-03-12">12 March</time>.addressmarks contact information for the nearestarticleor for the whole page: an author's email, a company's phone number, a shop's address. It is not for every postal address that appears in a text (an address in a story is just a paragraph).
article or section?
This is the question everyone asks. Try the syndication test: if you could lift the content out and publish it somewhere else (an RSS feed, another site) and it would still make complete sense, it is an article. A blog post passes; its "Ingredients" part does not, so that is a section inside the article.
And if no meaning fits, use a div. It is still the right tool for wrappers that exist only for styling or layout, like a box you need to centre the content. Semantic HTML is not "never use div". It is "do not use div when a meaningful element exists".
Match each piece of a news site to its element.
A full page structure
Put together, a typical blog post page forms this tree. Notice that header and footer appear twice: once for the whole site, and once inside the article for the post's own title and author details.
Here it is as code you can play with:
Preview
Try adding a third section called "Serving" with its own h2. Then change the date in datetime and the visible text to today. Notice how the address shows in italics by default: browsers give a few semantic elements small default styles, which CSS can override.
Why semantics matter
Accessibility
Screen readers turn semantic elements into landmarks: named regions people can jump between. With one key press, a screen reader user can skip straight to the main content, or list every heading, or find the navigation. On a page of divs there are no landmarks, so the only option is to listen through everything from the top, on every page. Some elements also bring free behaviour: a real button can be reached with the Tab key and pressed with Enter or Space, while a clickable div cannot without extra work. When a page has several nav elements, the aria-label attribute you saw above gives each one a name ("Main", "Footer") so they can be told apart. You will learn more in Accessibility Basics.
Search engines
Search engines read your HTML too. Clear headings, a distinct main area and well-marked article content help them work out what the page is about and which parts are the actual content rather than menus and footers. Semantics will not make a weak page rank well on its own, but it removes guesswork.
Maintainability
Open a file six months later and <nav> tells you at once what you are looking at, while <div class="wrapper-2"> does not. Semantic elements also give CSS meaningful hooks, like article header or nav a, so you need fewer made-up class names.
header, nav, main and footer; the other uses only divs with the same class names. Who notices the difference?Common mistakes
- Using
sectionas a styling wrapper. If a block has no heading and no theme of its own, it is adiv. - Wrapping every group of links in
nav. Keepnavfor major navigation, like the main menu or a table of contents. A few links in a footer can sit in thefooteron their own. - Picking
asidefor anything in a sidebar. It is for content that is related but separate. If the "sidebar" holds the page's main filters or form, it may belong inmain. - Forgetting the headings. Landmarks help people jump to an area; headings tell them what each area contains. Most
sectionandarticleelements should start with one. - Using
addressfor any address. It is only for contact details about the author or owner of the page or article.
Put this typical page structure in order from top to bottom.
- Tap the steps below in the right order.
- semantic HTML
- Choosing elements for what content means, such as nav or article, rather than for how it looks.
- div soup
- A page built almost entirely from meaningless div elements, which hides its structure from software.
- landmark
- A region like header, nav, main or footer that screen reader users can jump between.
- article
- Self-contained content that would make sense on its own, such as a blog post or product card.
- section
- A themed part of a page or article, usually with its own heading.
- aside
- Content related to the main flow but separate from it, like a sidebar.
- time
- An element for dates and times, with a machine-readable datetime attribute.