2 / 6 · Intermediate
Heading structure and landmarks
A common way to read a page with a screen reader is to jump from heading to heading, so a page with no h2 elements reads like a book with no chapters.
Jump to the 9 practice questionsYou will learn
- Use real h1 to h6 elements so headings can be listed and jumped to
- Build an outline without skipped levels
- Mark page regions with landmark elements
Before this: Alternative text for images
1Explore
Skimming by headings
Sighted readers skim. They glance at the big bold lines, find the section they want and start reading there. Screen reader users do the same thing with headings. MDN notes that a common technique is to jump quickly from heading to heading to work out what a page contains, and that most screen readers can list every heading on the page.
"Bread" looks like a heading but is a div, so the screen reader reads it as plain text. "Opening hours" is a real h2.
<style>
.title { font-size: 1.5em; font-weight: bold; }
</style>
<h1>Corner Bakery</h1>
<div class="title">Bread</div>
<p>Sourdough, rye and white loaves.</p>
<h2>Opening hours</h2>
<p>Every day from 7 am.</p>2Problem
A big bold div
A div with large bold text is read by a screen reader as
Hint
Look at how "Bread" is announced above.
Solution
Answer: ordinary text
Only h1 to h6 (or the heading role) are announced as headings.
3Explain
What WCAG asks
WCAG 2.2 covers this in success criterion 1.3.1 Info and Relationships, at level A: structure that is shown visually must also be available in the code. Criterion 2.4.6 Headings and Labels, at level AA, adds that headings must describe the topic of their section. A heading such as "More" or "Section 2" may not explain its topic. A clearer heading names the subject, such as "Opening hours".
4Problem
Headings that describe
Which criterion asks that headings describe their topic?
Hint
The criterion has "Headings" in its name.
Solution
Answer: 2.4.6 Headings and Labels
Criterion 2.4.6, level AA, requires headings to describe their topic. Correct heading tags alone do not help someone choose a section if the words are vague.
5Problem
"Section 2"
Is a heading "Section 2" a good heading?
Hint
Does it say what the section is about?
Solution
Answer: No, it does not say what the section is about
In this example, “Section 2” alone gives no clue to the topic. A more descriptive heading helps users find the section; context can affect the assessment.
6Explain
Three rules for levels
First, do not skip levels. Go from h1 to h2 to h3. Someone who hears an h4 straight after the h1 is left wondering where the missing levels went. Second, prefer a single h1 per page that names its content, much like the title element. The HTML standard allows more than one, but MDN describes one h1 as the usual best practice. Third, do not choose a heading level for its size. If an h3 looks too small, change the font size in CSS and keep the level that matches the structure.
One h1 names the page. Each h2 starts a section, and each h3 sits inside the h2 above it.
7Problem
After an h1
Which comes right after an h1 in a well-built outline?
Hint
Do not skip a level.
Solution
Answer: h2
Do not skip levels: h1, then h2.
8Problem
An h3 that looks small
An h3 looks too small for the design. What should you do?
Hint
Size is a CSS job.
Solution
Answer: Keep h3 and change font-size in CSS
Levels follow structure; size is a CSS job.
9Problem
A recipe outline
Put these headings in outline order for a recipe page.
- h2 Method
- h3 Shaping the loaf
- h1 Rye bread
- h2 Ingredients
Hint
One h1, then sections, with the sub-step inside its section.
Solution
Answer:
- h1 Rye bread
- h2 Ingredients
- h2 Method
- h3 Shaping the loaf
One h1, then sections, with the sub-step inside Method.
10Explore
Landmarks
Headings divide the content; landmarks divide the page into regions. The elements header, nav, main and footer each carry a built-in role. A screen reader can therefore offer a list of regions and jump straight to the main content or the navigation. A page normally has one main. You get these roles for free by choosing the right element, which is the first rule of ARIA in action: no extra attributes needed.
header, nav, main and footer are announced as regions a listener can jump between.
<header>
<nav>
<a href="/">Home</a> <a href="/menu">Menu</a>
</nav>
</header>
<main>
<h1>Corner Bakery</h1>
<h2>Bread</h2>
<h3>Sourdough</h3>
</main>
<footer>12 Mill Lane</footer>11Problem
What landmarks are for
What do landmark elements let screen reader users do?
Hint
Look at the region lines in the list above.
Solution
Answer: Jump straight to regions such as the main content
Regions such as main and nav appear in a list the user can jump to.
12Problem
How many main?
How many main elements does a page normally have?
Hint
The single main content area.
Solution
Answer: One
main marks the single main content area.
13Problem
The navigation element
Hint
Three letters.
Solution
Answer: nav
The nav element carries the navigation landmark role.
14Practice
Real headings
The two section titles are divs styled to look like headings. Turn them into real h2 elements.
- h1 kept
- two h2 headings
- no fake headings left
<style>
.title { font-size: 1.5em; font-weight: bold; margin: 1em 0 .3em; }
</style>
<h1>Corner Bakery</h1>
<div class="title">Bread</div>
<p>Sourdough, rye and white loaves.</p>
<div class="title">Opening hours</div>
<p>Every day from 7 am.</p>Hint
Both divs become h2.
A solution
<style>
.title { font-size: 1.5em; font-weight: bold; margin: 1em 0 .3em; }
</style>
<h1>Corner Bakery</h1>
<h2>Bread</h2>
<p>Sourdough, rye and white loaves.</p>
<h2>Opening hours</h2>
<p>Every day from 7 am.</p>15Practice
Fix the levels
The levels jump from h1 to h4. Make Bread and Cakes h2, and Birthday cakes an h3 inside Cakes.
- two h2 headings
- Birthday cakes is h3
- no h4 or h5 left
<h1>Corner Bakery</h1>
<h4>Bread</h4>
<p>Baked before 7 am.</p>
<h4>Cakes</h4>
<p>Order a day ahead.</p>
<h5>Birthday cakes</h5>
<p>Any size, any name.</p>Hint
h4 becomes h2, and h5 becomes h3.
A solution
<h1>Corner Bakery</h1>
<h2>Bread</h2>
<p>Baked before 7 am.</p>
<h2>Cakes</h2>
<p>Order a day ahead.</p>
<h3>Birthday cakes</h3>
<p>Any size, any name.</p>16Practice
nav and main
Wrap the three links in a nav and the heading and paragraph in a main.
- three links inside nav
- h1 inside main
<a href="/">Home</a>
<a href="/menu">Menu</a>
<a href="/contact">Contact</a>
<h1>Corner Bakery</h1>
<p>Fresh bread every morning.</p>Hint
Two wrappers: nav around the links, main around the heading and text.
A solution
<nav>
<a href="/">Home</a>
<a href="/menu">Menu</a>
<a href="/contact">Contact</a>
</nav>
<main>
<h1>Corner Bakery</h1>
<p>Fresh bread every morning.</p>
</main>17Explain
Common mistakes
<h1>Corner Bakery</h1>
<h4>Opening hours</h4>
<p>Every day from 7 am.</p><style>
h2 { font-size: 1em; }
</style>
<h1>Corner Bakery</h1>
<h2>Opening hours</h2>
<p>Every day from 7 am.</p>h4 was picked for its small size, which skips two levels. Use h2 and make it small with CSS.
18
Summary
- Screen reader users move through a page by its headings.
- Use real h1 to h6, one h1, and no skipped levels.
- Headings describe their section (WCAG 2.4.6).
- header, nav, main and footer give regions for free.