Skip to contents

Accordion

A set of collapsible panels with headings.

View as Markdown

Anatomy

Import the component and assemble its parts:

Anatomy

Examples

Open multiple panels

You can set up the accordion to allow multiple panels to be open at the same time using the multiple prop.

API reference

Root

Groups all parts of the accordion. Renders a <div> element.

defaultValueValue[]
Description

The uncontrolled value of the item(s) that should be initially expanded.

To render a controlled accordion, use the value prop instead.

Type
valueValue[]
Name
Description

The controlled value of the item(s) that should be expanded.

To render an uncontrolled accordion, use the defaultValue prop instead.

Type
onValueChangefunction
Description

Event handler called when an accordion item is expanded or collapsed. Provides the new value as an argument.

Type
hiddenUntilFoundbooleanfalse
Description

Allows the browser’s built-in page search to find and expand the panel contents.

Overrides the keepMounted prop and uses hidden="until-found" to hide the element without removing it from the DOM.

Type
Default
false
loopFocusbooleantrue
Description

Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.

Type
Default
true
multiplebooleanfalse
Description

Whether multiple items can be open at the same time.

Type
Default
false
disabledbooleanfalse
Description

Whether the component should ignore user interaction.

Type
Default
false
orientationOrientation'vertical'
Description

The visual orientation of the accordion. Controls whether roving focus uses left/right or up/down arrow keys.

Type
Default
'vertical'
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
keepMountedbooleanfalse
Description

Whether to keep the element in the DOM while the panel is closed. This prop is ignored when hiddenUntilFound is used.

Type
Default
false
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-orientation

Indicates the orientation of the accordion.

data-disabled

Present when the accordion is disabled.

AttributeDescription
data-orientation

Indicates the orientation of the accordion.

data-disabled

Present when the accordion is disabled.

Accordion.Root.PropsHide

Re-Export of Root props as AccordionRootProps

Accordion.Root.StateHide

Accordion.Root.ChangeEventReasonHide

Accordion.Root.ChangeEventDetailsHide

Accordion.Root.ValueHide

Item

Groups an accordion header with the corresponding panel. Renders a <div> element.

valueany
Name
Description

A unique value that identifies this accordion item. If no value is provided, a unique ID will be generated automatically. Use when controlling the accordion programmatically, or to set an initial open state.

Type
Example
onOpenChangefunction
Description

Event handler called when the panel is opened or closed.

Type
disabledbooleanfalse
Description

Whether the component should ignore user interaction.

Type
Default
false
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-open

Present when the accordion item is open.

data-disabled

Present when the accordion item is disabled.

data-index

Indicates the index of the accordion item.

AttributeDescription
data-open

Present when the accordion item is open.

data-disabled

Present when the accordion item is disabled.

data-index

Indicates the index of the accordion item.

Accordion.Item.PropsHide

Re-Export of Item props as AccordionItemProps

Accordion.Item.StateHide

Accordion.Item.ChangeEventReasonHide

Accordion.Item.ChangeEventDetailsHide

A heading that labels the corresponding panel. Renders an <h3> element.

classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-open

Present when the accordion item is open.

data-disabled

Present when the accordion item is disabled.

data-index

Indicates the index of the accordion item.

AttributeDescription
data-open

Present when the accordion item is open.

data-disabled

Present when the accordion item is disabled.

data-index

Indicates the index of the accordion item.

Accordion.Header.PropsHide

Re-Export of Header props as AccordionHeaderProps

Accordion.Header.StateHide

Trigger

A button that opens and closes the corresponding panel. Renders a <button> element.

nativeButtonbooleantrue
Description

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).

Type
Default
true
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-panel-open

Present when the accordion panel is open.

data-disabled

Present when the accordion item is disabled.

AttributeDescription
data-panel-open

Present when the accordion panel is open.

data-disabled

Present when the accordion item is disabled.

Accordion.Trigger.PropsHide

Re-Export of Trigger props as AccordionTriggerProps

Accordion.Trigger.StateHide

Panel

A collapsible panel with the accordion item contents. Renders a <div> element.

hiddenUntilFoundbooleanfalse
Description

Allows the browser’s built-in page search to find and expand the panel contents.

Overrides the keepMounted prop and uses hidden="until-found" to hide the element without removing it from the DOM.

Type
Default
false
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
keepMountedbooleanfalse
Description

Whether to keep the element in the DOM while the panel is closed. This prop is ignored when hiddenUntilFound is used.

Type
Default
false
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-open

Present when the accordion panel is open.

data-orientation

Indicates the orientation of the accordion.

data-disabled

Present when the accordion item is disabled.

data-index

Indicates the index of the accordion item.

data-starting-style

Present when the panel is animating in.

data-ending-style

Present when the panel is animating out.

AttributeDescription
data-open

Present when the accordion panel is open.

data-orientation

Indicates the orientation of the accordion.

data-disabled

Present when the accordion item is disabled.

data-index

Indicates the index of the accordion item.

data-starting-style

Present when the panel is animating in.

data-ending-style

Present when the panel is animating out.

--accordion-panel-height

The accordion panel’s height.

--accordion-panel-width

The accordion panel’s width.

CSS VariableDescription
--accordion-panel-height

The accordion panel’s height.

--accordion-panel-width

The accordion panel’s width.

Accordion.Panel.PropsHide

Re-Export of Panel props as AccordionPanelProps

Accordion.Panel.StateHide