# Accordion

A stack of sections that open and close, one at a time or several.

A stack of disclosures where the rows know about each other: one open at a time (or several with multiple), arrow keys move between the headers. Each item is the collapsible's row (44px trigger, the right caret that turns down, the same reveal), with a hairline between items; plain on the page or in one card. Behaviour and ARIA from the Zag accordion machine through Ark UI.

Kind: component · Category: Display · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `accordion` machine, through Ark UI

## Add

```bash
npx fndn add accordion
```

It writes the folder `accordion/` into the project's ui folder (`index.ts`, `accordion.tsx`, `Accordion.vue`, `Accordion.svelte`, `accordion.recipe.ts`), and what it is built from: [Collapsible](/components/collapsible.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { Accordion } from "@/components/ui/accordion";
```

```vue
import { Accordion } from "@/components/ui/accordion";
```

```svelte
import { Accordion } from "$lib/components/ui/accordion";
```

## Parts

In the DOM the root carries `data-slot="accordion"` and each part `data-slot="accordion-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `accordion` |  | Ark's accordion root; data-orientation=vertical. plain: no surface. card: one surface card (radius.card, shadow.card) that clips its rows. |
| `item` | `div` | `accordion-item` |  | One disclosure (Ark's item, a collapsible root): data-state=open\|closed, data-disabled. A 1px line under every item but the last. |
| `trigger` | `button` | `accordion-trigger` |  | The collapsible's row trigger (the classes of collapsible.trigger, variant row): 44px minimum, padding 10, hover fill hover, press hover-2, focus ring inside. aria-expanded, aria-controls, data-state from the engine; native disabled. |
| `caret` | `span` | `accordion-caret` |  | The collapsible's caret: right caret (ph caret-right) that turns down 90deg while the item is open, mirrored right-to-left; first or last child of the trigger; aria-hidden; kbd-instant. |
| `label` | `span` | `accordion-label` |  | The item's heading text: 14px/500 ink, wraps (never cut); its first line shares the caret's 24px line. Author text keeps its own direction. |
| `meta` | `span` | `accordion-meta` | optional | Trailing quiet note in the trigger (12px ink-2), never wraps. |
| `content` | `div` | `accordion-content` |  | role=region, aria-labelledby its trigger; the collapsible's region (grid rows 0fr to 1fr). Closed: hidden, out of the layout and the tab order. |
| `body` | `div` | `accordion-body` |  | The one child of the region; it clips while the region moves. Holds the detail text, then the item's free content. |
| `text` | `p` | `accordion-text` | optional | The item's detail text: 12px ink-2, inset to line up with the label (padding 0 10px 10px). |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `array` |  | The items in order: { value, label, meta?, detail?, disabled? }. Free content in an item's body, after the detail text: React, the item's content (a node); Vue, the content slot; Svelte, the content snippet (both receive the item). |
| `value` | `array` | `[]` | Bindable (React: `defaultValue` and `onValueChange`; Vue: `v-model:value`; Svelte: `bind:value`). The values of the open items. React: value / defaultValue / onValueChange; Vue: v-model:value; Svelte: bind:value. |
| `multiple` | `boolean` | `false` | Several items may be open at once. Without it, opening one closes the other. |
| `collapsible` | `boolean` | `true` | The open item closes when its trigger is pressed again. false: one item always stays open once one has been opened (single mode only). |
| `variant` | `"plain" \| "card"` | `"plain"` | plain: rows on the page, hairlines between them. card: the rows in one surface card (the task-rows list look). |
| `caret` | `"start" \| "end"` | `"end"` | Where the caret sits in each trigger, as the collapsible. |
| `disabled` | `boolean` | `false` | Every item is disabled (an item can be disabled on its own with its disabled field). |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `valueChange` | (value: string[]) the open items, after a click, Enter or Space |

## States

`hover`, `press`, `focus-visible`, `open`, `disabled`

## Keyboard and accessibility

Role: button (aria-expanded, aria-controls) + region per item.

Keyboard:

- Tab reaches the triggers one by one; nothing inside a closed item is reachable
- Enter / Space toggle the focused item; the change is instant (no reveal, no caret turn)
- ArrowDown / ArrowUp move focus to the next / previous trigger; Home / End to the first / last
- A disabled item's trigger is skipped by Tab and by the arrows

Notes:

- Each trigger is a real button whose whole content is its name; each region is labelled by its trigger.
- A closed region leaves the layout once its exit has played, which also takes it out of the accessibility tree.
- Set it from outside by controlling value (React value / onValueChange).

## Motion

- the collapsible's: reveal grid-template-rows 0fr -> 1fr over duration.reveal easing.out-strong with opacity over duration.base; the items below move with it
- exit: the same transition back, held by fndn-collapsible-exit before the region is hidden; in single mode the item that closes and the one that opens move at the same time
- caret: rotate 0 -> 90deg (right-to-left 180 -> 90deg) over duration.move easing.out-strong
- trigger hover and press fills over duration.fast (hover gated to a fine pointer)
- keyboard: region and caret are instant (kbd-instant)
- first paint: nothing plays

## Tokens

`color.surface`, `color.line`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.hover`, `color.hover-2`, `shadow.card`, `radius.card`, `radius.control`, `text.xs`, `text.sm`, `duration.fast`, `duration.base`, `duration.move`, `duration.reveal`, `easing.out-strong`

## Dependencies

- [Collapsible](/components/collapsible.md)

## Examples

### Deploy help

React · `deploy-help.tsx`

```tsx
import { Accordion } from "@/components/ui/accordion";

const questions = [
  { value: "timeout", label: "Why did my build time out?", detail: "Builds stop after 45 minutes. Cache your dependencies, or move long jobs to data-pipeline." },
  { value: "preview", label: "How do preview deploys work?", detail: "Every pull request gets its own URL. It updates on each push and is removed when the branch merges." },
  { value: "rollback", label: "Can I roll back a deploy?", detail: "Yes. Open any earlier deploy of Production and choose Promote; the switch takes a few seconds." },
];

export default function DeployHelp() {
  return <Accordion items={questions} style={{ width: 320 }} />;
}
```

Vue · `deploy-help.vue`

```vue
<script setup lang="ts">
import { Accordion } from "@/components/ui/accordion";

const questions = [
  { value: "timeout", label: "Why did my build time out?", detail: "Builds stop after 45 minutes. Cache your dependencies, or move long jobs to data-pipeline." },
  { value: "preview", label: "How do preview deploys work?", detail: "Every pull request gets its own URL. It updates on each push and is removed when the branch merges." },
  { value: "rollback", label: "Can I roll back a deploy?", detail: "Yes. Open any earlier deploy of Production and choose Promote; the switch takes a few seconds." },
];
</script>

<template>
  <Accordion :items="questions" style="width: 320px" />
</template>
```

Svelte · `deploy-help.svelte`

```svelte
<script lang="ts">
  import { Accordion } from "$lib/components/ui/accordion";

  const questions = [
    { value: "timeout", label: "Why did my build time out?", detail: "Builds stop after 45 minutes. Cache your dependencies, or move long jobs to data-pipeline." },
    { value: "preview", label: "How do preview deploys work?", detail: "Every pull request gets its own URL. It updates on each push and is removed when the branch merges." },
    { value: "rollback", label: "Can I roll back a deploy?", detail: "Yes. Open any earlier deploy of Production and choose Promote; the switch takes a few seconds." },
  ];
</script>

<Accordion items={questions} style="width: 320px" />
```

### Project settings

React · `project-settings.tsx`

```tsx
import { Accordion } from "@/components/ui/accordion";

/* one open at a time; a setting the plan does not include stays shut */
const settings = [
  { value: "build", label: "Build command", meta: "pnpm build", detail: "Runs on every push. Output goes to dist/ and is served from the edge." },
  { value: "env", label: "Environment variables", meta: "12", detail: "DATABASE_URL, SESSION_SECRET and 10 more, set per environment." },
  { value: "domains", label: "Domains", meta: "2", detail: "app.northwind.example (primary) and northwind-web.example." },
  { value: "sso", label: "Single sign-on", meta: "Business plan", disabled: true },
];

export default function ProjectSettings() {
  return <Accordion variant="card" defaultValue={["build"]} items={settings} style={{ width: 360 }} />;
}
```

Vue · `project-settings.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Accordion } from "@/components/ui/accordion";

