shadcn.io is an independent project built on shadcn/ui
On this page9 sections
An accordion stacks headings in a column, and each heading opens the section under it. One section is open at a time unless you allow several. It suits an FAQ or a long settings page, where most of the content can stay folded away until someone needs it.
For one section that opens and closes on its own, use a Collapsible. When every section matters as much as the next and people move between them, Tabs keep one in view at all times.
Installation
Anatomy

Usage
import {
Accordion, AccordionContent, AccordionItem, AccordionTrigger,
} from "@/components/ui/accordion";const AccordionDemo = () => (
<Accordion className="w-full max-w-sm" defaultExpandedKeys={["shipping"]}>
<AccordionItem id="shipping">
<AccordionTrigger>What are your shipping options?</AccordionTrigger>
<AccordionContent>
We offer standard (5-7 days), express (2-3 days), and overnight
shipping. Free shipping on international orders.
</AccordionContent>
</AccordionItem>
<AccordionItem id="returns">
<AccordionTrigger>What is your return policy?</AccordionTrigger>
<AccordionContent>
Returns accepted within 30 days. Items must be unused and in original
packaging. Refunds processed within 5-7 business days.
</AccordionContent>
</AccordionItem>
<AccordionItem id="support">
<AccordionTrigger>How can I contact customer support?</AccordionTrigger>
<AccordionContent>
Reach us via email, live chat, or phone. We respond within 24 hours
during business days.
</AccordionContent>
</AccordionItem>
</Accordion>
);Accessibility
Each trigger is a <button> that reports its state with aria-expanded, so a screen reader says whether a section is open and Enter or Space toggles it. The button sits inside an h3, which puts every section in the page's heading outline. If the page calls for another level, change that heading in components/ui/accordion.
- Space
- When focus is on a trigger, opens or closes its section.
- Enter
- When focus is on a trigger, opens or closes its section.
- Tab
- Moves focus to the next focusable element, which is the next trigger unless an open section holds one.
- Shift+Tab
- Moves focus to the previous focusable element.
Demos
Basic
Account questions, one open at a time, with the password item starting open. The rows come from a list, so another question is another entry rather than a fresh block of markup. Use this for a short FAQ where two answers on screen at once would be noise. If people compare sections, let more than one stay open.
Multiple
Three groups of account settings, with notifications open from the start and privacy or billing free to open beside it. Allow several sections at once when people compare them or check related settings in one pass. In a single-open list, opening the next group folds away the one they were still reading.
Disabled
Premium feature information, the middle of three account questions, has isDisabled on its AccordionItem, so its trigger does nothing while the questions about account history and email open as usual. Leave a disabled row when the heading should stay visible as a locked feature and the upgrade path lives elsewhere on the page. If the plan will never include it, omit the row.
Borders
The root gets a border and a radius. Each item gets a bottom border and horizontal padding, and the last item drops its border so it does not double up with the outline. Use the bordered list when the accordion is the surface, sitting on a plain page. Skip the extra edges when a card already supplies them.
Card
The questions sit in CardContent, under a title and a short description about subscription and billing. Plans starts open. Use the card when this FAQ is one block among others, on a pricing or billing screen, and it needs a heading that is not itself a trigger. A bare accordion is enough when the page heading already names the topic.
RTL
The same account questions, in Arabic, with the first item open and dir set to rtl. Triggers, text, and the chevron follow the inline direction, so the icon is not stuck on the physical right. Use this when the page language is Arabic or Hebrew. Only the direction of the row changes.
FAQ
How do I let only one accordion item open at a time in React?
That is how it behaves with no props: expanding an item collapses the one that was open, and pressing the open item again closes it too. Add allowsMultipleExpanded to Accordion when several should stay open together, as the Multiple demo does.
How do I make an accordion item open by default?
Give each AccordionItem an id and list the ones to open in defaultExpandedKeys on Accordion, such as ["shipping"]. Every item starts closed when you leave the prop out. To open several from the start, add allowsMultipleExpanded and list each one.
The Basic demo opens its first item this way.
How do I open or close accordion items from my own code?
Hold the open items in state, pass them as expandedKeys and update them in onExpandedChange, which receives a Set of the expanded items' ids.
Once the state is yours, anything can change it. A link to one question can open that item by reading the hash from the URL, and where several may be open, an Expand all button lists every item at once.
Do form fields inside a closed accordion item still submit?
Yes. React Aria keeps a closed panel in the DOM and only hides it, so its fields are part of the form and submit with it.
A hidden field can't show the browser's own validation message, though. If a closed section holds a required field, validate it yourself and open that section when it fails.
Why can't Ctrl+F find text inside a closed accordion section?
It can, in browsers that support hidden="until-found", which is how React Aria hides a closed panel. A match inside a closed section opens it. In a browser without that support the closed sections are skipped, since find in page only searches visible text.
Is the React Aria accordion accessible with the keyboard?
Yes. Every trigger is a button in the tab order, and Enter and Space toggle its section. There are no arrow-key shortcuts between triggers: Tab moves through them in order, along with anything focusable in an open section.
The Accessibility section lists each key. Keep links and buttons out of the trigger itself, because a button can't hold other controls.
How do I change the accordion's chevron icon?
Edit AccordionTrigger in components/ui/accordion, which is your code once installed. It renders two icons, ChevronDownIcon while the section is closed and ChevronUpIcon while it is open, and classes keyed on aria-expanded show one and hide the other.
Swap both imports for the pair you want, a plus and a minus for example. For a single icon that rotates, keep one of the two and turn it with a rotate class under the same aria-expanded variant.
When should I use an accordion instead of tabs or a collapsible?
Use an accordion when the sections are read one after another on the same page and most can stay closed: an FAQ, a filter sidebar, a long settings page. Headings stay visible, so people scan them and open what they need.
Tabs fit when there are few sections, their labels fit on one row and one must always show. A Collapsible is one section with its own trigger, with no group around it and nothing else closing when it opens.
API Reference
Accordion
data-slot="accordion"
allowsMultipleExpanded?boolean
Whether multiple items can be expanded at the same time.
defaultExpandedKeys?Iterable<Key>
The initial expanded keys in the group (uncontrolled).
- Type
Iterable<Key>
expandedKeys?Iterable<Key>
The currently expanded keys in the group (controlled).
- Type
Iterable<Key>
isDisabled?boolean
Whether all items are disabled.
onExpandedChange?(keys: Set<Key>) → any
Handler that is called when items are expanded or collapsed.
- Type
(keys: Set<Key>) → any- Parameters
keys– Set<Key>- Returns
any
className?string
Merged with the part's classes.
data-orientationstring
Mirrors the orientation prop.
AccordionItem
data-slot="accordion-item"
defaultExpanded?boolean
Whether the disclosure is expanded by default (uncontrolled).
onExpandedChange?(isExpanded: boolean) → void
Handler that is called when the disclosure expanded state changes.
- Parameters
isExpanded– boolean- Returns
void
isExpanded?boolean
Whether the disclosure is expanded (controlled).
className?string
Merged with the part's classes.
data-orientationstring
Mirrors the orientation prop.
AccordionTrigger
data-slot="accordion-trigger"
isDisabled?boolean
Whether the button is disabled.
className?string
Merged with the part's classes.
data-orientationstring
Mirrors the orientation prop.
AccordionContent
data-slot="accordion-content"
childrenReactNode
The children of the component.
labelElementType?ElementType
The HTML element used to render the label, e.g. label, or span.
- Default
"label"
role?"group" | "region"
The accessibility role for the disclosure's panel.
- Type
"group" | "region"- Default
"group"
style?CSSProperties
The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element.
render?DOMRenderFunction<E, T>
Overrides the default DOM element with a custom render function.
This allows rendering existing components with built-in styles and behaviors
such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if <button> is expected, you cannot render an
<a>).
- Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop
as appropriate.
- Type
DOMRenderFunction<E, T>
className?string
Merged with the part's classes.
data-orientationstring
Mirrors the orientation prop.












