Skip to content
Practice & implementation

Headings in Components: Setting Levels Correctly in Code

Headings in components: the level per placement as a parameter, multiple h1 elements, sectioning elements, hidden headings and role=heading under WCAG 2.2.

19 min read ÜberschriftenScreenreaderWCAG 2.2

In short and in plain language

Headings give a page its structure. Many people who use a screen reader jump from heading to heading. That way they quickly find what they need.

Each heading has a level. The level shows what belongs together. Level 2 is followed by level 3, not straight by level 4.

Many parts of a page are used more than once. One example is a card with a picture and text. The card can sit at the top or further down. So the page tells the card which level its heading has.

Bold text is not a heading. The screen reader does not show it in the list of headings. A real heading has to be in the code.

Check the list of headings with a screen reader. A small script in the browser can show the list as well.

A teaser card brings its own heading: an <h3>, because in the first design it sat below an h2. Six months later the same card appears on the home page directly below the h1, in the sidebar without any h2, and inside a tab below an h3. The look is right everywhere, the outline in only one of four places. For screen reader users, that outline is the most common route through a long page: 67.8% (WebAIM Screen Reader User Survey #11) of respondents navigate through the headings first, and 88.3% (WebAIM Screen Reader User Survey #11) find the heading levels very or somewhat useful. The basic rules (one h1, no skipped levels, styling through CSS) are well known. This article covers the part that is decided in code: the level of a component per placement, multiple h1 elements and sectioning elements, visually hidden headings and role="heading" with aria-level.

Key takeaways

  • On lengthy pages, 67.8% of surveyed screen reader users navigate through headings first and 88.3% find heading levels useful; 1780 responses collected in July and August 2026 (WebAIM Screen Reader User Survey #11).
  • The heading level belongs to the placement, not the component: teaser, card and accordion receive it as a parameter with a default and limits from h2 to h6, while the look comes from a separate CSS class.
  • The HTML standard allows each following heading at most one level more (WHATWG, HTML Standard); WCAG lists proper nesting under 1.3.1 only as advisory technique G141, but a bold pseudo heading as failure F2 (W3C, F2).
  • Sectioning elements do not lower a level: the outline algorithm was removed from the HTML standard in 2022 (MDN Blog), nested h1 elements are non-conforming, and 18.1% of the home pages analyzed had more than one h1 (WebAIM Million 2026).
  • The new headingoffset attribute shifts levels per placement, but MDN lists it as experimental; without support the level of the element name applies, so the markup must work without the offset (MDN, headingoffset).
  • Use role=heading only as a fallback and only together with aria-level, hide headings visually only for sections that are visually obvious, and test with a heading list per placement plus a component test (W3C, ARIA12).

Why components shift the outline

On a modern website, headings rarely come from one place. The page template sets the h1, the editorial team adds subheadings to the body text, and every reusable component brings its own heading: the teaser in the grid, the product card, the accordion, the info box in the sidebar, the review block in the footer area. The level that ends up in the document is the sum of these decisions. None of them sees the whole page, and no editor can correct the level of a component in an input field.

The WebAIM Million shows how this adds up across the web. On the home pages analyzed in February 2026 it found 29.9 (WebAIM Million 2026) headings on average. Skipped heading levels occurred at one in every 25 (WebAIM Million 2026) headings, and of the home pages with at least one h6, 94.9% (WebAIM Million 2026) also had skipped heading levels. WebAIM concludes that most of these headings probably do not reflect the actual document structure (WebAIM Million 2026). An h6 is rarely typed into an editor field. A more likely source is a component whose level was chosen by font size and which has claimed the same level at every placement ever since.

Who this matters for is shown by WebAIM's screen reader survey, conducted in July and August 2026 with 1780 (WebAIM Screen Reader User Survey #11) valid responses; of those who stated their region, 27.7% (WebAIM Screen Reader User Survey #11) came from Europe. The sample was not controlled and may not represent all screen reader users (WebAIM Screen Reader User Survey #11). The share of respondents who navigate through headings first on a lengthy page was 71.6% (WebAIM Screen Reader User Survey #11) in 2024 and has decreased slightly, but it remains by far the most common method. Advanced users take this route much more often: 72.1% (WebAIM Screen Reader User Survey #11) of advanced users compared with 41.4% (WebAIM Screen Reader User Survey #11) of beginners. A clean outline helps above all those who depend on it.

The basic rules are already covered in several articles. Why the hierarchy matters for screen readers is explained in the article on screen reader optimization. How to check headings without tools is part of check 5 in the BFSG self-check. How an editorial team chooses levels is covered in the training for editorial teams, how structure also helps search in the article on accessibility and SEO, and how a content management system can prevent skipped levels in the article on authoring tools and ATAG. This article is about the place where no editor can step in: the code of the components.

What WCAG and HTML actually require

Two sets of rules interlock, and they differ in strictness. WCAG 2.2 requires in success criterion 1.3.1 at Level A that information, structure and relationships conveyed through presentation can be programmatically determined or are available in text (W3C, WCAG 2.2). A line that looks like a heading must therefore be marked up as a heading. Success criterion 2.4.6 at Level AA requires that headings and labels describe topic or purpose (W3C, WCAG 2.2). It does not require headings at all (W3C, Understanding 2.4.6). Only 2.4.10 at Level AAA requires section headings to organize the content (W3C, WCAG 2.2).

WCAG does not regulate the order of levels as a criterion of its own. Technique G141 recommends properly nested headings, so an h2 after an h1, and after an h2 another h2 or an h3 (W3C, G141). Under 1.3.1, however, it is listed among the advisory techniques that are not required for conformance (W3C, G141). The HTML standard is stricter here: each heading following another heading must have a level that is less than, equal to, or at most 1 (WHATWG, HTML Standard) greater than the previous heading's level. A jump from h2 to h4 therefore makes the document non-conforming to the HTML standard, even if a WCAG audit lists it only as a recommendation, depending on the test methodology.

For components, the opposite direction matters: going back up is allowed. An h2 may follow an h4 when it starts a new section (W3C WAI, Headings Tutorial). A component at the end of a deeply structured section is therefore not a problem, as long as it does not jump down itself. The overview shows where each rule comes from and what it means in code.

RuleSourceStatusConsequence in code
Reflect the structure of the presentation in codeWCAG 2.2, criterion 1.3.1Level AAnything that looks like a heading is a heading element or has role=heading
Headings describe topic or purposeWCAG 2.2, criterion 2.4.6Level AANo card title like Learn more, but the topic of the card
Sections have headingsWCAG 2.2, criterion 2.4.10Level AAANot required for AA, often decisive for usability
Properly nested levelsW3C, technique G141advisory for 1.3.1After an h2 comes an h2 or h3, no jump down
At most one level deeper than the previous headingWHATWG, HTML Standardconformance of the HTML documentDerive the component level from its placement
No pseudo heading through bold textW3C, failure F2failure of 1.3.1A real heading element instead of a bold paragraph

The level belongs to the placement

The most important decision is made when the component is built: it does not set its own heading level but receives it from the template that places it. The template knows the context, the component does not. If the card sits below an h2, it needs an h3. If the same card sits directly below the h1 of the home page, it needs an h2. The font size stays the same in both cases, because it depends on a CSS class and not on the element. The example shows the pattern as a simple template function; in other component systems it looks essentially the same, only the syntax of the property changes.

teaser-card.js
// Teaser card: the level comes from the placement, the look from the class
const MIN_LEVEL = 2; // the h1 belongs to the page
const MAX_LEVEL = 6; // there is no HTML element above h6

const esc = (s) => String(s).replace(/[&<>"]/g, (c) =>
  ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c]);

export function teaserCard({ title, text, href, headingLevel = 3 }) {
  const level = Math.min(MAX_LEVEL, Math.max(MIN_LEVEL, Number(headingLevel) || 3));
  return `
    <article class="teaser">
      <h${level} class="teaser__title heading-m">
        <a href="${esc(href)}">${esc(title)}</a>
      </h${level}>
      <p>${esc(text)}</p>
    </article>`;
}

// Service page: the cards sit below the h2 "Services"
teaserCard({ title: 'WCAG audit', text: 'All Level A and AA criteria.', href: '/en/wcag-audit/', headingLevel: 3 });

// Home page: the same card sits directly below the h1
teaserCard({ title: 'WCAG audit', text: 'All Level A and AA criteria.', href: '/en/wcag-audit/', headingLevel: 2 });

Three details make the pattern robust. First, there is a default value, so that a missing argument does not lead to an empty or invalid element. Second, the level is clamped: a component does not set an h1, because that belongs to the page, and there is no HTML element above h6. Anyone who needs deeper structure has to use aria-level, more on that below. Third, the heading-m class carries font size, weight and spacing, so an h2 card and an h3 card may look identical. The look is no longer an argument for the wrong level.

Teasers and cards

Cards add a second question: where does the link go? A proven approach is to place the link inside the heading and make the whole card clickable through a pseudo element of the link. The card title then remains the name of the link, and the heading list shows the same text as the link list. If you wrap an <a> around the whole card including heading, text and price instead, the entire content becomes the link name and the heading sits in the middle of a link. If a card grid has no visible section heading above it, the parent section is missing from the list; that is what the visually hidden heading described below is for.

Accordion

In an accordion, the header is both heading and control. The pattern in the W3C ARIA Authoring Practices Guide says that each accordion header button is wrapped in an element with role heading that has an aria-level appropriate for the information architecture of the page (W3C, APG Accordion Pattern). A native heading element may be used, and the button is the only element inside the heading (W3C, APG Accordion Pattern). The level therefore follows the page, not the accordion: below an h2 the headers get h3, and the same accordion inside a tab below an h3 gets h4.

faq-accordion.html
<!-- FAQ accordion below the h2 "Frequently asked questions": headers at level 3 -->
<h2 id="faq-heading">Frequently asked questions</h2>

<h3 class="accordion__header">
  <button type="button" id="faq-1-button" aria-expanded="false" aria-controls="faq-1-panel">
    How does an audit work?
  </button>
</h3>
<div id="faq-1-panel" hidden>
  <p>We test every view against WCAG 2.2 Level A and AA.</p>
</div>

Fixed areas: sidebar and footer

There is one exception to the principle. In fixed sections of a page, such as sidebars, heading levels should not change depending on the content area; there, consistency across pages is more important (W3C WAI, Headings Tutorial). An info box with opening hours in the sidebar therefore has the same level on every page, typically an h2, even if the main content next to it has reached h4. People who use the sidebar regularly will find it in the same place in the heading list. Technically this is the same parameter, just with a fixed value in the layout instead of a value from the content.

Multiple h1 elements and sectioning elements

A persistent misunderstanding in component libraries: every component may start with an h1, because section and article lower the level automatically. The idea comes from the outline algorithm that the HTML standard used to describe. Browsers implemented it only in the rendering, not in the heading level in the accessibility tree that screen readers use (MDN Blog). The algorithm was removed from the standard in 2022 (MDN Blog). Without further markup, an h1 inside a section is therefore level 1 for a screen reader, no matter how deeply it is nested.

The rendering is now catching up. Before May 2025 (MDN, Heading Elements) the standard specified that an h1 inside section, article, aside or nav should render like an h2, that is smaller; this special rule has been removed. Since version 136 (MDN Blog), Chrome shows deprecation warnings for such h1 elements that use the smaller default font size, and Firefox planned to ship the new rendering on all platforms in version 140 (MDN Blog). Anyone who relied on the old reduction sees nested h1 elements at full size in browsers with the new rendering. At the latest then it becomes obvious that they were not subheadings.

The HTML standard allows multiple h1 elements on a page as long as they are not nested; it is not considered a best practice (MDN, Heading Elements). Nesting multiple h1 elements in nested sectioning elements was allowed in older versions, was never considered a best practice and is now non-conforming (MDN, Heading Elements). This is not an edge case: 18.1% (WebAIM Million 2026) of the home pages analyzed had more than one h1, up from 16.3% (WebAIM Million 2026) in 2025. For components this leads to a simple rule: the h1 belongs to the page template, and no component sets one itself.

Sectioning elements are still useful, just for a different reason. Headings are useful for labeling page regions, and aria-labelledby associates a heading with its region (W3C WAI, Headings Tutorial). Regions do not replace headings, though: 28.3% (WebAIM Screen Reader User Survey #11) of respondents always or often use landmarks when they are present, but only 3.4% (WebAIM Screen Reader User Survey #11) use them as the primary method for finding information on a lengthy page. Regions and headings complement each other, and headings are the route most people take.

headingoffset: in the standard, not yet in daily use

The HTML standard now has a dedicated tool for exactly this component problem. The headingoffset attribute on an element increases the computed heading level of the headings inside it; valid values are integers from 0 to 8 (WHATWG, HTML Standard). With headingreset the count can be stopped at a certain point, for example in a dialog that should start again at level 1 (WHATWG, HTML Standard). The computed level does not go above 9 (WHATWG, HTML Standard). An explicit aria-level on the heading takes precedence over the computed heading level (MDN, headingoffset).

card-grid.html
<!-- headingoffset: the placement shifts the level of the component -->
<h1>Accessible web development</h1>
<h2>Services</h2>
<div class="card-grid" headingoffset="1">
  <article class="teaser">
    <h2 class="heading-m">WCAG audit</h2> <!-- with support: level 3, without: level 2 -->
  </article>
</div>

MDN lists the attribute as experimental with limited availability, not as Baseline (MDN, headingoffset). The decisive sentence is about the fallback: in browsers that do not support the attribute, headings keep the level of their element name, so the markup must still make sense without the offset (MDN, headingoffset). The example above shows the catch. Without support it produces two h2 elements in a row, and the card is no longer a subsection of the services. Anyone who writes components with an h1 because they trust the offset will deliver a page full of h1 elements in such browsers. For production code this means today: keep setting the level as a parameter, watch headingoffset, and use it only once browsers and screen readers support it broadly.

Visually hidden headings

Some sections are visually obvious but have no visible title: the product grid below the filters, the row of cards below an image, the footer area with contact details. For sighted users the design explains the section; in the heading list it is missing. A visually hidden heading closes this gap without changing the design. It stays in the accessibility tree but takes up no visible space.

visually-hidden.css
/* Screen readers only: the text stays in the accessibility tree */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Usage in the template:
<section aria-labelledby="results-heading">
  <h2 id="results-heading" class="visually-hidden">Search results</h2>
  <ul class="product-grid">...</ul>
</section>
*/

Do not use display: none or visibility: hidden: these styles hide content from all users, including screen readers (WebAIM, Invisible Content). And use the technique sparingly. Many screen reader users have some vision, and what they see and what they hear should typically be in harmony (WebAIM, Invisible Content). A hidden heading is right when it names a section that the design already shows. It is wrong when it adds content that sighted users do not get, or when it only fills a level that the layout skipped. In the second case the level of the visible heading is wrong, not the list incomplete.

role=heading with aria-level only as a fallback

Sometimes the element cannot be changed: an embedded widget outputs a div, a content management system produces markup that cannot be adjusted, or technical documentation needs more than six levels. In that case role="heading" can mark an element as a heading. The role must be paired with aria-level to define the heading level (W3C, ARIA12). The WAI-ARIA 1.2 specification also requires aria-level, so that elements with the role heading are organized into a logical outline (W3C, WAI-ARIA 1.2).

widget-heading.html
<!-- Output of an embedded widget that cannot be changed -->
<div class="widget-title" role="heading" aria-level="3">Opening hours</div>

<!-- Level 7 does not exist as an HTML element -->
<div role="heading" aria-level="7">Subsection delivery address</div>

<!-- Wrong: role without a level -->
<div role="heading">Opening hours</div>

Where possible, the native element remains the better choice. An h3 brings its own styling and behavior, for example in the browser's reader mode. A div with a role is not styled as a heading there, because ARIA only changes what assistive technology is told, not the style or functionality of the element (W3C, ARIA12). Very deep structures hit a practical limit: headings with an aria-level of 10 (W3C, ARIA12) or higher can create difficulties, and at the time the technique was written in 2024, most combinations of browser and assistive technology reported them as level 2 (W3C, ARIA12). Levels above six occur in manuals; on a service page they are a sign that the structure has become too deep. And the role does not go on the control itself: in an accordion, the button sits inside the heading, not the other way around.

Bold text is not a heading

The two errors in the mockup above are mirror images of the same problem. In the first case the level is chosen by appearance: the step card in the process section brings a hard-coded h4 because the font size fit, and a jump appears below the h2. In the second case the markup is missing entirely: “Frequently asked questions” is a bold paragraph above the accordion. For sighted users this is a heading; in the heading list it does not appear, and the section cannot be reached by heading navigation.

WCAG lists both patterns as failures of 1.3.1. F2 describes the case where a change in the appearance of text conveys meaning without using appropriate semantic markup (W3C, F2). F43 describes the opposite case: structural markup is used to achieve a presentational effect and indicates relationships that do not exist in the content (W3C, F43). The example there is an address in an h4 that was only meant to look large and bold. In components the same failure often looks more harmless, for example as a price, quote or key figure inside a heading element.

The solution is to separate level and appearance. A design system defines text styles as separate classes that fit any element, and the placement chooses the level. For the h1, MDN recommends an explicit baseline after the change in default rendering; with :where() the rule has zero specificity and does not override other rules that target the h1 (MDN Blog). How text styles, components and tests fit together in a design system is described in the article on the accessible design system.

heading-styles.css
/* Text styles independent of the level */
.heading-xl { font-size: clamp(2rem, 1.5rem + 2vw, 2.75rem); font-weight: 700; line-height: 1.15; }
.heading-l  { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.heading-m  { font-size: 1.25rem; font-weight: 650; line-height: 1.3; }
.heading-s  { font-size: 1rem;    font-weight: 650; line-height: 1.4; }

/* Baseline for h1, with zero specificity so it does not override your own rules */
:where(h1) { margin-block: 0.67em; font-size: 2em; }

Testing with the heading list

The test follows the mockup: on the left the page, on the right the list a screen reader builds from it. Screen readers are able to navigate heading markup, which can be an effective way for their users to find content of interest more quickly (W3C, H42). The same list can be generated in the browser. The following script collects all heading elements and all elements with role="heading", reads the level, reports a role without aria-level, flags headings hidden from everyone and marks downward jumps.

heading-list.js
// Run in the browser console: heading list with level and findings
(() => {
  const nodes = document.querySelectorAll('h1, h2, h3, h4, h5, h6, [role="heading"]');
  const rows = [];
  let previous = 0;
  for (const el of nodes) {
    const isNative = /^H[1-6]$/.test(el.tagName);
    const aria = el.getAttribute('aria-level');
    const level = aria !== null ? Number(aria) : isNative ? Number(el.tagName[1]) : null;
    const hidden = !el.checkVisibility() || el.closest('[aria-hidden="true"]') !== null;
    const findings = [];
    if (level === null) findings.push('role="heading" without aria-level');
    if (!hidden && level !== null && previous && level > previous + 1) {
      findings.push(`jump from ${previous} to ${level}`);
    }
    if (hidden) findings.push('hidden from everyone');
    rows.push({ level, text: el.textContent.trim().replace(/\s+/g, ' ').slice(0, 80), findings: findings.join(', ') });
    if (!hidden && level !== null) previous = level;
  }
  console.table(rows);
})();

The list does not replace testing with a screen reader, but it makes it faster. It also shows what a source code check misses: headings that scripts only insert in the browser, for example in expanded accordions, opened dialogs or filter results loaded later. In our screen reader testing we therefore check, in every view and every opened state, what the website passes on to screen readers, including the heading structure. Headings are not the only route through a page. How skip links and menus work together is covered in the article on accessible navigation, and how roles and states are marked up in the article on ARIA roles and live regions.

Component test per placement

A test at the source is usually more effective than checking page by page. Render every component with a heading in your test environment once for each intended level and check the result: does the element match the parameter, does the class stay the same, do the default and the clamp work? Such a test fails before a card lands in a new placement, and it keeps the rule in place when the team changes.

teaser-card.test.js
// Component test: the level follows the parameter, the clamp works, the look stays the same
import { teaserCard } from './teaser-card.js';

const cases = [[2, 'H2'], [3, 'H3'], [1, 'H2'], [9, 'H6'], [undefined, 'H3']];
for (const [input, expected] of cases) {
  const box = document.createElement('div');
  box.innerHTML = teaserCard({ title: 'Test', text: '', href: '#', headingLevel: input });
  const heading = box.querySelector('.teaser__title');
  console.assert(heading.tagName === expected, `level ${input}: ${heading.tagName}`);
  console.assert(heading.classList.contains('heading-m'), 'text style missing');
}

What an audit finds and fixes in headings

In a WCAG audit we assess headings per view against 1.3.1 and 2.4.6 and describe a remediation path for every finding. For headings, that path usually leads to the component: which component produces the heading, in which placements does it appear, and does the level come from the context or is it hard-coded? A finding on a teaser card is then not a single error on one page, but an item in the library that is fixed in all placements at once. This saves rework and prevents the same error from showing up again on the next page.

  1. Create an inventory of components with a heading: teaser, cards, accordion, tabs, dialog, info box, sidebar, footer area.
  2. Record for each component whether the level is hard-coded, passed as a parameter or set through role=heading.
  3. Generate the heading list per placement and mark downward jumps, missing section headings and multiple h1 elements.
  4. Search for bold paragraphs, image headings and text graphics that look like headings but are not marked up.
  5. Introduce the level as a parameter with a default and a clamp, and separate text styles from the level.
  6. Verify the screen reader output in all states and add the component test to the library.

Three rules for every component with a heading

The level comes from the placement and has a default value. The look depends on a class, not on the element. No component sets an h1 or jumps below the level of its parent section.

We implement this in your existing code, without a rebuild: in accessible web development we introduce the level as a parameter in the components, separate text styles from elements and add automated tests. So that new components follow the rule from the start, we offer training for development and design teams. Which requirements apply to your offering under the German Accessibility Strengthening Act is described on the page on BFSG requirements.

Sources

This article is based on data from: WebAIM (Screen Reader User Survey #11, conducted July to August 2026, last updated September 29, 2026; The WebAIM Million, 2026 report; Invisible Content Just for Screen Reader Users), W3C (Web Content Accessibility Guidelines 2.2; Understanding 2.4.6; techniques G141, H42 and ARIA12; failures F2 and F43; WAI-ARIA 1.2; WAI tutorial Headings; ARIA Authoring Practices Guide, Accordion Pattern), WHATWG (HTML Living Standard, section Headings and outlines) and MDN (Heading Elements; headingoffset; blog post Default styles for h1 elements are changing).

Related Articles

WCAG & standards

Empty Links and Buttons: Giving Controls a Clear Name

Empty links and buttons are among the most common WCAG findings. Fix patterns for icon buttons, image links and “more” links, checked via the links list.

18 min read
Practice & implementation

Accessible Product Pages: Variants, Gallery, Add to Cart

A flaw in the product template appears on every item page. How to make variant choice, gallery, price line and add-to-cart feedback accessible.

15 min read
WCAG & standards

Page Language: Setting lang and Marking Language Changes

How to mark page language and language changes under WCAG 3.1.1 and 3.1.2: lang on the html element, English claims, language switchers, exceptions, testing.

19 min read