/* one open at a time; a setting the plan does not include stays shut */
const settings = [
  { value: "build", label: "Build command", meta: "pnpm build", detail: "Runs on every push. Output goes to dist/ and is served from the edge." },
  { value: "env", label: "Environment variables", meta: "12", detail: "DATABASE_URL, SESSION_SECRET and 10 more, set per environment." },
  { value: "domains", label: "Domains", meta: "2", detail: "app.northwind.example (primary) and northwind-web.example." },
  { value: "sso", label: "Single sign-on", meta: "Business plan", disabled: true },
];
const open = ref(["build"]);
</script>

<template>
  <Accordion variant="card" v-model:value="open" :items="settings" style="width: 360px" />
</template>
```

Svelte · `project-settings.svelte`

```svelte
<script lang="ts">
  import { Accordion } from "$lib/components/ui/accordion";

  /* one open at a time; a setting the plan does not include stays shut */
  const settings = [
    { value: "build", label: "Build command", meta: "pnpm build", detail: "Runs on every push. Output goes to dist/ and is served from the edge." },
    { value: "env", label: "Environment variables", meta: "12", detail: "DATABASE_URL, SESSION_SECRET and 10 more, set per environment." },
    { value: "domains", label: "Domains", meta: "2", detail: "app.northwind.example (primary) and northwind-web.example." },
    { value: "sso", label: "Single sign-on", meta: "Business plan", disabled: true },
  ];
  let open = $state(["build"]);
