Semantic elements help organize web pages clearly. Screen readers use them to read content correctly to people who cannot see the screen.
Semantic elements and screen readers in HTML
<header>...</header> <nav>...</nav> <main>...</main> <section>...</section> <article>...</article> <footer>...</footer>
Use semantic tags to describe the role of each part of your page.
Screen readers recognize these tags and help users understand the page layout.
<header> tag defines the top section of the page, usually with a title or logo.<header> <h1>My Website</h1> </header>
<nav> tag groups navigation links so screen readers can jump to them easily.<nav> <ul> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> </ul> </nav>
<main> tag holds the main content, and <article> is for independent content pieces.<main> <article> <h2>Article Title</h2> <p>Article content goes here.</p> </article> </main>
<footer> tag defines the bottom section with copyright or contact info.<footer> <p>Ā© 2024 My Website</p> </footer>
This page uses semantic elements to organize content clearly. The aria-label on <nav> helps screen readers identify the navigation area.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Semantic Elements Example</title> </head> <body> <header> <h1>Welcome to My Site</h1> </header> <nav aria-label="Main navigation"> <ul> <li><a href="#home">Home</a></li> <li><a href="#services">Services</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav> <main> <section id="home"> <h2>Home</h2> <p>This is the home section with important info.</p> </section> <section id="services"> <h2>Services</h2> <article> <h3>Web Design</h3> <p>We create beautiful websites.</p> </article> <article> <h3>SEO</h3> <p>Improve your site ranking on search engines.</p> </article> </section> </main> <footer> <p>Contact us at info@example.com</p> </footer> </body> </html>
Always add lang attribute on <html> for screen readers to know the language.
Use aria-label or aria-labelledby to give extra descriptions to regions if needed.
Semantic elements improve keyboard navigation and help search engines understand your page.
Semantic elements give meaning to parts of your webpage.
Screen readers use these elements to read content in a helpful order.
Using semantic tags makes your website easier to use for everyone.
Practice
Solution
Step 1: Understand the purpose of semantic elements
Semantic elements describe the role of content, helping screen readers know what is important.Step 2: Identify the element for main content
The<main>element specifically marks the main content unique to the page, guiding screen readers effectively.Final Answer:
<main> -> Option AQuick Check:
Main content uses <main> tag for screen readers [OK]
- Using <div> which has no semantic meaning
- Confusing <section> with main content
- Using <span> which is inline and non-semantic
Solution
Step 1: Recall the semantic tag for navigation
The<nav>element is the standard semantic tag for navigation menus.Step 2: Check syntax correctness
<nav> ... </nav>is valid HTML5 syntax recognized by screen readers.Final Answer:
<nav> ... </nav> -> Option AQuick Check:
Navigation uses <nav> tag [OK]
- Using non-existent <navigation> tag
- Confusing <menu> with <nav> (menu is different)
- Using <section> without role attribute
<header> <h1>Welcome</h1> </header> <main> <p>Hello world!</p> </main>
Solution
Step 1: Understand screen reader reading order
Screen readers read semantic elements in document order, starting with header content.Step 2: Identify first readable text
The<header>contains an<h1>with "Welcome", so it reads this first.Final Answer:
"Welcome" from the header's h1 -> Option DQuick Check:
Header content is read before main content [OK]
- Assuming main content reads first
- Thinking header is skipped
- Believing screen reader reads all at once
<div role='main'> <h2>Content</h2> </div>
Solution
Step 1: Check semantic correctness
Whilerole='main'can be used, the semantic<main>element is preferred for accessibility.Step 2: Understand best practice for screen readers
Using<main>provides built-in semantic meaning and better support than adivwith role.Final Answer:
Usingrole='main'on adivinstead of<main>-> Option BQuick Check:
Use <main> tag, not div with role [OK]
- Thinking role='main' on div is equal to <main>
- Ignoring heading level importance
- Adding tabindex unnecessarily
Solution
Step 1: Identify semantic element for complementary content
The<aside>element is designed for complementary content like sidebars.Step 2: Check ARIA attribute necessity
<aside>already implies complementary role, so extra ARIA roles are unnecessary and may confuse screen readers.Final Answer:
<aside> without extra ARIA attributes -> Option CQuick Check:
Use <aside> for complementary content [OK]
- Adding redundant ARIA roles to <aside>
- Using <section> or <div> without semantic meaning
- Confusing <nav> with sidebar role
Ready to prove it?
Pass the test and this pattern moves unknown
