HTML Semantics

Beginner
12 min read
Updated: Nov 2026
6 examples
<header> … <footer>

Definition and Usage

HTML semantics is the practice of choosing elements that describe the meaning of each part of a document. Instead of nesting anonymous <div> boxes for every region, you mark the site banner, navigation, primary content, related sidebars, and page footer with purpose-built tags.

What is a semantic page layout?

A typical document outline uses <header> for introductory branding, <nav> for major links, a single <main> for the unique page content, optional <article> / <section> / <aside> groups inside that content, and <footer> for closing information. The visual look still comes from CSS—the tags communicate structure.

Why does semantics matter?

Screen readers and other assistive tools expose landmarks so people can jump to navigation, main content, or the footer. Search engines and browser features also gain clearer signals about what belongs where. Teammates reading your source understand the page faster than a wall of generic containers.

When should you use semantic layout tags?

Use them whenever a region has a clear role on the page. Reach for <div> only when you need a hook for layout or styling and no more specific element fits. Prefer a heading inside each <section> so the outline stays clear.

Meaning first, style second.

Semantic tags do not replace CSS grids or flexbox. They name the regions; CSS positions and paints them.

One <main> per page.

Keep a single visible main landmark. Nesting main inside header, nav, article, aside, or footer is invalid.

Landmarks help keyboard and AT users.

Native semantic regions create most landmarks automatically. You rarely need a custom role when the right HTML element already exists.

HTML Semantics Syntax

A minimal landmark-friendly body structure:

layout.html
<header> … banner / intro </header>
<nav> … site links </nav>
<main> … unique page content </main>
<footer> … closing info </footer>
HTML
<body>
  <header>
    <h1>Site name</h1>
    <nav aria-label="Primary">
      <a href="/">Home</a>
      <a href="/about">About</a>
    </nav>
  </header>

  <main>
    <article>
      <h2>Article title</h2>
      <section>
        <h3>Section heading</h3>
        <p>Section content…</p>
      </section>
    </article>
    <aside>
      <h2>Related</h2>
      <p>Complementary notes.</p>
    </aside>
  </main>

  <footer>
    <p>&copy; 2026 Example Site</p>
  </footer>
</body>

Nesting is flexible: <nav> often lives inside <header>, and <aside> can sit beside or after the main story. Choose tags for meaning; arrange them with CSS.

Core HTML Concepts

Elements you will use most often when structuring documents:

ElementMeaning
<header>Introductory content for a page or a section (logo, title, local nav)
<nav>Major navigation block—primary menus, table of contents, breadcrumbs
<main>Dominant unique content of the document (one visible main)
<article>Self-contained composition that could stand alone (post, card, comment)
<section>Thematic grouping, usually with a heading, inside a larger page or article
<aside>Content tangentially related to the surrounding material (tips, related links)
<footer>Closing information for a page or section (copyright, contacts, meta links)
<div>Generic container with no semantics—use for styling or script hooks only

Semantic vs non-semantic containers

Semantic (e.g. <main>)Non-semantic (<div>)
MeaningDescribes role in the documentNone by itself
LandmarksOften creates an AT landmarkOnly if you add ARIA roles
Best forPage regions and content groupsLayout wrappers, CSS grids, JS targets

How to Structure a Semantic Page

A practical order that keeps meaning and accessibility aligned.

  1. Sketch the regions first: banner, nav, main story, optional sidebar, footer.
  2. Wrap the unique page content in one <main>.
  3. Put site-wide links in <nav>; give multiple navs distinct aria-label values.
  4. Use <article> for standalone pieces and <section> for headed themes.
  5. Place tangents in <aside>—not every side column needs that tag.
  6. Reserve <div> for anonymous layout boxes after the semantic outline is set.
GoalPattern
Site chrome<header> + nested <nav>
Primary contentSingle <main> wrapping the unique body
Blog post / news story<article> with heading and optional sections
Themed block<section> with a heading
Related tips / widgets<aside> complementary to the main story
CSS grid / flex wrapper<div class="…"> around semantic children

Live Preview

Switch layout patterns and compare how semantic regions appear versus a div-only shell.

Rendered sample with labels for each region. Div-only layouts look similar but lack native landmarks.

Rendered page
header — Site name
main — Unique page content
footer — © 2026
<header>…</header>
<main>…</main>
<footer>…</footer>

HTML Examples

Six patterns: page skeleton, header with nav, article sections, aside, semantic vs div, and a full layout.

Example 1 — Basic Page Skeleton

HTML
<header>
  <h1>CodeToFun Blog</h1>
</header>
<main>
  <h2>Welcome</h2>
  <p>This is the unique content for this page.</p>
</main>
<footer>
  <p>&copy; 2026 CodeToFun</p>
</footer>
Try It Yourself

How It Works

  1. header introduces the page with the site title.
  2. main holds content that is unique to this document.
  3. footer closes with copyright or contact notes.
  4. Use for every multi-region page before adding CSS.

Example 2 — Header with Navigation

HTML
<header>
  <h1>Travel Tips</h1>
  <nav aria-label="Primary">
    <a href="/">Home</a>
    <a href="/guides">Guides</a>
    <a href="/contact">Contact</a>
  </nav>
</header>
<main>
  <h2>Packing light</h2>
  <p>Choose versatile layers and a small daypack.</p>
</main>
Try It Yourself

How It Works

  1. nav marks major site links as a navigation landmark.
  2. aria-label names the landmark when a page has more than one nav.
  3. header groups branding and primary links together.
  4. Not every link list needs nav—reserve it for primary menus.

