Skip to content

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.

15 min read0/4 questions

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:

HTML & CSS
<style> header, nav, main, article, footer { border: 2px dashed #999; padding: 8px; margin: 6px 0; } header::before, nav::before, main::before, article::before, footer::before { display: block; font: bold 11px monospace; color: #c2410c; text-transform: uppercase; } header::before { content: "header"; } nav::before { content: "nav"; } main::before { content: "main"; } article::before { content: "article"; } footer::before { content: "footer"; }</style> <header> <p>Crumbs</p> <nav aria-label="Main"> <a href="#">Home</a> | <a href="#">Recipes</a> </nav></header><main> <article> <h1>The Perfect Scone</h1> <p>Posted <time datetime="2026-03-12">12 March 2026</time></p> <p>Cold butter is the secret to a good rise.</p> </article></main><footer> <p>Copyright 2026 Crumbs</p></footer>

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

ElementUse it forNotes
headerIntroductory content: logo, site title, sometimes the navCan also be used inside an article for its title and date
navA major block of navigation linksMain menu, table of contents. Not every group of links
mainThe main content of the page, unique to this pageOnly one visible main per page, not inside header or footer
articleSelf-contained content that makes sense on its ownA blog post, a news story, a product card, a comment
sectionA themed group of content, usually with its own headingChapters of a long page, "Ingredients" and "Method"
asideContent related to, but separate from, the main flowA sidebar, a "related recipes" box, a pull-out tip
footerClosing content: copyright, contact, related linksAlso works at the end of an article (author, tags)

A few smaller elements add meaning to bits of text:

  • time marks a date or time. Its datetime attribute holds a machine-readable version, like 2026-03-12 or 2026-03-12T18:00, while the visible text can be in any friendly format: <time datetime="2026-03-12">12 March</time>.
  • address marks contact information for the nearest article or 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 the pairs0/5 matched

Match each piece of a news site to its element.

Choose an item, then its match on the other side.

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.

A blog post page
bodynavheadersite headerheaderpost title, datesectionIngredientssectionMethodfooterauthor, tagsarticleasiderelated recipesmainfootersite footerroot

Here it is as code you can play with:

HTML & CSS
<style> body { max-width: 640px; } aside { border-left: 4px solid #e0b25c; padding-left: 12px; } article > footer { color: #555; font-size: 14px; }</style> <header> <strong>Crumbs</strong> <nav aria-label="Main"><a href="#">Home</a> | <a href="#">Recipes</a></nav></header> <main> <article> <header> <h1>The Perfect Scone</h1> <p>Posted <time datetime="2026-03-12">12 March 2026</time></p> </header> <section> <h2>Ingredients</h2> <ul><li>Flour</li><li>Cold butter</li><li>Milk</li></ul> </section> <section> <h2>Method</h2> <ol><li>Rub the butter into the flour.</li><li>Add milk, bake.</li></ol> </section> <footer> <address>Written by <a href="mailto:sam@example.com">Sam</a></address> </footer> </article> <aside> <h2>Try next</h2> <p><a href="#">Cheese scones</a></p> </aside></main> <footer><p>Copyright 2026 Crumbs</p></footer>

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.

Quick check
Which of these is a mistake?
Need a nudge? A hint rules out a wrong answer.

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.

Quick check
Two pages look identical in the browser. One uses header, nav, main and footer; the other uses only divs with the same class names. Who notices the difference?
Need a nudge? A hint rules out a wrong answer.

Common mistakes

  • Using section as a styling wrapper. If a block has no heading and no theme of its own, it is a div.
  • Wrapping every group of links in nav. Keep nav for major navigation, like the main menu or a table of contents. A few links in a footer can sit in the footer on their own.
  • Picking aside for 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 in main.
  • Forgetting the headings. Landmarks help people jump to an area; headings tell them what each area contains. Most section and article elements should start with one.
  • Using address for any address. It is only for contact details about the author or owner of the page or article.
Put it in order5 steps

Put this typical page structure in order from top to bottom.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.
Key terms
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.