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, anh1in the layout and another in each view, or a jump fromh2toh4. STR-003, a guideline (our choice) - A shell built from
divs, twonavs that are both announced as “navigation”, or a secondmaininsideSidebarInset. 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.
STR-001Give every page a title that says what it is for, and change it with every viewGive every page a title, in the title element, that says what the page holds or is for. In a single page app, set a new title on every route change, so the title names the view now shown, not only the app.STR-002aMark text that heads a part of the view as a heading in codeWhen 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.STR-002bWord each heading so it says what the part below it holdsWord every heading so it says what the part below it holds or is for. A heading that would fit any part of any page, such as "Details" or "Section 2", does not.STR-005Give images and icons that carry information a text alternative, and hide the ones that only decorateGive an image or icon that carries information a text alternative that says what it tells the person in that place, never a file name or a word that only names the kind of picture. Hide one that only decorates from assistive technology, with alt="" on an img or aria-hidden="true" on an icon.STR-006Name the page's main language in the lang attribute on the html element, and change it when the interface changes languagePut a lang attribute on the html element whose value is a valid language tag for the language most of the page is written in. When the interface switches to another language without loading a new page, change the attribute to that language at the same time.STR-006aMark text in another language than the text around it with its own lang attributeWhen a passage, phrase or word is in another language than the text around it, put lang with that language's tag on the element that holds it, such as language picker entries written in their own languages. Proper names, technical terms, words of unclear language and words the surrounding language has taken in need none.
Decided by the judges
No WCAG criterion requires these. The judges who spoke support them, all or most of them.
STR-004Build the page's regions from landmark elements, and name repeated ones apartBuild the page's regions from landmark elements: the main content in main, the top bar in header, each group of navigation links in nav and the bottom bar in footer. When a page has more than one nav, give each a name that tells them apart.
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.
STR-003Give each view one h1 and every other heading the level its place in the outline gives itGive each view one h1 that names its main content. Give every other heading the level its place in the outline gives it: one below the heading it belongs under. Going down never skips a level; going back up may skip as many as needed.
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
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.