Skip to content

Semantic HTML

Semantic HTML uses elements that convey meaning about the content they contain, improving accessibility, SEO, and code maintainability.

<div class="header">
<div class="logo">Site Name</div>
<div class="navigation">
<div class="nav-item"><a href="/">Home</a></div>
<div class="nav-item"><a href="/about">About</a></div>
</div>
</div>
<div class="main-content">
<div class="article">
<div class="article-header">
<div class="title">Article Title</div>
<div class="date">January 1, 2025</div>
</div>
<div class="article-body">
<p>Article content...</p>
</div>
</div>
<div class="sidebar">
<div class="widget">Related Links</div>
</div>
</div>
<div class="footer">
<div class="copyright">© 2025</div>
</div>

Problems:

  • Screen readers cannot identify page regions
  • Search engines cannot determine content hierarchy
  • Class names are the only indication of purpose
  • Requires ARIA roles to be accessible
<header>
<h1>Site Name</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
</header>
<main>
<article>
<header>
<h2>Article Title</h2>
<time datetime="2025-01-01">January 1, 2025</time>
</header>
<p>Article content...</p>
</article>
<aside>
<h3>Related Links</h3>
</aside>
</main>
<footer>
<p>© 2025</p>
</footer>

Benefits:

  • Screen readers announce page regions automatically
  • Search engines understand content structure
  • Self-documenting code
  • Built-in landmark roles
ElementPurposeImplicit ARIA Role
<header>Introductory content, navigationbanner (when top-level)
<nav>Navigation linksnavigation
<main>Main content of the pagemain
<article>Self-contained contentarticle
<section>Thematic grouping with headingregion (when labeled)
<aside>Tangentially related contentcomplementary
<footer>Footer for nearest sectioning contentcontentinfo (when top-level)
<figure>Self-contained media with captionfigure
<figcaption>Caption for a figureNone
<time>Machine-readable date/timeNone
<address>Contact informationNone
<mark>Highlighted/referenced textNone

Supported in all modern browsers including IE9+.

  • Screen readers use semantic elements to create a page outline
  • Users can jump between landmarks using keyboard shortcuts
  • <main> should only appear once per page
  • Nest headings properly (h1h2h3)
  • Use <section> with a heading; otherwise use <div>

Use semantic elements when:

  • The element matches the content’s purpose
  • You want automatic accessibility benefits
  • Building page structure and landmarks

Use <div> when:

  • Grouping for styling purposes only
  • No semantic meaning applies
  • Creating layout containers