</script>

<Accordion variant="card" bind:value={open} items={settings} style="width: 360px" />
```

### Release notes, several open

React · `release-notes.tsx`

```tsx
import { Accordion } from "@/components/ui/accordion";

/* several open at once, caret first: a reader compares releases */
const releases = [
  { value: "2.4.0", label: "2.4.0", meta: "Nov 14, 2026", detail: "Webhook deliveries retry up to five times with backoff. Usage alerts are in beta." },
  { value: "2.3.2", label: "2.3.2", meta: "Nov 3, 2026", detail: "Fixes preview URLs for branch names with a slash, like feat/usage-alerts." },
  { value: "2.3.0", label: "2.3.0", meta: "Oct 21, 2026", detail: "Adds the Staging environment and per-environment variables." },
];

export default function ReleaseNotes() {
  return <Accordion multiple caret="start" defaultValue={["2.4.0", "2.3.2"]} items={releases} style={{ width: 360 }} />;
}
```

Vue · `release-notes.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Accordion } from "@/components/ui/accordion";

/* several open at once, caret first: a reader compares releases */
const releases = [
  { value: "2.4.0", label: "2.4.0", meta: "Nov 14, 2026", detail: "Webhook deliveries retry up to five times with backoff. Usage alerts are in beta." },
  { value: "2.3.2", label: "2.3.2", meta: "Nov 3, 2026", detail: "Fixes preview URLs for branch names with a slash, like feat/usage-alerts." },
  { value: "2.3.0", label: "2.3.0", meta: "Oct 21, 2026", detail: "Adds the Staging environment and per-environment variables." },
];
const open = ref(["2.4.0", "2.3.2"]);
</script>

<template>
  <Accordion multiple caret="start" v-model:value="open" :items="releases" style="width: 360px" />
</template>
```

Svelte · `release-notes.svelte`

```svelte
<script lang="ts">
  import { Accordion } from "$lib/components/ui/accordion";

  /* several open at once, caret first: a reader compares releases */
  const releases = [
    { value: "2.4.0", label: "2.4.0", meta: "Nov 14, 2026", detail: "Webhook deliveries retry up to five times with backoff. Usage alerts are in beta." },
    { value: "2.3.2", label: "2.3.2", meta: "Nov 3, 2026", detail: "Fixes preview URLs for branch names with a slash, like feat/usage-alerts." },
    { value: "2.3.0", label: "2.3.0", meta: "Oct 21, 2026", detail: "Adds the Staging environment and per-environment variables." },
  ];
  let open = $state(["2.4.0", "2.3.2"]);
</script>

<Accordion multiple caret="start" bind:value={open} items={releases} style="width: 360px" />
```

### Billing, with actions inside

React · `billing.tsx`

```tsx
import { useState } from "react";
import { Accordion } from "@/components/ui/accordion";
import { Button } from "@/components/ui/button";

/* free content after an item's detail: the actions of that section */
export default function Billing() {
  const [open, setOpen] = useState<string[]>(["plan"]);
  return (
    <Accordion
      variant="card"
      value={open}
      onValueChange={setOpen}
      style={{ width: 360 }}
      items={[
        {
          value: "plan",
          label: "Plan",
          meta: "Team",
          detail: "12 of 20 seats in use. Renews on Dec 1, 2026 at $240.00.",
          content: (
            <div className="flex gap-2 px-2.5 pb-2.5">
              <Button size="sm">Change plan</Button>
              <Button size="sm" variant="ghost">View invoices</Button>
            </div>
          ),
        },
        {
          value: "payment",
          label: "Payment method",
          meta: "Card ending 4242",
          detail: "Expires 08/2028. Receipts go to maya@northwind.example.",
          content: (
            <div className="flex gap-2 px-2.5 pb-2.5">
              <Button size="sm">Update card</Button>
            </div>
          ),
        },
      ]}
    />
  );
}
```

Vue · `billing.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Accordion } from "@/components/ui/accordion";
import { Button } from "@/components/ui/button";

