Skip to content

Page structure patterns for shadcn

Rules / Page structure: 7 rules and 1 guideline

A screen reader user often meets a page’s structure before its content: the title read out when the page opens, a list of its headings, the landmarks to jump between. A sighted person gets the same from the layout at a glance. When that structure lives only in the styling, one group sees sections and the other hears a flat run of text. shadcn’s CardTitle and AlertTitle render a div, the Sidebar is built from divs, and the Vite and Next.js starters ship one title for every page. The rules here put the structure into the code.

Where page structure goes wrong

  • Every tab reads “Vite + React + TS”, or only the product’s name on every route, so nobody can tell the views apart. STR-001
  • A section title written as <p className="text-2xl font-bold">, so the page has no headings to move between. STR-002a
  • A price or a small label under a number marked up as a heading because the size fits. STR-002a
  • Three cards headed Details, Info and Misc. STR-002b
  • An app shell with no h1, an h1 in the layout and another in each view, or a jump from h2 to h4. STR-003, a guideline (our choice)
  • A shell built from divs, two navs that are both announced as “navigation”, or a second main inside SidebarInset. STR-004
  • alt="logo" or a file name as the text of an image, or a red status icon with no text at all. STR-005
  • <html lang="en"> left on a page the app has switched to German, or a language picker whose entries are read out in the wrong accent. STR-006, STR-006a

How the rules fit together

STR-001 starts at the top. Every page has a title that says what it holds or is for, and in a single page app it changes with every route, so it names the view now shown and not only the app.

Three texts cover headings. STR-002a says that text which heads a part of the view, such as a section, a card, a panel or a dialog, is a heading in code and not only bold or large type. STR-002b says what the heading says: what the part below it holds, not a word that would fit any part of any page. STR-003, a guideline (our choice), sets the level: one h1 per view, and every other heading one level below the heading it belongs under, never skipping on the way down. A dialog’s title is a heading of its own, outside the page’s outline.

STR-004 builds the page’s regions from landmark elements: header, nav, main and footer, with a name for each nav when there is more than one. That gives a screen reader user a way past the menus. The skip link in the navigation patterns (NAV-004, a guideline) gives one to keyboard users without a screen reader, and the order of the regions in code is LAY-002.

STR-005 covers pictures. An image or icon that carries information gets a text alternative that says what it tells the person in that place; one that only decorates is hidden from assistive technology. An icon button takes its name from what it does (ACT-001b), and an image link from where it goes (TXT-003). A table’s title, which is not a heading, is in the table patterns.

Two texts cover language, which a screen reader needs to pronounce the words. STR-006 names the page’s main language in lang on the html element and changes it when the interface switches language without a new page. STR-006a marks a passage in another language with its own lang, such as the entries in a language picker.

What WCAG requires and what the judges decide

Six rules here come from WCAG 2.2. Page titles follow from 2.4.2 Page Titled, headings in code from 1.3.1 Info and Relationships, headings that describe from 2.4.6 Headings and Labels, text for images from 1.1.1 Non-text Content, and the language of the page and of its parts from 3.1.1 Language of Page and 3.1.2 Language of Parts. For these the law decides. The judges are recorded too: all three supported headings in code and text for images, both who spoke supported headings that describe, and the one who spoke supported page titles. No judge has spoken on language; the law decides it alone.

Landmarks are decided by the judges, with both who spoke in support. No criterion requires them; 1.3.1 and 2.4.1 Bypass Blocks can be met in other ways. Heading levels are a guideline: only one judge has spoken, and no criterion requires one h1 or levels without gaps, so it is our choice, with our reasons on its page.

Rules and guidelines

Each one has its own page with the full rule, Do and Don't cases, exceptions and the verdict. A rule is decided by WCAG 2.2 or by the judges. A guideline is our own choice. How the method works

Required by WCAG 2.2

A WCAG 2.2 Level AA criterion requires the behaviour. Where a rule adds advice of its own, it says so.

Decided by the judges

No WCAG criterion requires these. The judges who spoke support them, all or most of them.

Guidelines, our choice

The judges are split or too few have spoken, so we choose and give our reasons. A product that chooses otherwise is not wrong.

All rules · Is shadcn accessible? · Give the rules to an AI agent

Justified by Blackwood & Blake helps you work toward WCAG 2.2 AA. It is not a certification. Read more