Accordion
Divide content into collapsible sections
Source
LLM docs
Docs
Package
Usage
Accordion allows users to expand and collapse sections of content. It helps manage large amounts of information in a limited space by showing only section headers initially and revealing content upon interaction.
Accordion is commonly used for:
- FAQ sections: displaying questions as headers with answers revealed when clicked
- Forms: organizing long forms into sections, for example, personal info, shipping, and payment
- Menus: nested navigation in sidebars or mobile views
order prop
The order prop (used in all demos on this page) sets the heading level for the Accordion.Control root element.
According to WAI-ARIA recommendations,
it is required to use h2-h6 heading levels to fit correctly within the outline of the page.
All examples on this page use order={3}, which means that all button elements of
Accordion.Control are wrapped with an h3 tag (h2 tags are used for the documentation sections).
The order prop is not enforced by the library but is required if your application
must meet accessibility standards.
Change chevron
Use the chevron prop to change the chevron icon. When chevron is set,
the chevronIconSize prop is ignored. To remove the chevron icon, use chevron={null}.
To customize chevron styles, use Styles API with the
data-rotate attribute. This attribute is set when the item
is opened if the disableChevronRotation prop is not set.
Example of a custom chevron icon with rotation styles:
Custom control label
You can use any React node as a label for Accordion.Control component.
When you use nested elements in Accordion.Control, it is recommended to
set aria-label attribute to make the control accessible for screen readers.
With icons
Use the icon prop to display any element in the left section of the Accordion.Control:
Change transition
To change transition duration, set transitionDuration prop:
To disable transitions, set transitionDuration to 0:
Default opened items
For multiple={false}, set defaultValue as string:
For multiple={true}, set defaultValue as an array of strings:
Control opened state
For multiple={false}, set value as string:
For multiple={true}, set value as an array of strings:
Compose controls
Putting a button or link inside Accordion.Control is a common mistake when
using Accordion. The Accordion.Control root element is a button. Putting interactive
elements inside other interactive elements is forbidden – you will receive a DOM
validation error from React if you try to implement the following component:
Instead of putting interactive elements inside the Accordion.Control, render them
next to it. For example, you can add an ActionIcon or Menu
to the right side of the original control. If you need to display an interactive element
over the Accordion.Control, use position: absolute instead.
Disabled items
Set the disabled prop on the Accordion.Control component to disable it.
When you disable items, users cannot activate them with the mouse or keyboard,
and arrow key navigation will skip them:
Unstyled Accordion
Set the unstyled prop on the Accordion component to remove all non-essential
library styles. Use the unstyled prop to style the component with the
Styles API without overriding any styles.
Styles API
Accordion supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Example of using Styles API to customize Accordion styles:
TypeScript
The AccordionProps type exported from @mantine/core is a generic that accepts a boolean type
describing the multiple state:
Accessibility
The Accordion component implements the WAI-ARIA accessibility pattern.