TL;DR
An accessible menu works for a visitor without a mouse: on a keyboard, a screen reader, or a phone zoomed in. Most menus fail the same way: they open only on hover, lose the keyboard, or promise behavior their code never delivers. The fix is plain HTML (a list of links in a navigation landmark), a real button for each dropdown that says whether it is open, Escape to close it, a visible focus outline, and a skip link. Test it with only a keyboard and a screen reader.
An accessible navigation menu is one that works for everyone who arrives at the site: a mouse user, a keyboard user, someone on a screen reader, and someone zoomed to 400% on a phone. Most menus fail in the same few places. They use ARIA roles that promise behavior the menu never delivers, they hide dropdowns behind hover, or they lose the focus outline. This guide walks through the HTML, ARIA, JavaScript, and CSS that fix each of those, with a complete example you can copy, and the WCAG 2.2 success criteria that each piece helps you meet.
Which standard applies depends on who owns the site. For state and local governments, the Department of Justice’s 2024 web rule under ADA Title II adopts WCAG 2.1 Level AA, with compliance dates in 2027 and 2028. For other sites, WCAG at Level AA is the benchmark accessibility audits usually measure against. This guide targets WCAG 2.2 AA, which includes everything in 2.1 AA.
Start with semantic HTML
Most of an accessible menu comes free with the right elements:
<nav>marks a navigation landmark. Screen reader users can jump straight to it from a landmarks list.<ul>and<li>tell a screen reader how many links there are (“list, 5 items”) before the user starts reading them.<a href>for anything that goes to another page. Links are focusable and open with Enter, with no extra code.<button type="button">for anything that opens, closes, or toggles something on the same page. Buttons are focusable and activate with both Enter and Space.
The rule of thumb: if it changes the URL, it is a link. If it changes the
page in place, it is a button. A link with href="#" that opens a dropdown
is a button wearing a link’s clothes, and screen readers will announce it
wrongly.
Role attributes for website menu navigation
Here is what each role does, and whether a website menu needs it.
| Role or attribute | What it does | Use it in site navigation? |
|---|---|---|
role="navigation" | Marks a navigation landmark. | Only on an element that is not <nav>. The <nav> element already has this role, so adding it there is redundant. |
role="link" | Makes an element announce as a link. | No. Use <a href>, which is a link already and also opens with Enter. |
role="menu" | Declares an application style menu: arrow keys move between items, Tab leaves the whole menu. | Rarely. See the next section. |
role="menuitem" | An item inside a role="menu". | Only inside a real role="menu". On a plain link it changes what the screen reader announces and promises arrow key behavior. |
role="button" | Makes an element announce as a button. | No. Use <button>, which is focusable and handles Enter and Space for you. |
tabindex="0" | Puts an element into the Tab order. | Not on links or buttons, which are focusable already. Avoid any value above 0, which reorders focus. |
When not to use role=“menu” and role=“menuitem”
The W3C ARIA Authoring Practices Guide (APG) describes a menu as a widget that offers a list of choices, such as actions or functions, and says menus behave like native operating system menus. When focus is in one, arrow keys move between items, and Tab and Shift + Tab do not.
A website’s main navigation is a set of links, not a set of commands. If
you put role="menu" on it, a screen reader user hears “menu” and reaches
for the arrow keys, and unless you have written all of that keyboard
handling, nothing happens. The APG’s own navigation example says it does not
use the menu role “because it does not provide the complex functionality
that assistive technologies expect.” MDN goes further: “menubars should not
be used to create website navigation.”
What to use instead is the disclosure pattern: a list of links, with a button that shows and hides each dropdown. That is what the example below builds.
ARIA attributes for website menu navigation
| ARIA attribute | What it does | How to use it |
|---|---|---|
aria-label="Main" | Gives an element an accessible name when no visible text names it. | Name each <nav> when a page has more than one. Leave out the word “navigation”: the screen reader already says the role, so “Main navigation” is announced as “Main navigation navigation”. |
aria-label="Open menu" | Names an icon-only button. | Use it on a hamburger button that has no visible text. If the button shows the word “Menu”, the text is the name and no aria-label is needed. |
aria-haspopup="true" | Says the button opens a popup of a given type. true means the popup is a menu. | Leave it off disclosure buttons. Its value has to match the popup’s role (menu, listbox, tree, grid, or dialog), and a list of links is none of those. |
aria-controls="nav-services" | Points to the id of the element the button shows and hides. | Put it on each disclosure button, with the id of its submenu. |
aria-expanded="false" | Says whether the controlled content is showing. | false while closed, true while open. Update it on every toggle. |
aria-current="page" | Marks the link to the page the visitor is on. | Put it on one link per navigation, and style it visibly too. |
A complete accessible navigation menu example
This is a main navigation with three links and one dropdown, built on the disclosure pattern. It has no framework dependency.
<a class="skip-link" href="#main">Skip to main content</a>
<header>
<a href="/" class="brand">Brand</a>
<nav aria-label="Main">
<button
type="button"
class="nav-toggle"
aria-expanded="false"
aria-controls="nav-list"
>
Menu
</button>
<ul id="nav-list" class="nav-list">
<li><a href="/" aria-current="page">Home</a></li>
<li class="has-submenu">
<button
type="button"
class="submenu-toggle"
aria-expanded="false"
aria-controls="nav-services"
>
Services
</button>
<ul id="nav-services" class="submenu">
<li><a href="/services/web-development/">Web development</a></li>
<li><a href="/services/seo/">SEO</a></li>
</ul>
</li>
<li><a href="/about/">About</a></li>
<li><a href="/contact/">Contact</a></li>
</ul>
</nav>
</header>
<main id="main" tabindex="-1">
...
</main>
A few choices here are worth calling out:
- “Services” is a button, not a link. If Services should also have its own page, add an “All services” link as the first item in the submenu rather than making one control do two jobs. The APG recommends avoiding a control that both performs an action and opens a submenu.
- No
roleattributes at all. Every element already has the right role. tabindex="-1"on<main>lets the skip link move focus there in every browser, without putting<main>into the Tab order.
The JavaScript: toggle, Escape, and focus
The disclosure pattern needs very little script. Each button flips its own
aria-expanded, and CSS shows or hides the list based on that value, so the
attribute and the screen can never disagree.
const nav = document.querySelector('nav[aria-label="Main"]');
const toggles = nav.querySelectorAll('button[aria-controls]');
function setOpen(button, open) {
button.setAttribute('aria-expanded', String(open));
}
function closeSubmenus(except) {
nav.querySelectorAll('.submenu-toggle').forEach((button) => {
if (button !== except) setOpen(button, false);
});
}
toggles.forEach((button) => {
button.addEventListener('click', () => {
const open = button.getAttribute('aria-expanded') !== 'true';
if (button.classList.contains('submenu-toggle')) closeSubmenus(button);
setOpen(button, open);
});
});
// Escape closes a submenu first, then the outer mobile menu.
nav.addEventListener('keydown', (event) => {
if (event.key !== 'Escape') return;
const open = nav.querySelector('.submenu-toggle[aria-expanded="true"]');
if (open) {
event.preventDefault();
setOpen(open, false);
open.focus();
return;
}
const outer = nav.querySelector('.nav-toggle');
if (window.matchMedia('(max-width: 767px)').matches &&
outer.getAttribute('aria-expanded') === 'true') {
event.preventDefault();
setOpen(outer, false);
closeSubmenus();
outer.focus();
}
});
// Close a submenu when focus or a click moves outside the navigation.
document.addEventListener('click', (event) => {
if (!nav.contains(event.target)) closeSubmenus();
});
nav.addEventListener('focusout', (event) => {
// relatedTarget is the element receiving focus; null when focus did not
// move to another element, which the click handler above covers.
if (event.relatedTarget && !nav.contains(event.relatedTarget)) closeSubmenus();
});
This matches the keyboard behavior the APG lists for disclosure navigation:
- Tab and Shift + Tab move between the top level links and buttons, and into an open dropdown’s links.
- Enter or Space on a disclosure button toggles its dropdown.
- Escape closes an open dropdown and puts focus back on its button. With no dropdown open, it closes the outer mobile menu and returns focus to Menu. The desktop list stays visible.
Arrow keys are optional for this pattern. The APG notes that if you add them, they “supplement, but do not replace, tabbing among buttons and links.”
The CSS: visibility, focus, and the current page
/* Hidden until its button says it is open. */
.submenu {
display: none;
}
.submenu-toggle[aria-expanded='true'] + .submenu {
display: block;
}
/* Small screens: the Menu button shows and hides the whole list.
Wide screens: the list is always shown and the button is hidden. */
@media (max-width: 767px) {
.nav-toggle[aria-expanded='false'] + .nav-list {
display: none;
}
}
@media (min-width: 768px) {
.nav-toggle {
display: none;
}
}
/* A focus ring that keyboard users can always see. */
.nav-list a:focus-visible,
.nav-list button:focus-visible,
.nav-toggle:focus-visible {
outline: 3px solid currentColor;
outline-offset: 3px;
}
/* The current page, shown as well as announced. */
.nav-list [aria-current='page'] {
text-decoration: underline;
text-underline-offset: 0.3em;
}
/* Comfortable targets: at least 24 by 24 CSS pixels. */
.nav-list a,
.nav-list button {
display: inline-block;
min-height: 44px;
padding: 10px 12px;
}
/* The skip link: off screen until it is focused. */
.skip-link {
position: absolute;
left: 1rem;
top: -100px;
}
.skip-link:focus {
top: 1rem;
}
Notes on these rules:
- Use
display: none(or thehiddenattribute) for closed menus, notopacity: 0or moving them off screen. Content that is only invisible can still take keyboard focus, so a Tab press lands on links nobody can see. - Never remove the outline without a replacement.
outline: nonewith nothing in its place is one of the most common keyboard accessibility failures.:focus-visibleshows the ring to keyboard users without showing it after every mouse click. - Hover can add to the menu, but cannot be the only way in. If you also open dropdowns on hover, the dropdown must stay open while the pointer moves onto it, and the user must be able to close it without moving the pointer, usually with Escape.
The skip link
A skip link is the first focusable element on the page, and it jumps past
the header and navigation to the main content. Without one, a keyboard user
has to Tab through every menu item on every page before reaching the page’s
content. It is hidden until focused, then appears in the top left corner.
The example above has one: the .skip-link anchor pointing at
<main id="main">.
Marking the current page with aria-current
aria-current="page" tells a screen reader that a link points to the page
the visitor is already on, so it announces “Home, current page, link”. MDN’s
guidance is to mark only one element in a set as current. Set it on the
server or at build time where you can, so it is correct before any script
runs, and give it a visible style, since a sighted user needs the same
information.
Mobile menus
The same structure works at every width. On a small screen, the “Menu”
button shows and hides the whole list, using the same aria-expanded and
aria-controls pairing as the dropdowns. A few points that matter more on
mobile:
- Give the button a visible label if you can. The word “Menu” next to
the icon is clearer to everyone than an icon alone. If the button is
icon-only, it needs
aria-label="Open menu", and the icon itself should be hidden from screen readers witharia-hidden="true". - Do not let a fixed header cover focused items. A sticky header or an open panel that completely hides the link that currently has focus fails WCAG 2.2’s Focus Not Obscured (Minimum) criterion.
- If the open menu covers the whole page and works like a dialog, it needs dialog behavior: focus moves into it on open, stays inside it, and returns to the Menu button on close. A menu that simply pushes the page content down does not need any of that.
WCAG 2.2 success criteria for navigation menus
| Criterion | Level | What it means for a menu |
|---|---|---|
| 2.1.1 Keyboard | A | Every link and dropdown works from the keyboard. |
| 2.1.2 No Keyboard Trap | A | Focus can always leave the menu by keyboard. |
| 2.4.1 Bypass Blocks | A | A skip link (or landmarks and headings) lets users skip the repeated navigation. |
| 2.4.3 Focus Order | A | Focus moves through the menu in an order that makes sense: keep the DOM order and visual order the same. |
| 4.1.2 Name, Role, Value | A | Every control has a name and a correct role, and its state (such as aria-expanded) is exposed and kept up to date. |
| 1.4.13 Content on Hover or Focus | AA | Dropdowns opened by hover or focus can be dismissed, can be hovered, and stay open until the user moves on. |
| 2.4.7 Focus Visible | AA | Keyboard focus is always visible. |
| 2.4.11 Focus Not Obscured (Minimum) | AA | A focused item is never completely hidden by a sticky header or an overlay. New in WCAG 2.2. |
| 2.5.8 Target Size (Minimum) | AA | Links and buttons are at least 24 by 24 CSS pixels, or spaced so they are not crowded. New in WCAG 2.2. |
| 3.2.3 Consistent Navigation | AA | The menu appears in the same relative order on every page. |
For a second route to your pages alongside the menu, add an accessible HTML sitemap. It helps people find content but does not replace keyboard access to this menu.
How to test an accessible navigation menu
Automated tools catch some problems; the keyboard and a screen reader catch the rest. Run through this list on every change to the menu:
- Keyboard only. Put the mouse away. Press Tab from the top of the page. The skip link should appear first. Every link and button should receive a visible focus ring, in the order it appears on screen.
- Dropdowns. Open each one with Enter and with Space. Tab through its links. Press Escape: it should close, and focus should land on its button.
- Screen reader. Use NVDA or JAWS on Windows, or VoiceOver on macOS and iOS. Open the landmarks list and check that the navigation has a sensible name. On each disclosure button, listen for “collapsed” and “expanded” as you toggle it. On the current page’s link, listen for “current page”.
- Zoom and mobile. Zoom the browser to 200% and 400%, and test on a phone. The mobile menu should open, close, and never cover the item that has focus.
- Automated scan. Run axe (the browser extension or axe-core in your test suite) or Lighthouse’s accessibility audit. Fix every violation, then repeat the manual checks, because a clean automated scan does not mean the menu works.
Fixing a typical Bootstrap style navbar
Many menus start from a framework template that looks like this, with ARIA added in the hope of making it accessible:
<nav role="navigation" aria-label="Main Navigation">
<a href="#" role="link" data-nosnippet>Brand</a>
<ul role="menu">
<li><a href="#" role="menuitem" tabindex="0">Home</a></li>
<li>
<a href="#" role="button" aria-haspopup="true" aria-expanded="false">Services</a>
<ul role="menu">...</ul>
</li>
</ul>
</nav>
Every attribute here is either redundant or misleading:
role="navigation"duplicates what<nav>already says, andaria-label="Main Navigation"is announced as “Main Navigation navigation”. Use<nav aria-label="Main">.role="link"on an<a href>adds nothing.role="menu"androle="menuitem"promise arrow key behavior the template never adds. Remove them.tabindex="0"on a link adds nothing: links are focusable already.<a href="#" role="button">should be a real<button type="button">. Replacearia-haspopup="true"witharia-controlspointing at the submenu’s id.data-nosnippetkeeps text out of Google’s search snippets. Google supports it onspan,div, andsectionelements, so on a link it does nothing. It has no effect on accessibility either way.
The result is the example earlier in this guide: fewer attributes, and every one of them true.
Sources
- W3C ARIA Authoring Practices Guide: Example Disclosure Navigation Menu
- W3C ARIA Authoring Practices Guide: Menu and Menubar Pattern
- W3C, Web Content Accessibility Guidelines (WCAG) 2.2
- MDN, ARIA: navigation role
- MDN, aria-haspopup
- MDN, aria-current
- MDN, tabindex
- Google Search Central, data-nosnippet
Frequently asked questions
What ARIA role should a website navigation menu use?
None, in most cases. The HTML nav element already has the navigation role, so role="navigation" is only needed on an element that is not nav. When a page has more than one nav, give each a short aria-label, such as "Main" or "Footer", so screen reader users can tell them apart.
Should I use role="menu" and role="menuitem" for site navigation?
Usually not. The menu and menuitem roles tell assistive technology to expect an application style menu, where arrow keys move between items and Tab leaves the menu. A list of links in a nav element, with disclosure buttons for any dropdowns, matches what site navigation actually does.
What does aria-expanded do on a menu button?
aria-expanded tells assistive technology whether the content a button controls is showing. Set it to false while the menu is closed and true while it is open, and update it every time the button is pressed.
What does aria-current="page" do?
It marks the link that points to the page the visitor is on, so a screen reader announces it as the current page. Put it on only one link in each navigation, and pair it with a visible style so sighted users get the same information.
How do I make a dropdown menu keyboard accessible?
Open and close the submenu with a real button element that carries aria-expanded and aria-controls, so Enter and Space work without extra code. Let Tab move through the links inside, and let Escape close the submenu and return focus to its button.