Accordion
Default Accordion
Use Arrow Up/Down to navigate between headers, Home/End to jump to first/last, and Enter/Space to toggle sections.
Separated Cards
Minimal Style
---const items = [ { title: 'Section 1', content: '<p>Content for Section 1...</p>', open: true }, { title: 'Section 2', content: '<p>Content for Section 2...</p>' }]---
<!-- Default accordion --><Accordion items={items} />
<!-- Separated cards variant --><Accordion items={items} variant="separated" allowMultiple={true}/>
<!-- Minimal variant --><Accordion items={items} variant="minimal" size="sm"/>npx ui-gen add accordionProperties
items
type: AccordionItem[]
required: true
Array of accordion items. Each item should have:
title(string) - The header textcontent(string) - HTML content (can include markup)open(boolean, optional) - Whether the item starts expandeddisabled(boolean, optional) - Whether the item is disabled
variant
type: string
options: default, separated, minimal
default: default
default- Single bordered container with internal dividersseparated- Individual cards with spacing between themminimal- Clean style with minimal borders
size
type: string
options: sm, md, lg
default: md
Controls the text size and padding of the accordion.
allowMultiple
type: boolean
default: false
When true, multiple sections can be expanded simultaneously. When false, expanding one section closes others.
collapsible
type: boolean
default: true
When false, at least one section must always remain open (requires at least one item to start with open: true).
Accessibility Features
This Accordion component is fully WCAG 2.1 AA compliant:
⌨️ Keyboard Navigation
- Arrow Up/Down - Navigate between accordion headers
- Home/End - Jump to first/last header
- Enter/Space - Toggle the focused section
- Tab - Move focus to the next focusable element
🎯 ARIA Support
aria-expandedindicates whether each section is open/closedaria-controlslinks headers to their content regionsrole="region"on content areas for screen reader navigationaria-labelledbyconnects content to headers
📱 Screen Reader Support
- Semantic HTML structure with proper heading levels
- Descriptive button labels
- Content regions are properly announced
- State changes are communicated
🎨 Visual Accessibility
- High contrast focus indicators
- Clear visual hierarchy
- Consistent spacing and typography
- Smooth animations that respect
prefers-reduced-motion
Examples
Basic Accordion
---const items = [ { title: 'Question 1', content: '<p>Answer to question 1</p>' }, { title: 'Question 2', content: '<p>Answer to question 2</p>', open: true }]---<Accordion items={items} />Multiple Sections Open
<Accordion items={items} allowMultiple={true} variant="separated"/>Minimal FAQ Style
<Accordion items={faqItems} variant="minimal" size="sm" collapsible={false}/>