Semantic HTML & Document Structure

Beginner · 14 min

Why naming your elements by meaning instead of by appearance makes pages easier to find, maintain, and use with assistive tech.

Before thisHow Browsers Render a Page

Net Ninja · 14 min

Semantic HTML & Document Structure

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Net NinjaReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Semantic HTML means choosing elements for what their content is, not for how it happens to look.
  • A page built entirely from <div> and <span> — 'div soup' — still renders fine, but it throws away information the browser, search engines, and assistive tech all depend on.
  • Elements like <header>, <nav>, <main>, <article>, <section>, <aside>, and <footer> describe the document's outline the same way headings describe an essay's outline.
  • Search engines weight text inside <article>, <h1>, and similar elements more heavily than text in a generic <div>, because semantic tags are a signal of what actually matters on the page.
  • Screen readers build a navigable landmark map from semantic elements, letting a blind user jump straight to the nav or the main content instead of tabbing through everything in order.

The problem semantics solves

Open the dev tools on almost any page built a few years ago by someone in a hurry, and you’ll find the same pattern: a <div class="header">, a <div class="nav">, a <div class="main-content">, a <div class="footer">. Every one of these is just a <div> wearing a class name like a costume. The browser doesn’t know any of them is special — to the rendering engine, they’re identical, interchangeable boxes that happen to have different CSS rules attached.

This works, in the narrow sense that the page looks right. But it throws away information. A class name is a note to the developer — it means nothing to a search engine crawler, nothing to a screen reader, nothing to a browser extension that wants to summarize the page, and nothing to the next developer six months from now trying to figure out which <div> is the actual content. The meaning of the page exists only in the author’s head and in a CSS stylesheet that could be deleted without the HTML complaining.

Semantic HTML fixes this by giving you elements that describe what something is, not just how it should look. A <nav> is navigation whether or not it has any CSS at all. An <article> is a self-contained piece of content. This is the same idea as naming a variable userEmail instead of x — the name itself carries meaning that would otherwise live only in a comment nobody reads.

The elements, and what each one claims

HTML5 added a specific set of elements for document structure, each making a claim about the content inside it:

  • <header> — introductory content for the page or a section: a logo, a title, often navigation.
  • <nav> — a block of links meant for navigating the site, not just any list of links.
  • <main> — the one primary piece of content unique to this page. There should be exactly one per page.
  • <article> — a chunk of content that would make sense distributed on its own: a blog post, a forum comment, a product card.
  • <section> — a thematic grouping of content, usually with its own heading, used when nothing more specific fits.
  • <aside> — content tangentially related to the main content, like a sidebar, a callout, or a related-links box.
  • <footer> — closing content for the page or a section: copyright, contact info, site links.

None of these come with default styling that does anything dramatic — <main> looks like a block-level <div> until you style it. The value isn’t visual. It’s that the tag itself now documents the role of its contents, independent of any CSS.

The document outline

Put these elements together and a page acquires a real outline, much like the ones Word or Google Docs infers from your heading levels. A <header> at the top, a <nav> inside it, a <main> holding one or more <article> or <section> blocks, maybe an <aside>, and a <footer> at the bottom. This isn’t decoration — tools genuinely parse this structure. A browser’s reader mode uses it to strip away navigation and ads and show just the <article>. Search engines use it to figure out which part of the page is the actual content worth indexing. Assistive technology uses it to build a map of the page a user can jump around in without reading linearly.

Nesting matters here too. A <section> inside an <article> about, say, a recipe might separate “Ingredients” from “Instructions” — two distinct thematic chunks of the same self-contained piece of content. Each <section> should generally have its own heading, the same way each section of a document outline has a title.

Why this pays off three times over

The case for semantics isn’t abstract correctness — it pays rent in three concrete places. First, SEO: search engines use tag semantics as one signal among many for figuring out page structure and relevance, and an <article> full of real heading hierarchy is easier to rank sensibly than an undifferentiated pile of <div>s. Second, maintainability: six months from now, a developer scanning <header>, <main>, <footer> understands the page’s shape in seconds, versus archaeology through a dozen identically named <div class="container"> elements. Third, and often underweighted, assistive technology: a screen reader builds its landmark navigation list directly from these tags, and a keyboard-only user can jump straight to <nav> or <main> instead of tabbing through the entire page in document order.

None of this requires exotic knowledge — it requires picking the right tag for the job, the same discipline as naming a function for what it does rather than calling everything handleClick. The rest of this group builds directly on that discipline: forms, accessibility, and SEO all assume you’re starting from a page that already has real structure, not a pile of unmarked boxes.

Check yourself

  1. 01What is 'div soup,' and why does it still work in a browser?

    It's a page built almost entirely out of generic <div> and <span> elements with styling classes instead of meaningful tags; it still renders correctly because the browser only needs CSS and layout rules to draw a box on screen, not the box's meaning.

  2. 02What are three semantic elements, and what kind of content is each one meant to hold?

    <nav> holds the site's primary navigation links, <article> holds a self-contained piece of content like a blog post, and <aside> holds content that's related but tangential, like a sidebar or pull quote.

  3. 03Why does a search engine care whether text sits inside a <div> or an <article>?

    A crawler uses tag semantics as a shortcut for figuring out what a page is actually about; text inside a meaningful container like <article> or a heading tag is treated as more likely to be the page's real content than text inside an untyped <div>.

  4. 04How does a screen reader use the landmark elements on a page?

    It compiles them into a jump list — headings, nav, main, footer, and so on — so a user can navigate straight to the section they want instead of listening to the entire page read top to bottom.

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark