Semantic HTML & Accessibility
Semantic elements describe meaning
Instead of <div> everywhere, use elements that say what the content is:
| Element | Meaning |
|---|---|
<header> | intro or top bar |
<nav> | main navigation links |
<main> | the main content (one per page) |
<section> | a themed group with a heading |
<article> | self-contained content (a post, a card) |
<aside> | side content |
<footer> | bottom info |
Why it matters
- Accessibility: screen-reader users can jump between landmarks.
- SEO: search engines understand your page better.
- Readable code for you and your team.
Accessibility (a11y) checklist
- Meaningful
alttext on images. - A
<label>for every input. - Use real
<button>s for actions and<a>for navigation, so keyboard and screen readers work automatically. - Keep a logical heading order (h1 → h2 → h3).
- Enough colour contrast (at least 4.5:1 for body text).
- Everything usable with the keyboard (Tab, Enter, Space), with a visible focus outline.
- ARIA (
aria-label,role) only when no native HTML element fits. "No ARIA is better than bad ARIA."
💡 Run DevTools → Lighthouse → Accessibility to find problems automatically.
Example
<header>
<h1>Tech Blog</h1>
<nav aria-label="Main">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/posts">Posts</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h2>Learning HTML</h2>
<p>Semantic HTML makes pages easier to use for everyone.</p>
</article>
<aside>
<h2>Related</h2>
<p>Accessibility basics</p>
</aside>
</main>
<footer>
<p>© 2026 Tech Blog</p>
</footer>