Accessible Tabs and Accordions
Tabs and accordions help organize long pages by showing only part of the content at a time. Done well, they are tidy and useful. Done badly, they trap keyboard users and hide content from screen readers. The right choice depends on your content.
Accordion or tabs?
- Accordion: a stack of headings that expand to reveal content. Good for FAQs and long lists where people may read several items.
- Tabs: a row of labels that switch between panels. Good for parallel views of the same kind of content, such as product details, where only one panel is read at a time.
If visitors need to compare or read everything, do not hide it. Search engines and users may also miss content that is hidden by default. See FAQ pages and SEO.
Building accessible accordions
- Use real headings for each item so that screen reader users can navigate by heading. See how to use headings for SEO.
- Put a button inside each heading to toggle the panel. Buttons work with Enter and Space automatically.
- Expose the state. Use
aria-expandedset to true or false on the button, and connect it to its panel witharia-controls. - Hide closed panels properly so that their contents cannot be reached by keyboard or read aloud. Using
hiddenordisplay: nonedoes this. - Show clearly what is clickable. An icon such as a chevron helps, and the whole header should be the target.
The native details and summary elements provide a simple accordion with good built-in behavior and little code. They are worth considering first. Check their support and styling in the browsers you need.
Building accessible tabs
The tabs pattern is more complex and has specific expectations:
- A container with
role="tablist", tabs withrole="tab", and panels withrole="tabpanel" - The selected tab is marked with
aria-selected="true", and each tab is linked to its panel - Keyboard: Tab moves focus into the tab list, arrow keys move between tabs, and Tab moves into the active panel
- Only the active tab is in the page's tab order
If you use ARIA roles, you take on the responsibility of providing the keyboard behavior. A wrong implementation is worse than a simple one. See ARIA basics: when to use ARIA.
A simpler option for tabs
If your tabs are really navigation between pages, use links. If the content is short, show it all with headings.
Focus and visibility
Focus styles must be clear on every tab and header. See accessible focus styles. Make sure the active state does not rely on color alone. See color blindness and web design.
Mobile
Tabs can overflow small screens. Consider turning them into an accordion on mobile, and make targets large enough. See touch target sizes for mobile.
Test it
Use only the keyboard, then try a screen reader. Check that state changes are announced. See how to test with a screen reader.
Common mistakes
- Clickable divs without roles or keyboard support
- State shown only visually
- Hiding important content by default
- Using ARIA roles without the matching behavior
Many of these components are triggered by clicking something, which brings up the question of what to use: accessible buttons vs links.