Navigation is the one component every visitor uses, and it is also the one I most often find broken for keyboard and screen-reader users. The good news is that making it accessible is not hard. It just needs a little care.
Start with a real button
The menu toggle should be a button element, not a div with a click handler. Buttons are focusable, respond to Enter and Space, and are announced correctly by screen readers, all for free.
Give it a clear label, either visible text like "Menu" or an aria-label, and connect it to the menu with aria-controls.
Tell everyone whether it is open
Use aria-expanded on the button and update it every time the menu opens or closes. Screen-reader users hear "Menu, collapsed" or "Menu, expanded" and know exactly where they stand.
- Set aria-expanded to false by default.
- Toggle it in the same function that shows or hides the menu.
- Hide the closed menu with the hidden attribute, not just opacity, so links inside it can't be tabbed to.
Let people get out
Pressing Escape should close the menu and return focus to the toggle button. It is a small detail that keyboard users notice immediately when it is missing.
Make focus visible
Never remove focus outlines without replacing them. A clear focus style, a thick outline in your accent color, helps everyone who navigates by keyboard, including power users who simply prefer it.
If you can use your whole site with only the Tab, Enter and Escape keys, you are most of the way there.
Test it yourself
Unplug your mouse for ten minutes and try to use your own site. Then turn on VoiceOver or NVDA and do it again. You will find more issues in those twenty minutes than in any automated report.