html 236 lines · 2 tabs

Semantic HTML5 elements and accessibility best practices

Alex Chang Feb 2026
2 tabs
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Semantic HTML Example</title>
</head>
<body>
  <!-- Header with site navigation -->
  <header>
    <nav aria-label="Main navigation">
      <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About</a></li>
        <li><a href="/blog">Blog</a></li>
        <li><a href="/contact">Contact</a></li>
      </ul>
    </nav>
  </header>

  <!-- Main content area -->
  <main>
    <!-- Article with proper heading hierarchy -->
    <article>
      <header>
        <h1>Understanding Semantic HTML</h1>
        <p>Published on <time datetime="2026-02-04">February 4, 2026</time></p>
        <p>By <a href="/author/alex">Alex Chen</a></p>
      </header>

      <section>
        <h2>What is Semantic HTML?</h2>
        <p>Semantic HTML uses elements that clearly describe their meaning
        to both the browser and the developer.</p>

        <!-- Figure with caption -->
        <figure>
          <img src="semantic-html.jpg" alt="Diagram showing semantic HTML structure">
          <figcaption>Semantic HTML element hierarchy</figcaption>
        </figure>
      </section>

      <section>
        <h2>Benefits of Semantic Markup</h2>
        <ul>
          <li><strong>Accessibility:</strong> Screen readers understand content structure</li>
          <li><strong>SEO:</strong> Search engines better index your content</li>
          <li><strong>Maintainability:</strong> Code is easier to read and update</li>
        </ul>
      </section>

      <aside>
        <h3>Related Articles</h3>
        <ul>
          <li><a href="/aria-guide">ARIA Roles Guide</a></li>
          <li><a href="/accessibility">Web Accessibility 101</a></li>
        </ul>
      </aside>
    </article>

    <!-- Another section with different content -->
    <section>
      <h2>Latest Blog Posts</h2>
      <article>
        <h3><a href="/post-1">CSS Grid Layout</a></h3>
        <p>Learn modern CSS Grid techniques...</p>
      </article>
      <article>
        <h3><a href="/post-2">JavaScript Async/Await</a></h3>
        <p>Master asynchronous JavaScript...</p>
      </article>
    </section>
  </main>

  <!-- Aside for supplementary content -->
  <aside aria-label="Sidebar">
    <section>
      <h2>Newsletter Signup</h2>
      <form>
        <label for="email">Email:</label>
        <input type="email" id="email" name="email" required>
        <button type="submit">Subscribe</button>
      </form>
    </section>
  </aside>

  <!-- Footer with site information -->
  <footer>
    <nav aria-label="Footer navigation">
      <ul>
        <li><a href="/privacy">Privacy Policy</a></li>
        <li><a href="/terms">Terms of Service</a></li>
      </ul>
    </nav>
    <p>&copy; 2026 Frontend Dev. All rights reserved.</p>
  </footer>
</body>
</html>
2 files · html Explain with highlit

Semantic HTML uses meaningful elements like <header>, <nav>, <main>, <article>, and <footer> instead of generic <div> tags. I structure content with proper heading hierarchy (<h1> to <h6>). Semantic markup improves SEO by helping search engines understand content structure. Screen readers navigate better with semantic elements and ARIA attributes. The <section> element groups related content, while <article> represents self-contained composition. Using <button> for actions and <a> for navigation ensures proper keyboard interaction. The alt attribute on images provides text alternatives. Proper semantic HTML creates accessible, maintainable websites that work for everyone.


Related snips

Share this code

Here's the card — post it anywhere.

Semantic HTML5 elements and accessibility best practices — share card
Link copied