Accordion

Accordions display a list of high-level options that can expand/collapse to reveal more information.

    SourceTheme Source@chakra-ui/accordion

Import#

Chakra UI exports 5 accordion-related components.

  • Accordion.Root: The wrapper that uses cloneElement to pass props to Accordion.Item children.
  • Accordion.Item: A single accordion item.
  • Accordion.Trigger: The button that toggles the expand/collapse state of the accordion item. This button must be wrapped in an element with role heading.
  • Accordion.Content: The container for the details to be revealed.
  • Accordion.Icon: A chevron-down icon that rotates based on the expanded/collapsed state
import { Accordion } from '@chakra-ui/react'

Usage#

By default, only one item may be expanded and it can only be collapsed again by expanding another.

Accordion now supports keyboard navigation between accordion buttons. Pressing the up and down arrow keys will move focus between accordion buttons.

<Accordion.Root>
<Accordion.Item>
<h2>
<Accordion.Trigger>
<Box as='span' flex='1' textAlign='left'>
Section 1 title
</Box>
<Accordion.Icon />
</Accordion.Trigger>
</h2>
<Accordion.Content pb={4}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item>
<h2>
<Accordion.Trigger>
<Box as='span' flex='1' textAlign='left'>
Section 2 title
</Box>
<Accordion.Icon />
</Accordion.Trigger>
</h2>
<Accordion.Content pb={4}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
</Accordion>

Expand multiple items at once#

If you set multiple to true then the accordion will permit multiple items to be expanded at once.

If you pass this prop, ensure that the index or defaultIndex prop is an array.

<Accordion.Root defaultIndex={[0]} multiple>
<Accordion.Item>
<h2>
<Accordion.Trigger>
<Box as='span' flex='1' textAlign='left'>
Section 1 title
</Box>
<Accordion.Icon />
</Accordion.Trigger>
</h2>
<Accordion.Content pb={4}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item>
<h2>
<Accordion.Trigger>
<Box as='span' flex='1' textAlign='left'>
Section 2 title
</Box>
<Accordion.Icon />
</Accordion.Trigger>
</h2>
<Accordion.Content pb={4}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
</Accordion>

Toggle each accordion item#

If you set collapsible to true, any expanded item may be collapsed again.

<Accordion.Root collapsible>
<Accordion.Item>
<h2>
<Accordion.Trigger>
<Box as='span' flex='1' textAlign='left'>
Section 1 title
</Box>
<Accordion.Icon />
</Accordion.Trigger>
</h2>
<Accordion.Content pb={4}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item>
<h2>
<Accordion.Trigger>
<Box as='span' flex='1' textAlign='left'>
Section 2 title
</Box>
<Accordion.Icon />
</Accordion.Trigger>
</h2>
<Accordion.Content pb={4}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
</Accordion>

Styling the expanded state#

The Accordion.Trigger component has aria-expanded set to true or false depending on the state of the Accordion.Item. Use the style prop _expanded to style this state.

<Accordion.Root>
<Accordion.Item>
<h2>
<Accordion.Trigger _expanded={{ bg: 'tomato', color: 'white' }}>
<Box as='span' flex='1' textAlign='left'>
Click me to see a different style
</Box>
<Accordion.Icon />
</Accordion.Trigger>
</h2>
<Accordion.Content>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
</Accordion>

Accessing the internal state#

If you need access to the internal state of each accordion item, you can use a render prop. It provides 2 internal state props: isExpanded and isDisabled.

<Accordion.Root multiple>
<Accordion.Item>
<h2>
<Accordion.Trigger>
<Box as='span' flex='1' textAlign='left'>
Section 1 title
</Box>
<Accordion.Icon />
</Accordion.Trigger>
</h2>
<Accordion.Content pb={4}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item>
{({ isExpanded }) => (
<>
<h2>
<Accordion.Trigger>
<Box as='span' flex='1' textAlign='left'>
Section 2 title
</Box>
{isExpanded ? (
<MinusIcon fontSize='12px' />
) : (
<AddIcon fontSize='12px' />
)}
</Accordion.Trigger>
</h2>
<Accordion.Content pb={4}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
</Accordion.Content>
</>
)}
</Accordion.Item>
</Accordion>

Accessibility#

Pressing space or enter when focus is on the accordion panel header will toggle (expand or collapse) the accordion.

Edit this page on GitHub

Proudly made inNigeria by Segun Adebayo

Deployed by â–² Vercel