Accordion Pattern Overview and Structure
You'll learn: What accordions are, when to use them, and how to structure them semantically in HTML.
What Is an Accordion?
An accordion is a vertically stacked set of interactive headers that reveal or hide associated content panels. Think of it like a physical accordion instrument that expands and collapses—each section can be opened to show its content or closed to save space. Only the headers remain visible when panels are collapsed.
When to Use Accordions
Accordions work best when you have related content sections that users don't need to see simultaneously. Common use cases include:
- FAQs: Each question is a header; answers are hidden until clicked
- Settings panels: Group related options without overwhelming the interface
- Long forms: Break complex forms into manageable sections
- Table of contents: Show document structure without cluttering the page
Accordions help conserve screen space and reduce cognitive load by showing only what's relevant at the moment.
Basic HTML Structure
An accordion consists of repeating units, each containing:
- Header (button): The always-visible, clickable element that controls expansion
- Panel (region): The content area that shows/hides based on the header state
The header should be a <button> (not a link!) because it triggers an action rather than navigating. The panel is typically a <div> or <section> that contains the hidden content.
Each accordion item is independent, though they're grouped together visually and semantically. Unlike tabs where content panels are siblings at the same level, accordion panels are paired directly with their controlling headers.
Key Takeaway: Accordions are vertically stacked header-panel pairs that expand/collapse to show related content sections, built with interactive buttons controlling associated content regions—perfect for organizing information users explore selectively.