Accordion
Accordion display a list of high-level options that can expand/collapse to reveal more information.
Installation
The above command is for individual installation only. You may skip this step if @nextui-org/react is already installed globally.
Import
NextUI exports 2 accordion-related components:
- Accordion: The main component to display a list of accordion items.
- AccordionItem: The item component to display a single accordion item. This uses the Disclosure component internally.
Usage
With Subtitle
Expand multiple items
If you set allowsMultipleExpanded to true, then the Accordion will allow multiple items to be expanded at the same time.
Compact
If you set isCompact to true, the Accordion will be displayed in a compact style.
Variants
Accordion has 4 variants: light, shadow, bordered and splitted.
Light variant
Shadow variant
Bordered variant
Splitted variant
Default expanded keys
If you want to expand some items by default, you can set the defaultExpandedKeys property to an array of keys.
Disabled keys
If you want to disable some items, you can set the disabledKeys property to an array of keys.
Start content
If you want to display some content before the accordion items, you can set the startContent property.
Custom Indicator
Accordion items have a property called indicator. You can use it to customize the open/close indicator.
The indicator can be also a function, which receives the isExpanded, isDisabled and the default indicator as parameters.
Custom Motion
Accordion's animation can be changed by upadting the content style.
Controlled
Accordion is a controlled component, which means you need to control the selectedKeys property by yourself.
Accordion Item Slots
- base: The accordion item wrapper.
- heading: The accordion item heading. It contains the indicatorand thetitle.
- trigger: The button that open/close the accordion item.
- titleWrapper: The wrapper of the titleandsubtitle.
- title: The accordion item title.
- subtitle: The accordion item subtitle.
- startContent: The content before the accordion item.
- indicator: The element that indicates the open/close state of the accordion item.
- content: The accordion item content.
Custom Accordion Styles
You can customize the accordion and accordion items styles by using any of the following properties:
- className: The class name of the accordion. Modify the accordion wrapper styles.(Accordion)
- itemClasses: The class names of the accordion items. Modify all accordion items styles at once. (Accordion)
- classNames: The class names of the accordion items. Modify each accordion item styles separately. (AccordionItem)
Here's an example of how to customize the accordion styles:
Data Attributes
Disclosure in the AccordionItem has the following attributes on the base element:
- data-expanded: Whether the accordion item is open.
- data-hover: When the accordion item is being hovered. Based on useHover.
- data-focus: When the accordion item is being focused. Based on useFocusRing.
- data-focus-visible: When the accordion item is being focused with the keyboard. Based on useFocusRing.
- data-disabled:
When the accordion item is disabled. Based on isDisabledprop.
- data-pressed: When the accordion item is pressed. Based on usePress.
Accessibility
- Keyboard event support for Space, Enter, Tab and Shift + Tab keys.
- Keyboard focus management and cross browser normalization.
- aria-expandedattribute for the accordion item.
- aria-disabledattribute for the accordion item.
- aria-controlsattribute for the accordion item.
API
Accordion Props
| Prop | Type | Default | 
| children |  | |
| variant |  | "light" | 
| allowsMultipleExpanded |  | |
| isCompact |  | false | 
| isDisabled |  | false | 
| showDivider |  | true | 
| dividerProps |  | |
| hideIndicator |  | false | 
| disableAnimation |  | false | 
| disableIndicatorAnimation |  | false | 
| keepContentMounted |  | false | 
| fullWidth |  | true | 
| motionProps |  | |
| disabledKeys |  | |
| expandedKeys |  | |
| defaultExpandedKeys |  | 
Accordion Events
| Prop | Type | Default | 
| onExpandedChange |  | 
Accordion Item Props
| Prop | Type | Default | 
| children |  | |
| title |  | |
| subtitle |  | |
| indicator |  | |
| startContent |  | |
| isCompact |  | false | 
| isDisabled |  | false | 
| keepContentMounted |  | false | 
| hideIndicator |  | false | 
| disableAnimation |  | false | 
| disableIndicatorAnimation |  | false | 
| HeadingComponent |  | "h2" | 
| classNames |  | 
Accordion Item Events
| Prop | Type | Default | 
| onFocus |  | |
| onBlur |  | |
| onFocusChange |  | |
| onKeyDown |  | |
| onKeyUp |  | |
| onPress |  | |
| onPressStart |  | |
| onPressEnd |  | |
| onPressChange |  | |
| onPressUp |  | |
| onClick |  | 
Types
Accordion Item Indicator Props
Accordion Item classNames
- This classNames are propagated to the internal disclosure component.

