# Navigation menus built as an app's menu bar

Source: https://easeweb.dev/learn/nav-menubar
Topics: Menus and navigation > Site navigation is read and moved through as links (WCAG 1.3.1)
The fix: Either rebuild the header as a nav element with a list of links, and a button with aria-expanded for each submenu, with no menu roles; or, as the smallest change, give the plain links role="menuitem" and put them in the bar's arrow-key order. The second passes 1.3.1 but leaves the site's navigation working as an app's menu.
Test with: screen reader, keyboard
References: https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships.html https://www.w3.org/TR/wai-aria-1.2/#menubar https://www.w3.org/WAI/ARIA/apg/patterns/menubar/ https://www.w3.org/WAI/ARIA/apg/patterns/menubar/examples/menubar-navigation/ https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/examples/disclosure-navigation/ https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/menu_role https://github.com/nvaccess/nvda/blob/master/source/browseMode.py https://www.radix-ui.com/primitives/docs/components/menubar https://www.radix-ui.com/primitives/docs/components/navigation-menu https://inclusive-components.design/menus-menu-buttons/

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

## What happens

A shop's header has four items in a row: Home, Shop, Journal and Help. Shop and Help open a list of pages; Home and Journal are plain links. With a mouse it all works. The header was built with a menu bar component, the kind a UI library offers for an app's File, Edit and View menus, so Shop and Help are menu items, and Home and Journal, which the component has no item type for, sit beside them as ordinary links.

A screen reader user tabs into the header. On Shop they hear "menu bar, Shop, menu item, collapsed, 1 of 2". Two items, in a header that shows four. They press Right Arrow, as a menu bar asks, and land on Help, "2 of 2", past Journal. Home and Journal are still there, and Tab reaches them, but each is read as "link" with no place in the menu: from what they hear, the menu is two items with two stray links beside it.

The keyboard is no simpler. The component gives the bar one Tab stop, on whichever menu item was last used, so Tab goes Home, Shop, Journal and on into the page. Help is reached only with the arrow keys from Shop, and Right Arrow from Shop skips Journal.

## Why it fails

WCAG 1.3.1 Info and Relationships asks that structure shown on screen can also be read by assistive technology. On screen, the four items are one row, one menu. In the code, `role="menubar"` says the row is a menu bar, and ARIA lets a menu bar hold only menu items (and groups and separators of them). The two submenu buttons have `role="menuitem"`, so they are its items; Home and Journal are links, a role a menu bar can't own, so they are not its items. A screen reader reports the structure the code gives it: a menu bar of two items, positions 1 of 2 and 2 of 2, and two links inside it that are left out of the count. The relationship a sighted visitor sees, four items in one menu, isn't there for anyone else.

The keys follow the same structure. A menu bar is meant to be one Tab stop, moved along with the arrow keys, so the component keeps a roving `tabindex`: `0` on one menu item and `-1` on the other. The links keep their own Tab stops and are not in the arrow-key order. Everything can still be reached, Help by Right Arrow, so 2.1.1 Keyboard passes, but which key reaches which item now depends on how each one was marked up.

## Who is affected

A menu bar also changes how a screen reader works. NVDA, for one, switches to focus mode as soon as focus lands in a menu bar or a menu item: it stops reading the page with its own keys and passes the arrow keys to the page's script, as it does in an app, because a menu bar promises that its script handles them.

## What automation and AI miss

axe and Lighthouse do report this one: the menu bar fails `aria-required-children`, "Certain ARIA roles must contain particular children". The message names neither the links nor the navigation (its detail lists only the `a` elements, as "children which are not allowed"), so it reads like a list problem, and the obvious way to clear it is to add `role="menuitem"` to the links. An AI coding tool asked to fix the error is likely to do exactly that. The error goes, and the header is now a complete app menu bar, which is the second fix below: it passes, and axe reports nothing on it, but it is still the wrong pattern for a site's navigation. Nothing in a scan asks whether the menu bar should be there at all.

The audit reports a menu bar that holds links which are not its menu items, and names them, in place of axe's message. A menu bar whose links are all menu items is sent to review as a lead: no criterion fails, so a person decides whether it is the site's navigation or an app's menu. Listening to the header with a screen reader, and tabbing through it, is still how to confirm either.

## Before: a menu bar with links beside its menu items

```html
<header>
  <div class="menu" role="menubar">
    <a href="/" aria-current="page">Home</a>
    <button type="button" role="menuitem" aria-haspopup="menu" aria-expanded="false" aria-controls="shop-menu" tabindex="0">Shop</button>
    <a href="/journal">Journal</a>
    <button type="button" role="menuitem" aria-haspopup="menu" aria-expanded="false" aria-controls="help-menu" tabindex="-1">Help</button>
  </div>
  <div id="shop-menu" role="menu" aria-label="Shop" hidden>
    <a href="/shop/lamps" role="menuitem" tabindex="-1">Lamps</a>
    <a href="/shop/chairs" role="menuitem" tabindex="-1">Chairs</a>
    <a href="/shop/rugs" role="menuitem" tabindex="-1">Rugs</a>
  </div>
  <div id="help-menu" role="menu" aria-label="Help" hidden>
    …
  </div>
</header>
```

