Accordion
A collapsible component for displaying content in a vertical stack.
Anatomy
<Accordion.Root>
<Accordion.Item>
<Accordion.ItemTrigger>
<Accordion.ItemIndicator />
</Accordion.ItemTrigger>
<Accordion.ItemContent />
</Accordion.Item>
</Accordion.Root>
Examples
Default Value
Set defaultValue to choose which items start expanded.
Controlled
Use value and onValueChange to control the expanded items.
Root Provider
Use RootProvider with the useAccordion hook to access the state and methods from outside the component.
Collapsible
Set collapsible to let users close every panel.
Multiple
Set multiple to let several panels stay open at once.
Horizontal
The accordion is vertical by default. Set orientation="horizontal" for a horizontal layout.
Lazy Mount
Set lazyMount to render content only once an item expands. Add unmountOnExit to remove it again on collapse.
Context
Use Accordion.Context or useAccordionContext to access the accordion state.
Item State
Use Accordion.ItemContext or useAccordionItemContext to access an item's state.
Guides
Content Animation
Animate the content size with the --height and --width CSS variables:
@keyframes slideDown {
from {
opacity: 0.01;
height: 0;
}
to {
opacity: 1;
height: var(--height);
}
}
@keyframes slideUp {
from {
opacity: 1;
height: var(--height);
}
to {
opacity: 0.01;
height: 0;
}
}
[data-accordion-item-content][data-state='open'] {
animation: slideDown 250ms ease-in-out;
}
[data-accordion-item-content][data-state='closed'] {
animation: slideUp 200ms ease-in-out;
}
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
collapsible | true | booleanWhether an accordion item can be closed after it has been expanded. |
defaultValue | string[]The initial value of the expanded accordion items. Use when you don't need to control the value of the accordion. | |
disabled | booleanWhether the accordion items are disabled | |
hiddenUntilFound | booleanWhether closed items stay searchable with the browser's find-in-page. Uses `hidden="until-found"`, and expands an item when a match is found inside it. | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the accordion. Useful for composition. | |
lazyMount | false | booleanWhether to enable lazy mounting |
multiple | false | booleanWhether multiple accordion items can be expanded at the same time. |
onFocusChange | (details: FocusChangeDetails) => voidThe callback fired when the focused accordion item changes. | |
onValueChange | (details: ValueChangeDetails) => voidThe callback fired when the state of expanded/collapsed accordion items changes. | |
orientation | 'vertical' | 'horizontal' | 'vertical'The orientation of the accordion items. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
unmountOnExit | false | booleanWhether to unmount on exit. |
value | string[]The controlled value of the expanded accordion items. |
| Attribute | Description |
|---|---|
[data-accordion-root] | <uid> |
[data-orientation] | The orientation of the accordion |
ItemContent
Renders a <div> element.
| Prop | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-accordion-item-content] | <uid> |
[data-value] | The value of the item |
[data-state] | "open" | "closed" |
[data-disabled] | Present when disabled |
[data-focus] | Present when focused |
[data-orientation] | The orientation of the item |
ItemHeader
Defines the <h3> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<AccordionItemHeaderState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-accordion-item-header] | <uid> |
[data-state] | "open" | "closed" |
[data-focus] | Present when focused |
[data-disabled] | Present when disabled |
[data-orientation] | The orientation of the item |
ItemIndicator
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-accordion-item-indicator] | <uid> |
[data-state] | "open" | "closed" |
[data-disabled] | Present when disabled |
[data-focus] | Present when focused |
[data-orientation] | The orientation of the item |
Item
Renders a <div> element.
| Prop | Default | Type |
|---|---|---|
value | stringThe value of the accordion item. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
disabled | booleanWhether the accordion item is disabled. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<AccordionItemState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-accordion-item] | <uid> |
[data-state] | "open" | "closed" |
[data-focus] | Present when focused |
[data-disabled] | Present when disabled |
[data-orientation] | The orientation of the item |
ItemTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-accordion-item-trigger] | <uid> |
[data-controls] | |
[data-orientation] | The orientation of the item |
[data-state] | "open" | "closed" |
[data-focus] | Present when focused |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseAccordionReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
lazyMount | false | booleanWhether to enable lazy mounting |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
unmountOnExit | false | booleanWhether to unmount on exit. |
Context
API
| Property | Type |
|---|---|
focusedValue | string | nullThe value of the focused accordion item. |
value | string[]The value of the accordion |
setValue | (value: string[], reason?: ValueChangeReason) => voidSets the value of the accordion |
getItemState | (props: ItemProps) => ItemStateReturns the state of an accordion item. |
getItemHeaderProps | (props: ItemProps) => T["element"]Returns props for the item heading wrapper around the trigger. Render this as a heading element (e.g. `h3`) per the WAI-ARIA accordion pattern. |
Accessibility
Follows the Accordion WAI-ARIA design pattern.
Keyboard Support
| Key | Description |
|---|---|
Space | When focus is on an trigger of a collapsed item, the item is expanded |
Enter | When focus is on an trigger of a collapsed section, expands the section. |
Tab | Moves focus to the next focusable element |
Shift + Tab | Moves focus to the previous focusable element |