Example 3 — Article with Sections

HTML
<main>
  <article>
    <h2>Why semantic HTML helps</h2>
    <section>
      <h3>Accessibility</h3>
      <p>Landmarks let assistive tech jump between regions.</p>
    </section>
    <section>
      <h3>Maintainability</h3>
      <p>Named regions make large templates easier to scan.</p>
    </section>
  </article>
</main>
Try It Yourself

How It Works

  1. article wraps a self-contained story or essay.
  2. section splits themes under their own headings.
  3. Heading levels follow the outline (h2 then h3 here).
  4. Prefer section over anonymous divs for thematic groups.

Example 4 — Aside for Related Content

HTML
<main>
  <article>
    <h2>Garden checklist</h2>
    <p>Water early, mulch beds, and watch for pests.</p>
  </article>
  <aside>
    <h2>Related tip</h2>
    <p>Keep a rain gauge near the vegetable plot.</p>
  </aside>
</main>
Try It Yourself

How It Works

  1. aside marks content that complements the main story.
  2. It is not required for every visual sidebar column.
  3. Place it inside or after the related article as meaning dictates.
  4. CSS can still float or grid the aside beside the article.

Example 5 — When to Prefer div

HTML
<!-- Semantic regions stay meaningful -->
<main>
  <!-- div only wraps for layout / CSS -->
  <div class="card-grid">
    <article>
      <h2>Lesson 1</h2>
      <p>Learn headings and paragraphs.</p>
    </article>
    <article>
      <h2>Lesson 2</h2>
      <p>Practice lists and links.</p>
    </article>
  </div>
</main>
Try It Yourself

How It Works

  1. div groups cards for CSS grid without inventing fake meaning.
  2. article still marks each reusable lesson card.
  3. main keeps the landmark for unique page content.
  4. Rule of thumb: semantic first, anonymous wrappers only when needed.

Example 6 — Complete Semantic Layout

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>HTML Semantics Example</title>
</head>
<body>
  <header>
    <h1>City Library</h1>
    <nav aria-label="Primary">
      <a href="/">Home</a>
      <a href="/events">Events</a>
    </nav>
  </header>
  <main>
    <article>
      <h2>Summer reading club</h2>
      <section>
        <h3>Schedule</h3>
        <p>Meet every Thursday at 4 PM.</p>
      </section>
    </article>
    <aside>
      <h2>Hours</h2>
      <p>Mon–Sat 9 AM–6 PM</p>
    </aside>
  </main>
  <footer>
    <p>&copy; 2026 City Library</p>
  </footer>
</body>
</html>
Try It Yourself

How It Works

  1. Full document wires header, nav, main, article, section, aside, and footer.
  2. Landmarks map to assistive technology jump targets.
  3. Headings outline the article and complementary hours block.
  4. Ready for CSS without renaming regions to anonymous divs.

Edge Cases & Pitfalls

Most layout bugs come from overusing divs or misplacing main and landmarks.

main

Multiple main elements

Only one visible main per document. Extra mains confuse landmarks and validators.

divitis

Wrapping everything in div

Anonymous boxes hide structure. Prefer semantic tags, then add div wrappers only for CSS.

nav

nav for every link list

Use nav for primary navigation. Footer social links or a single skip link usually do not need it.

section

Headless sections

A section should almost always include a heading. Without one, prefer a plain div.

aside

Aside ≠ any sidebar

Use aside for complementary content. A decorative layout column with primary content is not an aside.

aria

Redundant ARIA roles

Do not add role="main" on <main> or similar duplicates. Native elements already expose the landmark.

Browser Support

Semantic layout elements (header, nav, main, article, section, aside, footer) are part of HTML and work in all modern browsers.

✓ Baseline · Widely available

HTML semantics

Every current browser understands semantic sectioning and landmark elements for document structure.

100% layout elements
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
Semantic HTML Universal

Bottom line: Use header, nav, main, article, section, aside, and footer freely—pair them with CSS for visual layout.

Key Takeaways

  • Semantic tags name page regions so tools and people understand the layout.
  • One main wraps the unique content; header, nav, and footer frame the chrome.
  • article / section / aside organize stories, themes, and complementary notes.
  • div is for layout hooks when no semantic element fits—not a default wrapper.

One line: Build the outline with header, nav, main, article, section, aside, and footer, then add div only where styling needs a nameless box.

Frequently Asked Questions

Semantic HTML means choosing elements that describe meaning and role—not just appearance. Tags such as header, nav, main, article, section, aside, and footer tell browsers, assistive tech, and search tools what each region of the page is for.
Use article for a self-contained piece that could stand alone or be syndicated (a blog post, news story, or comment). Use section to group related content under a shared theme within a larger page—usually with a heading.
Use div when you need a generic box for layout or styling and no semantic element fits. Prefer header, main, nav, and similar tags when the region has a clear meaning. Avoid wrapping everything in divs by default.
One visible main per document. It marks the primary content unique to that page. Do not put main inside article, aside, header, footer, or nav.
Landmarks are named regions (banner, navigation, main, complementary, contentinfo, and others) that assistive technologies expose so users can jump by page area. Semantic layout tags create most of these landmarks automatically.
No. They can also wrap introductory or closing content inside article, section, or aside. The page-level banner and contentinfo landmarks usually come from header/footer that are not nested inside those sectioning elements.

Practice in the editor

Open a Try It demo and rearrange semantic page regions.

Open Try It editor →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful