日本語

Lighthouse Heading Order: Fixing Skipped Heading Levels

​​Lighthouse​Accessibility,CSS,HTML,Troubleshooting

When Lighthouse's accessibility audit reports "Heading elements are not in a sequentially-descending order" (the Japanese report shows the same message in Japanese), the page has a heading whose level number is 2 or more higher than the heading before it. For example, an h4 placed right after an h2. Change that heading to one level below the previous heading (in this example, h3), and use CSS to match the font size. The warning goes away and the look stays the same. This warning comes up in blog posts and site templates when heading tags are chosen by font size.

I tested this on a page with an h4 right after an h2. I confirmed that Lighthouse reports the warning, and that it disappears after the fix.

Note

The test environment was Ubuntu 24.04, Node.js 22.23.4, and Lighthouse 13.6.0 (the CLI installed with npm; the axe-core inside it is 4.14.0). The browser was headless Google Chrome for Testing 153. I ran only the accessibility category (--only-categories=accessibility) with the default mobile settings. I built the pages locally and served them from 127.0.0.1. I did not test the Lighthouse panel in Chrome DevTools, PageSpeed Insights, or reading by an actual screen reader.

A page that triggers the warning

The test page lists the headings below. Under "Preparing" (h2), the two headings are h4 because I wanted them to look smaller.

The sample text is in Japanese. In English, the headings mean "Cat Notebook" (h1), "Preparing" (h2), "Food bowl" and "Water bowl" (h4), and "Daily care" (h2) with "Morning routine" (h3).

html
<h1>猫の手帳</h1>
<h2>準備するもの</h2>
<h4>ごはんの皿</h4>
<p>浅めの皿を使います。</p>
<h4>水の器</h4>
<p>毎日取り替えます。</p>
<h2>毎日の世話</h2>
<h3>朝にすること</h3>
<p>ごはんと水を用意します。</p>

The code above shows only the main part (the same applies to the other page examples). I served this page with python3 -m http.server 8000 --bind 127.0.0.1 --directory site and ran Lighthouse like this:

bash
npx lighthouse http://127.0.0.1:8000/bad.html \
  --only-categories=accessibility \
  --output=json --output=html --output-path=./out/bad \
  --chrome-flags="--headless=new --no-sandbox" --quiet

When I opened this warning in the HTML report, "Failing Elements" showed one h4: the Food bowl heading.

Lighthouse report with the "Heading elements are not in a sequentially-descending order" audit open. Failing Elements lists one h4, the Food bowl heading, and the heading is outlined in the scaled-down page screenshot
The report before the fix. One h4 with a skipped level is listed

I used a small Node.js script to pull the score and this audit's result from the JSON report. The lines starting with accessibility score: and so on are labels I added in the script. I left out the Lighthouse version and the score breakdown.

text
accessibility score: 94
heading-order title: Heading elements are not in a sequentially-descending order
heading-order score: 0 (binary)
- body > main > h4 | <h4> | ごはんの皿
   Fix any of the following:
     Heading order invalid
failed accessibility audits: heading-order

There are two h4s, but only the first one (Food bowl) was flagged. The second one (Water bowl) is preceded by another h4, so its level does not skip. Only the place where the level jumps gets flagged.

Which orders get flagged

This check is the heading-order rule in axe-core, which Lighthouse uses internally. In the axe-core 4.14.0 implementation, headings are listed in the order they appear on the page, and each one is compared with the heading before it. The rules are:

  • The first heading on the page passes at any level.
  • If a heading's level number is 2 or more higher than the previous heading's (for example, h2 → h4), it fails.
  • If the level number goes down (for example, h4 → h2), it passes no matter how far it drops.

I checked these rules on another page. It starts with an h3, goes from h4 to h6, and then returns to h2.

html
<h3>お知らせ</h3>
<p>最初の見出しが h3 のページです。</p>
<h4>今週の予定</h4>
<h6>補足</h6>
<p>h4 から h6 へ飛ばしています。</p>
<h2>過去のお知らせ</h2>
<p>h6 から h2 へ戻っています。</p>

Only h6 was flagged. I left out the score breakdown.

text
accessibility score: 94
heading-order title: Heading elements are not in a sequentially-descending order
heading-order score: 0 (binary)
- body > main > h6 | <h6> | 補足
   Fix any of the following:
     Heading order invalid

When I changed h6 to h5, the warning went away and the score became 100. Starting at h3 without an h1, and jumping from h5 back to h2, did not cause a problem for this audit.

axe-core tags this rule with best-practice. It is not a WCAG success criterion violation. It checks a recommended way of writing headings. The "Learn more about heading order" link in the report goes to the heading-order page on Deque University.

Changing it to h3 without changing the look

I changed the skipped h4 (Food bowl) to h3. Water bowl is also under the same h2, so I changed it to h3 too. In my Chrome test, a plain h3 without a class has a font size of 18.72px, which is larger than the 16px of h4. So I added a class to match the h4 size.

html
<h1>猫の手帳</h1>
<h2>準備するもの</h2>
<h3 class="small-heading">ごはんの皿</h3>
<p>浅めの皿を使います。</p>
<h3 class="small-heading">水の器</h3>
<p>毎日取り替えます。</p>
<h2>毎日の世話</h2>
<h3>朝にすること</h3>
<p>ごはんと水を用意します。</p>
css
.small-heading { font-size: 1rem; margin-block: 1.33em; }

The values 1rem and 1.33em match the default font size and vertical margin that Chrome gave h4 in my test environment. When I compared the computed styles, the h4 before the fix and the h3 after the fix were identical.

text
bad.html: H4 font-size=16px font-weight=700 margin=21.28px/21.28px
good.html: H3 font-size=16px font-weight=700 margin=21.28px/21.28px

I took screenshots of both pages at the same width, and the image files were byte-for-byte identical. If your site's CSS applies custom styles to h4, apply the same styles to the new class.

When I ran Lighthouse again under the same conditions, the warning was gone and the score was 100. I left out the score breakdown.

text
accessibility score: 100
heading-order title: Heading elements appear in a sequentially-descending order
heading-order score: 1 (binary)
failed accessibility audits: (none)

I also exported the heading levels with Playwright's ariaSnapshot(). After the fix, the levels go down one step at a time: h1 → h2 → h3. I left out the paragraph lines.

text
--- good.html
- main:
  - heading "猫の手帳" [level=1]
  - heading "準備するもの" [level=2]
  - heading "ごはんの皿" [level=3]
  - heading "水の器" [level=3]
  - heading "毎日の世話" [level=2]
  - heading "朝にすること" [level=3]

Another option is to make "Food bowl" and "Water bowl" bold paragraphs, such as <p><strong>ごはんの皿</strong></p>, instead of headings. In my test, this also removed the warning and gave a score of 100. However, as the report explains, assistive technologies use the heading order to navigate a page's structure. Decide based on whether that text should be part of the page's structure.

Hidden headings in between do not stop the warning

Putting a display: none h3 between an h2 and an h4 did not remove the warning. On the same page, I also tested a div with role="heading" and aria-level="4".

html
<h1>猫の手帳</h1>
<h2>準備するもの</h2>
<h3 style="display: none">道具</h3>
<h4>ごはんの皿</h4>
<p>display: none の h3 を間に置いています。</p>
<h2>毎日の世話</h2>
<div role="heading" aria-level="4">朝にすること</div>
<p>div に role="heading" と aria-level="4" を付けています。</p>

Lighthouse flagged both places. I left out the "Fix any of the following" lines under each one and the score breakdown.

text
accessibility score: 97
heading-order title: Heading elements are not in a sequentially-descending order
heading-order score: 0 (binary)
- body > main > h4 | <h4> | ごはんの皿
- body > main > div | <div role="heading" aria-level="4"> | 朝にすること

axe-core collects only the headings that screen readers announce and compares their order. A display: none h3 is not counted, so the h4 after the h2 was treated as is. The ariaSnapshot() output also leaves out the hidden h3.

On the other hand, a div with role="heading" uses its aria-level value as its heading level. A heading built from an element other than h1 to h6 is flagged in the same way if its aria-level skips a level.

How the score is affected

In the Lighthouse 13.6.0 configuration, the weight of heading-order is 3. The accessibility score is a weighted average of the audits, and each audit scores 0 if there is at least one violation. So this audit scores 0 whether there is one skipped level or two.

I recalculated the scores from the weights in the JSON reports:

Page Calculation Score
h4 right after h2 51 / 54 94
Fixed with h3 54 / 54 100
Hidden h3 and role="heading" (two flagged places) 116 / 119 97

The page with hidden headings has two flagged places, but its score (97) is higher than 94. That is because the role="heading" and aria-level attributes added ARIA audits to the calculation, which increased the denominator to 119. Don't judge how well a fix worked by the score. Check whether the Failing Elements list in the report is empty.

​Posted by 86