Skip to main content

How to fix keyboard navigation problems

If you cannot complete a task on a website using only the keyboard, many people cannot complete it at all. That includes people who cannot use a mouse, people who use a switch or other assistive device, and power users who simply prefer the keyboard.

This guide explains what "keyboard accessible" means, the WCAG criteria behind it, and how to fix the failures I see most often. It is general information, not legal advice.

What keyboard access means

Every action that a mouse or a finger can perform should also be possible with the keys a keyboard already has: Tab and Shift+Tab to move, Enter or Space to activate, Escape to close, and arrows where a component reasonably expects them (a tab list, a select, a menu). Focus should move in a sensible order, should be visible, and should never disappear into a trap.

  • 2.1.1 Keyboard — functionality can be operated through a keyboard, with limited exceptions for paths that depend on free-form drawing or similar input.
  • 2.1.2 No Keyboard Trap — keyboard focus can be moved away from a component using the keyboard.
  • 2.4.3 Focus Order — the tab order preserves meaning and operability.
  • 2.4.7 Focus Visible — it is possible to see where the keyboard focus is. See visible focus styles.

Failures I see constantly

A div or span with a click handler. It may look like a button, but it is skipped in the tab order and does not respond to Enter or Space unless you rebuild that behavior by hand. Use a real button or a real a href.

Menus that only open on hover. Keyboard and touch users never see the items. Open the menu on focus as well as hover, or provide a button that expands it, and let Escape close it.

A focus order that jumps around the page. This often comes from CSS that rearranges the visual layout, or from positive tabindex values used to "fix" the order. Put the HTML in the order people would expect, and use CSS for layout.

Hidden content that is still in the tab order. Off-screen carousels, closed mobile menus, and display tricks can leave hidden links focusable. If it is not visible, it generally should not be tabbable (hidden, display: none, or inert, depending on the case).

Dialogs that do not manage focus. A modal should move focus into the dialog, keep Tab cycling inside it while it is open, close on Escape, and return focus to the control that opened it. A dialog that you cannot leave with the keyboard is a trap. A dialog that never takes focus is easy to miss.

How to fix it, step by step

1. Start with real HTML controls

<button type="button">Filter by size</button>
<a href="/cart">View cart</a>

Do not do this:

<div onclick="addToCart()">Add to cart</div>

If you truly must use a non-semantic element, you will have to add tabindex="0", a role, a name, and keyboard handlers. That is more work and more ways to fail. A native control is better.

2. Make sure every interactive control can be reached and activated

Tab through the page. Every button, link, tab, and form field should stop and should work with Enter or Space as appropriate. Links activate with Enter. Buttons generally activate with Enter and Space.

3. Keep the tab order logical

Avoid tabindex="1" and other positive values. tabindex="0" can include a custom control in the natural order. tabindex="-1" makes something focusable by script (useful for a dialog heading or a skip target) without putting it in the tab order.

4. Prevent traps, especially in modals, lightboxes, and players

When a dialog opens, move focus to a sensible place inside it (often the heading, if it is focusable with tabindex="-1", or the first field). While it is open, Tab should not land on the page behind it. Escape should close it. Then send focus back to the button that opened it.

Embedded videos, chat widgets, and cookie banners are frequent trap sources. Test them, and test the close button.

5. Make focus visible

If you cannot see the ring, you cannot tell where you are. Do not set outline: none without a clear replacement. The next guide covers this in detail.

A simple manual test

  1. Put the mouse aside.
  2. Start at the top of the page. Use Tab and Shift+Tab through the header, the main content, the forms, and the footer.
  3. Open menus, dialogs, carousels, and the cookie banner. Close them with Escape where that is expected.
  4. Confirm the skip link works and that focus lands in the main content.
  5. If focus vanishes, or you cannot leave a widget, you have found a defect.

Mistakes to avoid

  • Removing outlines globally in CSS
  • Using tabindex to force a visual order the HTML does not have
  • Leaving disabled-looking controls in the tab order with no explanation
  • Opening a pop-up without moving focus into it
  • Closing a modal and leaving focus at the top of the document

Notes for common platforms

WordPress. Check the theme menu, especially mega menus and sticky headers, plus page-builder pop-ups and sliders.

Shopify. Cart drawers, predictive search, and app-injected quick-view modals are the usual trouble spots.

Webflow. Interactions that open dropdowns on hover need an equivalent for focus and keyboard. Test published pages, not only the designer canvas.

React. Custom components should use official, well-tested patterns (for example, dialogs that follow the APG ideas) rather than a clickable div. After a client-side route change, consider where focus should go so a screen-reader user is not left in the old place.

Official references: WCAG 2.1 2.1.1, 2.1.2, 2.4.3, and 2.4.7. For help reviewing a small-business site, text 910-931-0978 or see my resources page.