Why semantic HTML matters
We always want to prefer native implementations over custom ones if we can help it. Semantic HTML is the foundation of web accessibility.Semantic HTML provides meaning and structure to your content, making it understandable for both humans and assistive technologies.
Benefits of semantic HTML
- Better accessibility - Screen readers and other assistive technologies rely on semantic HTML to understand page structure
- Improved SEO - Search engines better understand your content hierarchy and meaning
- Easier maintenance - Code is more readable and self-documenting
- Built-in functionality - Native elements come with keyboard support, focus management, and expected behaviors
- Better performance - Native elements are optimized by browsers
- Reduced code - Less JavaScript and ARIA needed when using proper HTML
Landmark elements
We always want to make sure we are using proper landmark elements where applicable. Landmark elements define the major sections of your page and help users understand and navigate the overall structure.Common landmark elements
<header>
<header>
Contains introductory content, typically including navigation, logos, and site-level actions.Implicit ARIA role:
banner (when not nested in <article> or <section>)<nav>
<nav>
<main>
<main>
Contains the primary content of the page. There should be only one ARIA role:
<main> element per page.mainThe
<main> element should not be nested inside <article>, <aside>, <footer>, <header>, or <nav>.<section>
<section>
Represents a standalone section of content that would make sense in a document outline.ARIA role:
region (when labeled with aria-labelledby or aria-label)<article>
<article>
Represents a self-contained piece of content that could be independently distributed or reused.ARIA role:
articleGood use cases: blog posts, news articles, forum posts, product cards<aside>
<aside>
Contains content tangentially related to the main content, like sidebars or callouts.ARIA role:
complementary<footer>
<footer>
Example from the course
Take a look at the HTML structure of the Web A11y for Devs introduction page:Notice the usage of landmark elements:
<header>, <nav>, <main>, <section>, and <footer>. This structure helps screen reader users navigate efficiently.Heading hierarchy
Proper heading structure is essential for accessibility and SEO.The rules
Start with h1
Every page should have exactly one
<h1> element that describes the main content of the page.Use headings for structure, not styling
Choose heading levels based on content hierarchy, not appearance. Use CSS for styling.
Example heading structure
List structures
Lists provide structure and improve navigation for screen reader users.When to use lists
Use semantic list elements for:- Navigation menus
- Sets of related items
- Sequential instructions
- Table of contents
- Tag collections
- File listings
List types
- Unordered lists
- Ordered lists
- Description lists
Use
<ul> for lists where the order doesn’t matter:Semantic elements vs generic divs
Knowing when to use semantic elements versus generic<div> or <span> tags is crucial.
When to use semantic elements
Use semantic elements when the content has inherent meaning or structure:
- Buttons -
<button>instead of<div onclick="..."> - Links -
<a href="...">instead of<span onclick="..."> - Navigation -
<nav>instead of<div class="nav"> - Main content -
<main>instead of<div id="main"> - Articles -
<article>instead of<div class="article"> - Forms -
<form>,<input>,<label>,<fieldset>instead of custom elements - Tables -
<table>,<thead>,<tbody>,<th>,<td>for tabular data
When divs and spans are okay
<div> and <span> are appropriate for styling and layout purposes when no semantic element fits:Native buttons vs custom buttons
A native button gives us all necessary and accessible features - out of the box:Native button benefits
- Proper semantic role: “button”
- Keyboard controls (Enter & Space keys)
- Clean focus management
- Form integration
- Disabled state support
Custom div problems
- No semantic role
- No keyboard support
- No focus by default
- Requires extensive ARIA
- More code to maintain
The right way: native button
The wrong way: div button
Exercise: Fix broken landmarks
The Web A11y for Devs course includes a practice page with intentional landmark errors.Homework exercise
Navigate to the
/broken-landmarks page and identify all landmark element related issues.Common issues to look for:- Generic divs used instead of semantic elements
- Missing or incorrect landmark elements
- Improper nesting of landmarks
- Multiple main elements
- Missing heading structure
Example from broken-landmarks.html
The broken landmarks page intentionally uses divs instead of proper semantic elements:ARIA: When semantic HTML isn’t enough
Sometimes semantic HTML alone isn’t sufficient. ARIA (Accessible Rich Internet Applications) fills the gaps.First rule of ARIA: Don’t use ARIA. Use native HTML whenever possible. ARIA should be a last resort.
When to use ARIA
- Custom widgets - Complex interactive components not available in HTML (tree views, advanced tabs)
- Dynamic content - Announcing live updates (
aria-live) - Enhanced descriptions - Adding context beyond what HTML provides
- States and properties - Communicating dynamic state changes
When NOT to use ARIA
Don’t use ARIA when a native HTML element exists:Best practices checklist
Semantic HTML checklist
- Use exactly one
<h1>per page - Follow sequential heading order (h1 → h2 → h3)
- Use
<header>,<nav>,<main>,<footer>for page structure - Wrap sections in
<section>with descriptive headings - Use
<button>for actions,<a>for navigation - Structure lists with
<ul>,<ol>, or<dl> - Label sections with
aria-labelledbyoraria-label - Include skip links for keyboard navigation
- Use
<article>for self-contained content - Avoid divs when semantic elements exist
- Test with screen readers to verify structure
- Validate HTML to catch errors
Developer tools for testing
Browser DevTools
Browser DevTools
- Chrome DevTools Accessibility panel
- Firefox Accessibility Inspector
- Edge DevTools Accessibility panel
Screen readers
Screen readers
Navigate your page with a screen reader to verify:
- Landmarks are announced correctly
- Heading structure makes sense
- Interactive elements are identifiable
Document outline tools
Document outline tools
Browser extensions that show your heading structure:
- HeadingsMap
- HTML5 Outliner
Validation tools
Validation tools
- W3C HTML Validator
- axe DevTools
- WAVE browser extension
Common mistakes to avoid
- Using headings for styling - Don’t choose
<h3>because you want smaller text; use CSS - Skipping heading levels - Always follow sequential order
- Multiple h1 elements - Use only one
<h1>per page (outside of<article>elements) - Divs everywhere - Replace generic divs with semantic elements where appropriate
- Missing main element - Every page needs exactly one
<main> - Improper nesting - Don’t nest
<main>inside<article>or other landmarks - Empty landmarks - Don’t use landmark elements with no content
- Too many landmarks - Not every div needs to be a section; use landmarks for major page regions