components / display
Accordion
Stacked sections shown as a terminal prompt tree, with a smooth height animation.
accordion-default.tsx
import { Accordion, AccordionItem, AccordionPanel, AccordionTrigger } from "@/components/ui/accordion";
const faqs = [
{ value: "install", question: "How do I install a component?", answer: "Run the shadcn CLI with the component URL. The file lands in your project and you own the code." },
{ value: "theme", question: "Can I change the colors?", answer: "Yes. Every color is a CSS variable in your globals.css, so you can swap the palette in one place." },
{ value: "motion", question: "Does it respect reduced motion?", answer: "Yes. Transitions and animations are turned off for people who prefer reduced motion." },
];
export default function AccordionDefault() {
return (
<Accordion className="w-full max-w-md" defaultValue={["install"]}>
{faqs.map((f) => (
<AccordionItem key={f.value} value={f.value}>
<AccordionTrigger>{f.question}</AccordionTrigger>
<AccordionPanel>{f.answer}</AccordionPanel>
</AccordionItem>
))}
</Accordion>
);
}Installation
$ npx shadcn@latest add https://cd-ui.vercel.app/r/accordion.jsonfirst time? set up components.json and the theme first: see installation.
Usage
import { Accordion, AccordionItem, AccordionPanel, AccordionTrigger } from "@/components/ui/accordion"
<Accordion defaultValue={["a"]}>
<AccordionItem value="a">
<AccordionTrigger>Question</AccordionTrigger>
<AccordionPanel>Answer</AccordionPanel>
</AccordionItem>
</Accordion>Examples
Chevron indicator
accordion-chevron.tsx
import { Accordion, AccordionItem, AccordionPanel, AccordionTrigger } from "@/components/ui/accordion";
export default function AccordionChevron() {
return (
<Accordion className="w-full max-w-md" defaultValue={["install"]} indicator="chevron">
<AccordionItem value="install">
<AccordionTrigger>How do I install a component?</AccordionTrigger>
<AccordionPanel>Run the shadcn CLI with the component URL. The file lands in your project and you own the code.</AccordionPanel>
</AccordionItem>
<AccordionItem value="theme">
<AccordionTrigger>Can I change the colors?</AccordionTrigger>
<AccordionPanel>Yes. Every color is a CSS variable in your globals.css, so you can swap the palette in one place.</AccordionPanel>
</AccordionItem>
</Accordion>
);
}API
Accordion
Base UI · Accordion.RootRoot. By default only one item stays open; pass multiple to allow several.
| prop | type | default |
|---|---|---|
value · defaultValueOpen items, as an array of item values. Controlled or initial. | string[] | - |
multipleAllows more than one item open at the same time. | boolean | false |
indicator
| "prompt" | "chevron" | "prompt" |
onValueChangeCalled when an item opens or closes. | (value: string[]) => void | - |
classNameExtra classes, merged with | string | - |
AccordionItem
Base UI · Accordion.ItemOne section, identified by value.
| prop | type | default |
|---|---|---|
valueItem identifier. | string | - |
classNameExtra classes, merged with | string | - |
AccordionTrigger
Base UI · Accordion.TriggerHeading button. The ▸ marker turns 90° in 120ms (or the chevron 180° in 160ms) as the panel opens.
| prop | type | default |
|---|---|---|
classNameExtra classes, merged with | string | - |
AccordionPanel
Base UI · Accordion.PanelContent. Animates its height and opacity in 160ms and is removed from the page while closed.
| prop | type | default |
|---|---|---|
classNameExtra classes, merged with | string | - |
Keyboard
| key | action |
|---|---|
| EnterSpace | Opens or closes the focused item. |
| ↑↓ | Moves focus between headings. |
| HomeEnd | Focuses the first or last heading. |
Accessibility
- Each trigger sits inside a heading and is linked to its panel with
aria-expandedandaria-controls.