Sub topic 10
Headings for screen reader users
This chapter assumes you can write basic HTML, know what the h1 to h6 tags are, and have read the earlier chapters on the heading hierarchy and the h1. Here you will see how headings work for people who use screen readers, and why the same structure that helps search also helps them.
How screen reader users use headings
A screen reader is software that reads a page aloud or sends it to a braille display. Most people who use one do not listen to a page from top to bottom. They move between headings with a key press, much as a sighted reader scans for bold section titles.
Screen readers can also list every heading on a page, with its level, in one menu. This works like a table of contents that the browser builds from your markup. Surveys of screen reader users, such as the WebAIM screen reader survey, regularly find that headings are one of the most common ways people look for information on a page.
This means your headings are navigation as well as styling. If the outline is broken, these users lose their main way to find a section.
What the screen reader announces
A screen reader announces the text and the level of each heading, for example "heading level 2, When to repot". It uses the tag, not the font size. A div styled to look like a heading is announced as plain text and does not appear in the heading list.
| Markup | What a sighted user sees | What a screen reader user gets |
|---|---|---|
| `<h2>When to repot</h2>` | A large section title | "Heading level 2, When to repot", listed in the heading menu |
| `<div class="big-bold">When to repot</div>` | A large section title | Plain text, not in the heading menu |
| `<h4>More</h4>` after an `h2` | A small title | "Heading level 4, More", with no level 3 before it and no clue what follows |
Rules that serve both readers and search
The rules below match the advice from earlier chapters. Following them once covers search engines and assistive technology together.
- Use real heading tags for real headings. Do not fake them with bold text or large fonts.
- Use one
h1that names the page's main topic. - Do not skip levels. An
h2should be followed by anh3, not anh4. - Do not pick a tag for its size. Choose the level that fits the outline, then change the size with CSS.
- Write headings that make sense alone. Someone jumping from heading to heading hears nothing else.
Rule 5 matters most for the weak headings from the earlier "before" example. A heading such as "More" tells a screen reader user nothing when it is read out of context. "Aftercare for a repotted snake plant" tells them what the section holds.
<!-- Weak: skipped level, vague headings, a fake heading -->
<h1>Snake Plant</h1>
<h4>More</h4>
<div class="section-title">Tips</div>
<!-- Better: logical levels, descriptive text, real heading tags -->
<h1>How to Repot a Snake Plant</h1>
<h2>Aftercare</h2>
<h3>Watering after repotting</h3>
<h2>Common repotting mistakes</h2>Headings and landmarks
A heading outline is not the only structure a screen reader uses. HTML elements such as nav, main and footer create landmarks, which are regions users can jump between. Headings organise the content inside those regions. You do not need to give every landmark a heading, but a nav with several links may benefit from a short visible or hidden heading such as "Site menu" if the page has more than one navigation region.
Check your headings with a screen reader view
You can test the outline without a screen reader. This script, run in the browser console, prints every heading with its level indented, so you can spot skipped levels.
const headings = document.querySelectorAll("h1, h2, h3, h4, h5, h6");
let previous = 0;
headings.forEach((heading) => {
const level = Number(heading.tagName[1]);
const warning = level > previous + 1 ? " <-- skipped level" : "";
console.log(" ".repeat((level - 1) * 2) + heading.tagName + ": " + heading.textContent.trim() + warning);
previous = level;
});For a fuller check, try a real screen reader such as NVDA on Windows, VoiceOver on macOS, or TalkBack on Android. Open its heading list and read it without looking at the page. If the list reads like a sensible outline of the topic, the structure works.
Common errors
- Choosing
h3orh4for a smaller look. Fix the size in CSS instead. - Using several
h1elements to mark every section. Use oneh1andh2for the main sections. - Writing headings such as "Click here" or "More" that carry no meaning alone.
- Leaving empty heading tags in templates. Screen readers announce them as blank headings.
- Hiding the only heading text with
display: none. Screen readers skip it. Use a visually hidden CSS class if a heading must be read but not shown.
Exercise
A page has an h1, then an h2 titled "Setup", then an h4 titled "Details" chosen because it looks smaller. Name two problems this causes for a screen reader user, and give the fix.
Show answer
The h4 skips level 3, so the outline suggests a missing section, and "Details" gives no meaning when read from the heading list alone. Change the tag to h3, since it sits under the h2, and make it smaller with CSS. Rename it to something specific, such as "Required tools for setup".
Exercise
A heading is made with <div class="title">Watering</div>. Why does it not help a screen reader user, and how do you fix it?
Show answer
A div is not a heading element, so the screen reader treats it as plain text and leaves it out of the heading list. Replace it with a heading tag at the right level, such as <h2>Watering</h2>, and keep the look with the existing CSS class.