Accordion
vertically stacked collapsible content panels
Loading...
Installation
pnpm dlx shadcn@latest add https://prototyper-ui.com/r/accordion.jsonnpx shadcn@latest add https://prototyper-ui.com/r/accordion.jsonyarn dlx shadcn@latest add https://prototyper-ui.com/r/accordion.jsonbunx --bun shadcn@latest add https://prototyper-ui.com/r/accordion.jsonThis will add the following files to your project:
components/ui/accordion.tsx
Usage
import {
Accordion,
AccordionItem,
AccordionTrigger,
AccordionContent,
} from "@/components/ui/accordion"
<Accordion>
<AccordionItem>
<AccordionTrigger>Is it accessible?</AccordionTrigger>
<AccordionContent>
Yes. It adheres to the WAI-ARIA Accordion pattern.
</AccordionContent>
</AccordionItem>
</Accordion>Anatomy
<Accordion>
<AccordionItem>
<AccordionTrigger />
<AccordionContent />
</AccordionItem>
</Accordion>| Sub-component | data-slot | Purpose | Required |
|---|---|---|---|
Accordion | accordion | Root provider, manages expanded state | Yes |
AccordionItem | accordion-item | Wrapper for a single collapsible section | Yes |
AccordionTrigger | accordion-trigger | Button that toggles the panel open/closed | Yes |
AccordionContent | accordion-content | Collapsible content panel | Yes |
Examples
Disabled
Loading...
Styling
Data Slots
Use data-slot attributes to target specific parts of the accordion:
| Slot name | Element |
|---|---|
accordion | Root wrapper |
accordion-item | Individual collapsible section |
accordion-trigger | Toggle button (includes chevron) |
accordion-trigger-icon | Chevron icon inside the trigger |
accordion-content | Collapsible content panel |
Customization Examples
/* Remove border between items */
[data-slot="accordion-item"] {
@apply border-b-0;
}
/* Custom trigger icon color */
[data-slot="accordion-trigger-icon"] {
@apply text-primary;
}{/* Override content padding via className */}
<AccordionContent className="pb-6">
{/* ... */}
</AccordionContent>API Reference
Accordion
Root component that manages the expanded/collapsed state of all items.
Prop
Type
All Base UI Accordion.Root props are forwarded via ...props.
AccordionItem
Wrapper for a single collapsible section containing a trigger and content panel.
Prop
Type
All Base UI Accordion.Item props are forwarded via ...props.
AccordionTrigger
Button that toggles the visibility of the associated content panel.
Prop
Type
All Base UI Accordion.Trigger props are forwarded via ...props.
AccordionContent
Collapsible content panel that animates open and closed.
Prop
Type
All Base UI Accordion.Panel props are forwarded via ...props.
Accessibility
Keyboard Interactions
| Key | Action |
|---|---|
Space | Toggles the focused accordion item open/closed |
Enter | Toggles the focused accordion item open/closed |
ArrowDown | Moves focus to the next accordion trigger |
ArrowUp | Moves focus to the previous accordion trigger |
Home | Moves focus to the first accordion trigger |
End | Moves focus to the last accordion trigger |
Tab | Moves focus to the next focusable element |
ARIA Attributes
- Each trigger renders with
role="button"inside a heading element. aria-expandedindicates whether the associated panel is open.aria-controlson each trigger links to its corresponding content panel.aria-disabledis set on disabled triggers.- Each content panel renders with
role="region". aria-labelledbyon each panel links back to its corresponding trigger.