/* free content after an item's detail: the actions of that section */
const open = ref(["plan"]);
const items = [
  { value: "plan", label: "Plan", meta: "Team", detail: "12 of 20 seats in use. Renews on Dec 1, 2026 at $240.00." },
  { value: "payment", label: "Payment method", meta: "Card ending 4242", detail: "Expires 08/2028. Receipts go to maya@northwind.example." },
];
</script>

<template>
  <Accordion variant="card" v-model:value="open" style="width: 360px" :items="items">
    <template #content="{ item }">
      <div v-if="item.value === 'plan'" class="flex gap-2 px-2.5 pb-2.5">
        <Button size="sm">Change plan</Button>
        <Button size="sm" variant="ghost">View invoices</Button>
      </div>
      <div v-else class="flex gap-2 px-2.5 pb-2.5">
        <Button size="sm">Update card</Button>
      </div>
    </template>
  </Accordion>
</template>
```

Svelte · `billing.svelte`

```svelte
<script lang="ts">
  import { Accordion } from "$lib/components/ui/accordion";
  import { Button } from "$lib/components/ui/button";

  /* free content after an item's detail: the actions of that section */
  let open = $state(["plan"]);
  const items = [
    { value: "plan", label: "Plan", meta: "Team", detail: "12 of 20 seats in use. Renews on Dec 1, 2026 at $240.00." },
    { value: "payment", label: "Payment method", meta: "Card ending 4242", detail: "Expires 08/2028. Receipts go to maya@northwind.example." },
  ];
</script>

<Accordion variant="card" bind:value={open} style="width: 360px" {items}>
  {#snippet content(item)}
    {#if item.value === "plan"}
      <div class="flex gap-2 px-2.5 pb-2.5">
        <Button size="sm">Change plan</Button>
        <Button size="sm" variant="ghost">View invoices</Button>
      </div>
    {:else}
      <div class="flex gap-2 px-2.5 pb-2.5">
        <Button size="sm">Update card</Button>
      </div>
    {/if}
  {/snippet}
</Accordion>
```

## Recipe

`accordion.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";
import { collapsible } from "../collapsible/collapsible.recipe";

/* accordion — a stack of disclosures that know about each other (Zag accordion through Ark UI:
 * one open at a time unless multiple, arrow keys between the headers). Each Ark item is a
 * collapsible root, its content the collapsible's content, so an item is the collapsible's row:
 * its trigger, caret, label, meta, region, body and text are the collapsible recipe's (variant
 * row) composed here, never copied. The reveal, the caret turn, the hover and press fills and the
 * keyboard's instant change all come from collapsible.recipe.ts.
 *
 * What the accordion adds:
 *   item     a 1px line under every item but the last (task-rows' list look)
 *   caret    turns down from this trigger's open state (the collapsible's own rule names its trigger)
 *   trigger  Ark disables an item's trigger natively (the collapsible uses data-disabled)
 *   card     the rows in one surface card that clips them, so the first and last row's hover
 *            follows the card's radius
 * Parts are found by data-slot (accordion, accordion-item, accordion-trigger, …); the root slot is
 * `base`. The exit's @keyframes (fndn-collapsible-exit) is the collapsible's. */

const row = collapsible({ variant: "row" });

export const accordion = tv({
  slots: {
    base: "flex w-full min-w-0 flex-col",
    item: "flex min-w-0 flex-col border-b border-solid border-line last:border-b-0",
    trigger: [row.trigger(), "disabled:opacity-50 disabled:pointer-events-none"],
    caret: [row.caret(), "[[data-slot=accordion-trigger][data-state=open]>&]:[transform:rotate(90deg)]"],
    label: row.label(),
    meta: row.meta(),
    content: row.content(),
    body: row.body(),
    text: row.text(),
  },
  variants: {
    variant: {
      plain: {},
      card: { base: "overflow-hidden rounded-card bg-surface shadow-card" },
    },
  },
  defaultVariants: { variant: "plain" },
});

export type AccordionRecipeProps = VariantProps<typeof accordion>;
```