```js
// The menu bar's keys, as the component writes them: one Tab stop, and the arrow keys between
// its menu items. The submenus' own keys (Down Arrow to open, Up, Down and Escape inside) are
// left out here.
const bar = document.querySelector('[role="menubar"]');
const items = [...bar.querySelectorAll('[role="menuitem"]')];

function move(to) {
  for (const item of items) item.tabIndex = -1;
  const item = items[(to + items.length) % items.length];
  item.tabIndex = 0;
  item.focus();
}

bar.addEventListener('keydown', (event) => {
  const at = items.indexOf(event.target);
  if (at < 0) return;
  if (event.key === 'ArrowRight') move(at + 1);
  if (event.key === 'ArrowLeft') move(at - 1);
});
```

- Home and Journal are links inside a menu bar, which can own only menu items, so they are not its items. A screen reader counts two items, Shop "1 of 2" and Help "2 of 2".
- Right Arrow moves between Shop and Help only, so it skips Journal.
- Tab stops on Home, Shop and Journal, and never on Help, which has `tabindex="-1"` until Right Arrow reaches it.

## After: a nav with links and submenu buttons

```html
<header>
  <nav aria-label="Main">
    <ul class="menu">
      <li>
        <a href="/" aria-current="page">Home</a>
      </li>
      <li class="has-sub">
        <button type="button" aria-expanded="false" aria-controls="shop-menu">Shop</button>
        <ul id="shop-menu" tabindex="-1" hidden>
          <li>
            <a href="/shop/lamps">Lamps</a>
          </li>
          <li>
            <a href="/shop/chairs">Chairs</a>
          </li>
          <li>
            <a href="/shop/rugs">Rugs</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="/journal">Journal</a>
      </li>
      <li class="has-sub">
        <button type="button" aria-expanded="false" aria-controls="help-menu">Help</button>
        <ul id="help-menu" tabindex="-1" hidden>
          …
        </ul>
      </li>
    </ul>
  </nav>
</header>
```

```js
for (const item of document.querySelectorAll('.has-sub')) {
  const button = item.querySelector('button');
  const list = document.getElementById(button.getAttribute('aria-controls'));
  const setOpen = (open) => {
    button.setAttribute('aria-expanded', String(open));
    list.hidden = !open;
  };
  button.addEventListener('click', () => setOpen(list.hidden));
  item.addEventListener('keydown', (event) => {
    if (event.key === 'Escape' && !list.hidden) {
      setOpen(false);
      button.focus();
    }
  });
  // Close when focus leaves the item, and leave focus where the user put it.
  item.addEventListener('focusout', (event) => {
    if (!item.contains(event.relatedTarget)) setOpen(false);
  });
}
```

1. Replace the menu bar with a `nav` named Main, holding a list with one `li` per item. A screen reader announces the navigation and a list of four items, and every item is in it.
2. Keep Home and Journal as plain links, and make Shop and Help plain buttons: no `role`, no `aria-haspopup`, no `tabindex`. Each is its own Tab stop, in the order shown, and is read as what it is.
3. Put each submenu's list straight after its button, with `aria-expanded` on the button kept in step with `hidden` on the list, and `aria-controls` pointing at it. Tab goes from the button into the open list.
4. Close an open list on Escape, with focus back on its button, and when focus leaves its item. Put `tabindex="-1"` on the list so a click inside it doesn't count as leaving.
5. Remove the menu bar's key handling. Tab moves through the navigation; nothing needs the arrow keys.

This fixes the Before and passes 1.3.1: the list holds every item, and nothing is left outside it. [Hover-only dropdowns, or ones that never say they are open](/learn/nav-menus) explains the button, its state and the two ways it closes in detail.

## After: every link a menu item

```html
<header>
  <div class="menu" role="menubar">
    <a href="/" role="menuitem" aria-current="page" tabindex="-1">Home</a>
    <button type="button" role="menuitem" aria-haspopup="menu" aria-expanded="false" aria-controls="shop-menu" tabindex="0">Shop</button>
    <a href="/journal" role="menuitem" tabindex="-1">Journal</a>
    <button type="button" role="menuitem" aria-haspopup="menu" aria-expanded="false" aria-controls="help-menu" tabindex="-1">Help</button>
  </div>
  <div id="shop-menu" role="menu" aria-label="Shop" hidden>
    <a href="/shop/lamps" role="menuitem" tabindex="-1">Lamps</a>
    <a href="/shop/chairs" role="menuitem" tabindex="-1">Chairs</a>
    <a href="/shop/rugs" role="menuitem" tabindex="-1">Rugs</a>
  </div>
  <div id="help-menu" role="menu" aria-label="Help" hidden>
    …
  </div>
</header>
```

