Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 38 ยท Forms and Dynamic Content

Accessible Tabs, Accordions and Menus

Build accessible tabs with roving tabindex and arrow keys, accordions with details or aria-expanded buttons, and disclosure navigation, with working demos.

Custom widgets are where ARIA earns its keep, and also where it is most often misused. Before you build one, ask whether plain HTML already does the job. Often it does: a list of links is navigation, a <details> is an accordion, and a <select> is a menu of choices. Reach for ARIA tabs and menus only when you truly need that interaction model.

This lesson shows three patterns and the keyboard behavior users expect from them.

Accordions and disclosures

An accordion is a list of headings that each toggle a panel. The simplest accessible version uses native <details> and <summary>: keyboard (Enter and Space), expanded state, and screen reader announcements all come for free.

HTML
<details>
  <summary>Shipping times</summary>
  <p>Orders arrive in 3 to 5 working days.</p>
</details>

To build your own, use a real button inside a heading and aria-expanded:

Accordion with buttons

Key points: a <button> (not a div), aria-expanded that matches what is shown, hidden on the collapsed panel so it leaves the accessibility tree. Skip role="region" if you have many panels; it clutters the landmark list.

Tabs

Tabs show one panel of several at a time. The ARIA tabs pattern has strong keyboard expectations that differ from plain Tab-key navigation:

  • The tab list is one stop in the Tab order. Arrow keys move between tabs, Home and End go to the first and last.
  • Only the selected tab is tabindex="0"; others are tabindex="-1" (roving tabindex).
  • Roles: tablist, tab (aria-selected, aria-controls) and tabpanel (aria-labelledby).
  • Pressing Tab from a tab moves into the panel.

Tabs are the right choice only for content that is truly alternate views of one thing. For site sections, use links.

Keyboard-operable tabs

This version activates a tab as soon as it receives focus ("automatic activation"). For panels that are slow to load, use manual activation: arrows only move focus, and Enter or Space selects.

The ARIA menu role is for application-style menus (like a desktop File menu). It changes how screen readers behave and demands a lot of keyboard code. A website navigation with a dropdown is better built as a disclosure: a list of links, with a button that shows or hides a sub-list.

HTML
<nav aria-label="Main">
  <ul>
    <li><a href="/">Home</a></li>
    <li>
      <button type="button" aria-expanded="false" aria-controls="sub">Products</button>
      <ul id="sub" hidden>
        <li><a href="/laptops">Laptops</a></li>
        <li><a href="/phones">Phones</a></li>
      </ul>
    </li>
  </ul>
</nav>

Behavior to provide: the button toggles with Enter or Space; Escape closes the open sub-list and returns focus to the button; Tab moves through the links naturally. Avoid opening menus on hover only, because keyboard and touch users cannot hover. If you do show on hover, follow the 1.4.13 rules from the dialogs lesson.

Choosing a pattern

flowchart TD
  A["Show or hide content"] --> B{"One panel at a time, peer views?"}
  B -- "yes" --> C["Tabs: tablist, arrow keys"]
  B -- "no" --> D{"A few independent sections?"}
  D -- "yes" --> E["Accordion: details or aria-expanded buttons"]
  D -- "no" --> F{"Site navigation with sub-links?"}
  F -- "yes" --> G["Disclosure nav: button plus link list"]
  F -- "no" --> H["Plain content"]

Start with the simplest native element that fits.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which attribute tells assistive technology whether an accordion panel is open?

    aria-expanded=true or false on the toggle button exposes the state.
  2. 2. In the tabs pattern, which tabs have tabindex="0"?

    Roving tabindex keeps the tab list as a single Tab stop; arrow keys move between tabs.
  3. 3. Which is the recommended pattern for a website dropdown navigation?

    Disclosure navigation keeps real links and standard Tab behavior, and is much simpler to get right than role=menu.
  4. 4. What is the simplest accessible accordion?

    details and summary give keyboard support and state announcements with no JavaScript.

Summary

  • Use native <details> when possible; otherwise buttons with aria-expanded and aria-controls.
  • Tabs need tablist, tab, tabpanel, roving tabindex and arrow, Home and End keys.
  • Build site dropdowns as disclosure navigation with real links.
  • Never rely on hover alone, and keep focus management predictable.

Next: Automated Testing with axe and Lighthouse