Accordion

A collapsible component for displaying content in a vertical stack.

Loading...

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.

AttributeDefaultType
asChild
boolean

Use 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.
collapsibletrue
boolean

Whether 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
boolean

Whether the accordion items are disabled

hiddenUntilFound
boolean

Whether 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'
HideMode

How 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
string

The unique identifier of the machine.

ids
ElementIds

The ids of the elements in the accordion. Useful for composition.

lazyMountfalse
boolean

Whether to enable lazy mounting

multiplefalse
boolean

Whether multiple accordion items can be expanded at the same time.

onFocusChange
(details: FocusChangeDetails) => void

The callback fired when the focused accordion item changes.

onValueChange
(details: ValueChangeDetails) => void

The 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.

unmountOnExitfalse
boolean

Whether to unmount on exit.

value
string[]

The controlled value of the expanded accordion items.

AttributeDescription
[data-accordion-root]<uid>
[data-orientation]The orientation of the accordion

ItemContent

Renders a <div> element.

PropDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

PropDefaultType
value
string

The value of the accordion item.

asChild
boolean

Use 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
boolean

Whether 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
value
UseAccordionReturn

asChild
boolean

Use 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'
HideMode

How 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+.

lazyMountfalse
boolean

Whether 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.

unmountOnExitfalse
boolean

Whether to unmount on exit.

Context

API

PropertyType
focusedValue
string | null

The value of the focused accordion item.

value
string[]

The value of the accordion

setValue
(value: string[], reason?: ValueChangeReason) => void

Sets the value of the accordion

getItemState
(props: ItemProps) => ItemState

Returns 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

KeyDescription
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