HTML5 Semantic Elements Guide

Master modern HTML structure with semantic elements for better accessibility, SEO, and maintainability

Why Use Semantic HTML?

Semantic HTML uses meaningful tags that describe their content, making your code more readable for both humans and machines. Instead of generic <div> elements, semantic tags like <header>, <nav>, and <article> clearly communicate the purpose of each section.

Accessibility

Screen readers and assistive technologies can better understand and navigate your content, improving the experience for users with disabilities.

SEO Benefits

Search engines better understand your content structure, potentially improving your rankings and search result appearance.

Maintainability

Code is easier to read, understand, and maintain when the structure is clear and meaningful, reducing development time.

Future-Proof

Standards-compliant code is more likely to work correctly across different browsers and future web technologies.

Typical Page Structure

<body>
<header>
<h1>Site Title</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
</header>
 
<main>
<>
<h2>Article Title</h2>
<p>Article content...</p>
</>
 
<aside>
<h3>Related Links</h3>
</aside>
</main>
 
<footer>
<p>© 2025 Company Name</p>
</footer>
</body>

Header Element

<header>

Represents introductory content for its nearest ancestor sectioning content or sectioning root element. Typically contains a logo, site title, navigation, or other introductory elements.

Common Uses:

  • Site-wide header with logo and main navigation
  • Article or section header with title and metadata
  • Introduction to a page or section
Example:
<header>
  <img src="logo.png" alt="Company Logo">
  <h1>My Awesome Website</h1>
  <nav>
    <ul>
      <li><a href="/">Home</a></li>
      <li><a href="/about">About</a></li>
      <li><a href="/contact">Contact</a></li>
    </ul>
  </nav>
</header>

Navigation Element

<nav>

Represents a section of navigation links. Not all links need to be in a <nav> element—only major navigation blocks should use this tag.

Common Uses:

  • Primary site navigation menu
  • Table of contents for a long article
  • Breadcrumb navigation
  • Pagination controls
Example:

Main Element

<main>

Represents the dominant content of the document body. There should only be one <main> element per page, and it should not be a descendant of <article>, <aside>, <footer>, <header>, or <nav>.

Common Uses:

  • Main content area of a web page
  • Content that is unique to the page (excludes navigation, footers, etc.)
  • Wrapper for the primary purpose of the page
Example:
<main>
  <h1>Welcome to Our Blog</h1>
  
  <article>
    <h2>Latest Post Title</h2>
    <p>Post content goes here...</p>
  </article>
  
  <article>
    <h2>Another Post Title</h2>
    <p>More interesting content...</p>
  </article>
</main>

Article Element

<article>

Represents a self-contained composition that could be independently distributed or reused. Examples include blog posts, news articles, user comments, or interactive widgets.

Common Uses:

  • Blog post or news article
  • Forum post or user comment
  • Product card in a listing
  • Social media post
Example:
<article>
  <header>
    <h2>Understanding HTML5 Semantic Elements</h2>
    <p>Published on <time datetime="2025-12-18">December 18, 2025</time></p>
    <p>By <span>Austin Nammack</span></p>
  </header>
  
  <p>Semantic HTML is crucial for modern web development...</p>
  
  <footer>
    <p>Tags: HTML5, Web Development, Best Practices</p>
  </footer>
</article>

Section Element

<section>

Represents a thematic grouping of content, typically with a heading. Use <section> when the content has a clear theme or purpose, and use <div> for purely stylistic groupings.

Common Uses:

  • Chapters or subsections of content
  • Grouped content with a specific theme
  • Tabbed content panels
  • Product features sections
Example:
<article>
  <h1>Complete Guide to CSS Grid</h1>
  
  <section>
    <h2>Introduction</h2>
    <p>CSS Grid is a powerful layout system...</p>
  </section>
  
  <section>
    <h2>Basic Concepts</h2>
    <p>Understanding grid containers and items...</p>
  </section>
  
  <section>
    <h2>Advanced Techniques</h2>
    <p>Complex grid layouts and responsive design...</p>
  </section>
</article>

Aside Element

<aside>

Represents content that is tangentially related to the main content. This could be sidebars, callout boxes, or supplementary information that enhances but isn't essential to the main content.

Common Uses:

  • Sidebar with related links or content
  • Pull quotes or callout boxes
  • Advertising or promotional content
  • Author bio or related articles
Example:
<article>
  <h1>The Benefits of Semantic HTML</h1>
  <p>Main article content goes here...</p>
  
  <aside>
    <h3>Related Articles</h3>
    <ul>
      <li><a href="/css-best-practices">CSS Best Practices</a></li>
      <li><a href="/accessibility-guide">Web Accessibility Guide</a></li>
      <li><a href="/seo-tips">SEO Tips for Developers</a></li>
    </ul>
  </aside>
</article>

Footer Element

<footer>

Represents footer content for its nearest ancestor sectioning content or sectioning root. Typically contains information about the author, copyright, links to related documents, or contact information.

Common Uses:

  • Site-wide footer with copyright and links
  • Article footer with metadata or tags
  • Contact information and social media links
  • Legal information and privacy policies
Example:

Before & After Comparison

Non-Semantic (Bad)

<div class="header">
  <h1>My Website</h1>
  <div class="nav">
    <a href="/">Home</a>
    <a href="/about">About</a>
  </div>
</div>

<div class="content">
  <div class="post">
    <h2>Post Title</h2>
    <p>Content...</p>
  </div>
</div>

<div class="footer">
  <p>© 2025</p>
</div>

Semantic (Good)

<header>
  <h1>My Website</h1>
  <nav>
    <a href="/">Home</a>
    <a href="/about">About</a>
  </nav>
</header>

<main>
  <article>
    <h2>Post Title</h2>
    <p>Content...</p>
  </article>
</main>

<footer>
  <p>© 2025</p>
</footer>

Best Practices

Use One Main Element Per Page

Each page should have exactly one <main> element containing the primary content unique to that page. Don't include repeated content like navigation or footers inside <main>.

Don't Overuse Section Elements

Only use <section> when the content has a clear theme and typically a heading. For purely stylistic groupings without semantic meaning, use <div> instead.

Use ARIA Labels for Multiple Nav Elements

If you have multiple <nav> elements on a page (e.g., main navigation and footer navigation), use aria-label to differentiate them for screen reader users.

Nest Headings Logically

Maintain a logical heading hierarchy (h1 → h2 → h3) within semantic elements. Don't skip levels or use headings solely for styling purposes.

Combine with ARIA When Needed

While semantic HTML provides inherent accessibility, you can enhance it further with ARIA attributes like role, aria-label, and aria-labelledby when appropriate.

Think About Syndication

Use <article> for content that makes sense when taken out of context, like blog posts or products. If it wouldn't make sense on its own, it's probably not an article.