Overview
Accordion is a vertically stacked set of interactive headings that each reveal a section of content. It’s built on top of the Collapsible primitive.Features
- Full keyboard navigation
- Supports horizontal and vertical orientation
- Can expand one or multiple items at a time
- Can be controlled or uncontrolled
- Collapsible items can optionally be disabled
Installation
Anatomy
API Reference
Root
Contains all the parts of an accordion.Determines whether one or multiple items can be opened at the same time.
The controlled value of the item to expand when
type is "single". Must be used in conjunction with onValueChange.The value of the item to expand when initially rendered and
type is "single". Use when you do not need to control the state.Event handler called when the expanded state changes and
type is "single".The controlled value of the items to expand when
type is "multiple". Must be used in conjunction with onValueChange.The value of the items to expand when initially rendered and
type is "multiple". Use when you do not need to control the state.Event handler called when the expanded state changes and
type is "multiple".When
type is "single", allows closing content when clicking trigger for an open item.When
true, prevents the user from interacting with the accordion and all its items.The orientation of the accordion.
The reading direction of the accordion. If omitted, inherits globally from
DirectionProvider or assumes LTR (left-to-right) reading mode.Item
Contains all the parts of a collapsible section.A unique value for the item.
When
true, prevents the user from interacting with the item.Header
Wraps anAccordion.Trigger. Use the asChild prop to customize the element.
Trigger
Toggles the collapsed state of its associated item. It should be nested inside anAccordion.Header.
Content
Contains the collapsible content for an item.Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
Examples
Single Item
Multiple Items
Data Attributes
Root
data-orientation-"vertical"or"horizontal"
Item
data-state-"open"or"closed"data-disabled- Present when disableddata-orientation-"vertical"or"horizontal"
Header
data-state-"open"or"closed"data-disabled- Present when disableddata-orientation-"vertical"or"horizontal"
Trigger
data-state-"open"or"closed"data-disabled- Present when disableddata-orientation-"vertical"or"horizontal"
Content
data-state-"open"or"closed"data-disabled- Present when disableddata-orientation-"vertical"or"horizontal"
CSS Variables
Content
--radix-accordion-content-height- The height of the content when open--radix-accordion-content-width- The width of the content when open
Keyboard Interactions
Space- When focus is on an Accordion.Trigger, opens associated contentEnter- When focus is on an Accordion.Trigger, opens associated contentTab- Moves focus to the next focusable elementShift + Tab- Moves focus to the previous focusable elementArrowDown- Moves focus to the next Accordion.Trigger (vertical orientation)ArrowUp- Moves focus to the previous Accordion.Trigger (vertical orientation)ArrowRight- Moves focus to the next Accordion.Trigger (horizontal orientation)ArrowLeft- Moves focus to the previous Accordion.Trigger (horizontal orientation)Home- Moves focus to the first Accordion.TriggerEnd- Moves focus to the last Accordion.Trigger