Skip to content

STR-002a Mark text that heads a part of the view as a heading in code

Level
Rule
Verdict
Requirement
Status
proposed, version 1.0.0

Rule

When text heads a part of the view, such as a section, a card, a panel or a dialog, mark it as a heading in code, not only with bold or large type.

Examples

Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.

Do: Section titles are headings

Page: Project settings

h1Project settings
h2Members

Maya Lindqvist, Tomas Reyes and 2 more

h2Billing address

14 Alder Lane, Bristol

h2Delete project

This cannot be undone.

Simulated: the heading list a screen reader would build from this page's code:

  1. h1Project settings
  2. h2Members
  3. h2Billing address
  4. h2Delete project

Press Next heading as a screen reader's heading key would. It steps through the page's h1 and each section. The chips show every title is a heading element, styled with classes to look as it does.

Don't: Styled text, not headings

Page: Project settings

pProject settings
divMembers

Maya Lindqvist, Tomas Reyes and 2 more

divBilling address

14 Alder Lane, Bristol

divDelete project

This cannot be undone.

Simulated: the heading list a screen reader would build from this page's code:

No headings. A person who lists headings finds nothing.

Same page, same looks, but the titles are a p and div with bold type. The heading list is empty and Next heading has nowhere to go: to a screen reader the page has no sections.

Don't: A price marked as a heading

Page: Plans

h1Choose a plan
h2Team
h3€12 a month

Up to 10 members

Simulated: the heading list a screen reader would build from this page's code:

  1. h1Choose a plan
  2. h2Team
  3. h3€12 a month

The plan card is headed Team, but the price is an h3 too so that it stands out. A price heads nothing, and the heading list now offers it as a section.

Why

A sighted person finds their way down a page by the titles that stand out. A screen reader user does the same with a list of headings and a key that jumps from one to the next. That only works when the titles are headings in code. Text styled to look like a heading is, to a screen reader, one more line of text, so the page has no sections to jump between. The reverse misleads just as much: heading markup on a label or a number invents a section that is not there.

This is a requirement. WCAG 2.2, 1.3.1 Info and Relationships asks that structure shown on screen can also be read from the code. The Working Group lists as a failure text that is styled to look like a heading but is marked up as ordinary text (F2), and its HTML technique is the h1 to h6 elements (H42). The same criterion fails heading markup on text that heads nothing (F43). The criterion does not ask that a page have headings, or a certain number of them. It asks that what works as a heading is one. What the heading says is STR-002b, and its level is STR-003.

Do

  • In the project tool Ridgeway, the page Project settings has the sections Members, Billing address and Delete project. Each section title is a heading element, styled with classes.
  • In shadcn, CardTitle and AlertTitle render a div and take no asChild. When the title heads what is in the card or the alert, put an h2 or h3 inside it, or change the element the component renders.
  • SidebarGroupLabel also renders a div, but takes asChild. When it heads a group of links, write <SidebarGroupLabel asChild><h2>Projects</h2></SidebarGroupLabel>, which keeps its styling.
  • Keep DialogTitle, SheetTitle, AlertDialogTitle and DrawerTitle. They render headings through Radix and also give the dialog its name.
  • When a heading takes focus from script, as DLG-006 allows in one case, it stays a heading element with tabindex="-1".
  • Our own advice, not required: when a part is plain to sighted users from the layout but has no visible title, such as a list of search results, give it a heading with the sr-only class, such as "Search results".
  • Our own choice: use the native h1 to h6 elements. role="heading" with aria-level also counts, as a fallback when the element cannot change.

Don't

  • Head the page with <p className="text-2xl font-bold">Project settings</p>.
  • Build a section header as <div className="text-lg font-semibold">Members</div>.
  • Replace DialogTitle with a styled p, so the dialog loses both its heading and its name.
  • Mark the small grey text under a number on a dashboard tile, such as "Open tasks", as an h4 because the tag fits. It heads nothing, which is the failure in F43.
  • Make the price on a plan card, "€12 a month", an h3 so it stands out. A price heads nothing.

Exceptions

  • Labels of controls. A field's label or a group's legend is not a heading. A label may sit inside a heading when the whole page asks one question, but that is a choice, not part of this rule.
  • Table captions. A table's caption names the table and is not a heading. A word above a list can be one, when it heads that part.
  • Not covered here. The heading's words are STR-002b and its level is STR-003. Where a heading sits in the code relative to its part is LAY-002. The page's title element is STR-001.

Verdict

Requirement. Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work

Stances on STR-002a
SourceRoleStancePage
WCAG 2.2LawRequires1.3.1 Info and Relationships
Material DesignJudge SupportsAccessibility designing: structure
Apple Human Interface GuidelinesJudge SupportsVoiceOver
Carbon Design SystemJudge SupportsGlobal header
Accessibility: Developers
GOV.UK Design SystemExpert witness SupportsHeadings
Nielsen Norman GroupExpert witness No position

Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.

History

  • Version 1.0.0, : First version.

Last checked against the other rules for conflicts on .

More in Page structure: 7 rules and 1 guideline · All rules