# Accordion

> Animated accordion for React and shadcn: panels open to their real height, one or several at a time, built on Base UI.

Disclosures whose height springs open with no overshoot, content fading in as the height lands and the chevron turning on the same spring. Built on Base UI Accordion.

Also known as a collapsible or a FAQ.

- Tier: Free (MIT)
- Interaction: Press
- Page: https://eased.dev/components/accordion
- Installs: @base-ui/react
- Registry: https://eased.dev/r/accordion.json

## Install

```bash
npx shadcn add https://eased.dev/r/accordion.json
```

A stack of disclosures on Base UI's Accordion (buttons inside headings, `aria-expanded` and `aria-controls`), whose panels spring open to their real height with Auto Height.

## When to use

- Questions and answers where people scan the questions and open one or two: an FAQ, a billing help panel.
- Secondary detail under a heading that most people skip: shipping terms on a product page, advanced settings.
- Long sections in a narrow column, where showing everything at once would push the useful part off screen.

## When not to use

- Views of one thing that replace each other in the same place: use [Tabs](/components/tabs).
- Content people need to compare side by side or read in order: put it on the page.
- Steps someone must complete in sequence: a disclosure hides the next step instead of guiding them to it.

## Usage

```tsx billing-faq.tsx
import { Accordion, AccordionItem } from "@/components/eased/accordion/accordion";

export function BillingFaq() {
  return (
    <Accordion defaultValue={["charged"]}>
      <AccordionItem value="charged" title="When am I charged?">
        On the day your trial ends, then on the same date every month.
      </AccordionItem>
      <AccordionItem value="refund" title="Do you offer refunds?">
        Within 14 days of any charge, in full.
      </AccordionItem>
    </Accordion>
  );
}
```

## Examples

### Several open at once

Pass `multiple` when people open items to compare them, such as plan details.

```tsx
<Accordion multiple defaultValue={["storage", "seats"]}>
  <AccordionItem value="storage" title="Storage">50 GB per workspace, pooled across members.</AccordionItem>
  <AccordionItem value="seats" title="Seats">Up to 25 members; guests are free.</AccordionItem>
</Accordion>
```

### Controlled, with a heading level

Control the open items from state, and set `headingLevel` so the triggers fit the page outline.

```tsx
const [open, setOpen] = useState<string[]>([]);

<Accordion value={open} onValueChange={setOpen}>
  <AccordionItem value="vat" title="How do I add a VAT number?" headingLevel={2}>
    Go to Settings, Billing, Tax details and enter it with its country prefix.
  </AccordionItem>
</Accordion>
```

## API reference

### Accordion

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` | `string[]` | | Open items (controlled). |
| `defaultValue` | `string[]` | | Initially open items (uncontrolled). |
| `onValueChange` | `(value: string[]) => void` | | |
| `multiple` | `boolean` | `false` | Allow more than one item open at a time. |
| `disabled` | `boolean` | | Disables every item. |
| `className` | `string` | `""` | Appended to the root's classes. |

Items are separated by hairlines. Only these props reach Base UI's Accordion.Root.

### AccordionItem

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` | `string` | | Identifies the item in `value`. |
| `title` | `ReactNode` | | The trigger's label. |
| `headingLevel` | `2 \| 3 \| 4 \| 5 \| 6` | `3` | The heading element that wraps the trigger. |
| `disabled` | `boolean` | | |
| `children` | `ReactNode` | | The panel's content. |
| `className` | `string` | `""` | Appended to the item's classes. |

## Keyboard

| Key | Action |
|---|---|
| `Tab` | Moves through the triggers, and into the content of open panels. |
| `Enter` / `Space` | Opens or closes the focused item. |

## Accessibility

- Each trigger is a button inside a real heading (`h3` by default), with `aria-expanded` and `aria-controls` wired by Base UI.
- A closed panel is hidden once it has finished collapsing, so its content leaves the tab order and the accessibility tree; while it closes it is `inert`.
- A disabled trigger turns muted and shows a not-allowed cursor.

## Motion

The panel's height springs open on the smooth spring, which has no overshoot, and the content fades in over 200ms, starting 120ms in so it lands just after the height. The chevron turns 180° on the same spring. Closing fades the content out in 100ms while the height springs shut, so it is quicker than opening. Content that grows while open (an image loading, a list filtering) springs to its new height. Changing your mind mid-flight continues from the current height. Reduced motion snaps the height, fades the content in 100ms, and turns the chevron without a transition.

## Notes for AI

Use Accordion for optional detail that people open in place, one `AccordionItem` per question or section, with a unique `value` for each. Pass `multiple` only when opening several at once helps, and set `headingLevel` to fit the surrounding headings.

Do not animate the panel's height yourself or wrap the content in another collapsible: Auto Height already measures and springs it, and keeps closed panels out of the tab order. Put padding inside your content, not on the item.

## Related

- [Tabs](/components/tabs): one view at a time, switched from a row of tabs.

## Example

`components/eased/accordion/accordion-demo.tsx`

```tsx
"use client";

import { DemoFrame } from "../lib/demo-frame";
import { Accordion, AccordionItem } from "./accordion";

export function AccordionDemo() {
  return (
    <DemoFrame title="Billing help" meta="4 questions">
      <div className="min-h-0 flex-1 overflow-y-auto px-4 py-1">
        <Accordion defaultValue={["charged"]}>
          <AccordionItem value="charged" title="When am I charged?">
            On the day your trial ends, then on the same date every month. If that date doesn’t exist in a month, such as
            the 31st, we charge on the last day instead.
          </AccordionItem>
          <AccordionItem value="switch" title="Can I change plans mid-cycle?">
            Yes. Upgrades apply at once and you pay the difference for the days left in the cycle. Downgrades take effect at
            your next renewal, so you keep what you paid for.
          </AccordionItem>
          <AccordionItem value="refund" title="Do you offer refunds?">
            Within 14 days of any charge, in full, no questions asked.
          </AccordionItem>
          <AccordionItem value="vat" title="How do I add a VAT number to my invoices?">
            <p>
              Go to Settings → Billing → Tax details and enter it with its country prefix, for example DE123456789. We
              check it against VIES before saving.
            </p>
            <p className="mt-2">
              New invoices show it from then on. To reissue a past invoice with the number on it, open the invoice and
              choose Regenerate.
            </p>
          </AccordionItem>
        </Accordion>
      </div>
    </DemoFrame>
  );
}
```
