howto-accordion

Accordions are a pattern to limit visible content by separating it into multiple panels. Any panel can be expanded or collapsed, giving the user control over which content is visible.

By either clicking or by using the arrow keys the user changes the selection of the active heading. With enter or space the active headings can be toggled between expanded and collapsed state.

The headings and the panels have the attributes expanded or collapsed assigned to them depending on their state.

All panels should be styled to be visible if JavaScript is disabled.

See: https://www.w3.org/TR/wai-aria-practices-1.1/#accordion

Demo

Example usage

Code