Navigation menu patterns for shadcn
Rules / Navigation: 3 rules and 1 guideline
Almost every app has a menu that comes back on every page: a top bar, a sidebar, a row of links in the footer. People learn it once and then rely on it for two things: to tell them where they are, and to take them somewhere else. shadcn’s Sidebar and NavigationMenu draw the menu and handle the keys. The highlight on the current item, though, is a data attribute and a change of colour, and nothing in the components keeps the order the same from page to page or lets a keyboard user get past the menu to the content.
Where navigation goes wrong
- A highlighted sidebar item that a screen reader reads as just another link, because
isActivesets only a data attribute. NAV-002a - A current page shown only by a slightly darker text colour, or by the same background the hover uses. NAV-002b
- Two items marked at once, because a prefix match on
/matches every route. NAV-002b - Items that swap places from page to page because each page builds its own list, or a mobile sheet built from a second list that has drifted from the sidebar. NAV-003
- Twenty presses on Tab through the header and the sidebar, on every page, before the content is reached. NAV-004, a guideline (our choice)
How the rules fit together
NAV-002a and NAV-002b are two sides of the same mark. When a menu shows which item is the current page, NAV-002a says so in code as well, usually with aria-current="page" on the link itself, so a screen reader announces it. NAV-002b says that a menu repeated across pages shows that mark, on one item only, with a cue that is not colour alone: heavier text, a filled icon, a shape behind the item or a bar beside it. Take the mark from the route, so it is right after a reload, and keep it different from the hover style and from the focus ring.
NAV-003 keeps the menu predictable. Items that repeat across pages keep the same relative order on every page, unless the person reordered them. An item may be added on some pages or left out on others, as long as the rest keep their order. One shared list, rendered by the sidebar and by the mobile sheet alike, is the simple way to get there.
NAV-004, a guideline (our choice), adds a skip link: the first thing Tab reaches, visible while it has focus, and moving focus to the start of the main content. It works beside the landmarks in the page structure patterns. A named nav for each menu and one main let a screen reader jump past the menu (STR-004); the skip link does the same for people who use a keyboard without one.
The menu also has to survive a narrow screen. When the sidebar moves into a sheet, every link and the current mark go with it (LAY-001). The contrast a colour or a bar in the mark needs is in the colour patterns (VIS-003a, VIS-004), and the visible focus on each link is KBD-001.
What WCAG requires and what the judges decide
Two rules here come from WCAG 2.2. Saying the current page in code follows from 1.3.1 Info and Relationships, and keeping the order from 3.2.3 Consistent Navigation. For a requirement the law decides; the one judge who spoke on NAV-002a supported it, and both who spoke on NAV-003.
Showing the current item by more than colour is decided by the judges, and both who spoke support it. WCAG at Level AA does not ask a menu to show the current item at all, and 1.4.1 Use of Color accepts some marks made of colour, so this rule asks more than the law. The skip link is a guideline. Only one judge has spoken, and 2.4.1 Bypass Blocks can be met with landmarks alone, 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.
NAV-002aWhen a menu shows the current page, say so in the code on that itemWhen a navigation menu shows which item is the page the person is on, the code or the text says so too, so a screen reader announces that item as the current page. The usual way is aria-current="page" on its link.NAV-003Keep repeated navigation in the same order on every pageNavigation that repeats on several pages of a product, such as a top bar, a sidebar or a row of footer links, lists its items in the same relative order on every page, unless the person changed the order themselves.
Decided by the judges
No WCAG criterion requires these. The judges who spoke support them, all or most of them.
NAV-002bMark the current page in a repeated menu with a cue that is not colour aloneA navigation menu that repeats across pages marks the item for the page or section the person is in, and only that item. The mark does not rest on colour alone: use heavier text, a filled icon, a shape behind the item or a bar beside it.
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.
NAV-004Start a page with a skip link when links come before its main contentWhen a header or sidebar with links comes before a page's main content, make a skip link the first thing Tab reaches. It is visible while it has focus, and it moves focus to the start of the main content.
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.