```js
// The menu bar's keys, as the component writes them: one Tab stop, and the arrow keys between
// its menu items. The submenus' own keys (Down Arrow to open, Up, Down and Escape inside) are
// left out here.
const bar = document.querySelector('[role="menubar"]');
const items = [...bar.querySelectorAll('[role="menuitem"]')];

function move(to) {
  for (const item of items) item.tabIndex = -1;
  const item = items[(to + items.length) % items.length];
  item.tabIndex = 0;
  item.focus();
}

bar.addEventListener('keydown', (event) => {
  const at = items.indexOf(event.target);
  if (at < 0) return;
  if (event.key === 'ArrowRight') move(at + 1);
  if (event.key === 'ArrowLeft') move(at - 1);
});
```

1. Give Home and Journal `role="menuitem"`. They become items of the menu bar, so a screen reader counts four, and Shop is "2 of 4".
2. Give them `tabindex="-1"`, as the other items have. The script already collects every menu item in the bar, so the arrow keys now move through all four, and the bar is one Tab stop.

This is the smallest change that passes 1.3.1, and it is the one that clears axe's message. It doesn't make the header a site's navigation: it is now a complete app menu bar, with one Tab stop, the arrow keys to move along it, and links announced as "menu item". In a menu bar, NVDA, for one, hands the arrow keys to the page, so while focus is in it, its users can't read the menu as text the way they read the rest of the page.

## Which option to use

Use the nav. It passes on its own, with no keys to learn: every item is a Tab stop, links are read as links, and the list gives the right count. It is built from HTML that already does the work, so the menu bar's key script goes, and the button script left is the one the [hover dropdowns guide](/learn/nav-menus) already teaches. Making every link a menu item is the quick way to clear the scan, and it is the menu bar pattern done properly, but it keeps people in an app's menu where they expect a site's links. The ARIA Authoring Practices' own navigation menubar example says the disclosure pattern "is better suited for most web sites because few sites need the additional keyboard functionality required to support the ARIA menubar and menu roles." Keep a menu bar only where the bar really is an app's menu, with commands such as File and Edit, rather than pages.

## Implementation decisions

Component libraries usually offer both. In Radix UI, Menubar is "a visually persistent menu common in desktop applications", whose triggers are buttons with `role="menuitem"` and no item type for a plain link, which is how links end up beside them as in the Before. Navigation Menu is "a collection of links for navigating websites": it renders a `nav`, a list, and buttons with `aria-expanded` for its submenus, and its documentation says it "should not be confused with menubar". The shadcn/ui components wrap both under the same names. If your header uses Menubar, switch the component rather than adding roles to the links.

Other parts of the header each need their own answer:

- Arrow keys: optional. You may let Left and Right Arrow move between the top-level items as well, but keep each one a Tab stop, so people who don't know about the arrow keys miss nothing.
- `aria-haspopup`: leave it off the submenu buttons. On a button it announces a menu, and the list it opens is a list of links.
- The current page: keep `aria-current="page"` on its link, as [navigation that marks the current page only by its look](/learn/current-page) explains. It is read on a link in a list as it was in the menu bar.
- An item that is both a page and a submenu: keep the link and a separate button side by side; [dropdown parent links that open the submenu, not the page](/learn/menu-link-toggle) covers it.
- A real app menu on the same page, such as an editor's toolbar of File and Edit menus, stays a menu bar. Action menus behind a More button are covered in [action menus that open silently, out of keyboard reach](/learn/menu-button), where `role="menu"` is right.

## Verify the fix

1. Inspect the header: no `role="menubar"`, `role="menu"` or `role="menuitem"` on the navigation or its submenus, and no `tabindex` on its links and buttons.
2. Put the mouse aside and Tab from before the header to after it. Every link and submenu button is reached once, in the order shown, without the arrow keys.
3. With a screen reader, Tab into the navigation and listen. It announces navigation and a list with as many items as you can see, the links as links and each submenu button as a button, collapsed.
4. Open each submenu with Enter or Space: its button is announced as expanded, Tab moves into its links, and Escape closes it with focus back on the button.

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared header component changes.

## Limits

This guide is about the roles a site's navigation is given. A submenu that opens only on hover, or a button that never says whether its list is open, is covered in [hover-only dropdowns, or ones that never say they are open](/learn/nav-menus). The script is a minimal sketch without animation, hover opening or nested levels. Test the complete journey, including your narrow-screen menu, with your target assistive technology.

---

Get this guide in your coding agent: MCP https://easeweb.dev/mcp (setup at https://easeweb.dev/services/developers)
