Course contentsShow
← Web Development
Lesson 1183 of 2,98221. Accessible ComponentsFree lesson

Keyboard Support for Accordions

Enabling keyboard navigation between accordion headers and proper focus management when expanding.

Keyboard Support for Accordions

You'll learn how to enable users to navigate and control accordion components using only their keyboard.

What It Is

Keyboard support for accordions means implementing navigation between headers using arrow keys and expanding/collapsing panels with Enter or Space. This makes accordions usable for people who can't or don't use a mouse, including screen reader users and those with motor disabilities.

Think of an accordion like a vertical stack of folders. With proper keyboard support, you can move between folder tabs using arrow keys and open/close them with a key press—no mouse needed.

The Navigation Pattern

Accordion headers should respond to these keyboard interactions:

  • Tab: Moves focus into and out of the accordion group
  • Arrow Down/Up: Moves focus between accordion headers
  • Enter or Space: Toggles the focused header's panel open or closed
  • Home/End (optional): Jump to first or last header

When a user presses an arrow key, focus should move to the next or previous header in the sequence. If they're on the last header and press Down, focus wraps to the first header (and vice versa).

Focus Management

When you expand a panel, focus typically stays on the header button—not the content panel. This is different from tabs! The header remains the control point, allowing users to quickly collapse it or navigate to other headers without getting trapped in the content.

Use JavaScript to listen for keydown events on accordion headers, detect arrow keys, and programmatically move focus using .focus() on the appropriate header element.

Key Takeaway: Accordion keyboard support requires arrow key navigation between headers, Enter/Space to toggle panels, and keeping focus on the header button—not the content—when expanding.