# Accordion

> FAQ panels that open with a smooth, springy height and a turning chevron.

Category: Layout · Free · Updated 2026-10-20 · Live demo: https://www.motionkitui.com/components/accordion

## When to use it

FAQs, pricing details, documentation sections and settings groups.

## How it works

Each panel's height animates from 0 to auto with a spring, which CSS transitions can't do on their own, and the chevron turns as it opens. Buttons carry aria-expanded and aria-controls, and panels are labelled regions. You can allow one panel open at a time or several.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/accordion.json
```

Or copy `components/motionkit/accordion.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `{ id, title, content }[]` |  | The panels. |
| `multiple` | `boolean` | `false` | Let several panels stay open at once. |
| `defaultOpen` | `string[]` | `[]` | Ids open on first render. |

## Accessibility

- **Keyboard: Pass.** Each header is a button inside a heading. Enter or Space toggles it.
- **Screen readers: Pass.** Buttons expose aria-expanded and aria-controls; open panels are regions labelled by their header.
- **Reduced motion: Pass.** With reduced motion on, panels open and close instantly.
- **Colour contrast: Pass.** Headers 15.5:1, answers 7.1:1.

## Source

```tsx
"use client";

import { useId, useState, type ReactNode } from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";

export type AccordionItem = {
  id: string;
  title: string;
  content: ReactNode;
};

type AccordionProps = {
  items: AccordionItem[];
  /** Let several panels stay open at once. */
  multiple?: boolean;
  /** Ids open on first render. */
  defaultOpen?: string[];
  className?: string;
};

export function Accordion({ items, multiple = false, defaultOpen = [], className = "" }: AccordionProps) {
  const [open, setOpen] = useState<string[]>(defaultOpen);
  const reduceMotion = useReducedMotion();
  const base = useId();

  function toggle(id: string) {
    setOpen((current) =>
      current.includes(id) ? current.filter((value) => value !== id) : multiple ? [...current, id] : [id],
    );
  }

  return (
    <div className={`divide-y divide-white/10 rounded-2xl border border-white/10 bg-[#141B1B] text-[#F6F1E8] ${className}`}>
      {items.map((item) => {
        const isOpen = open.includes(item.id);
        const buttonId = `${base}-${item.id}-button`;
        const panelId = `${base}-${item.id}-panel`;
        return (
          <div key={item.id}>
            <h3>
              <button
                id={buttonId}
                aria-expanded={isOpen}
                aria-controls={panelId}
                onClick={() => toggle(item.id)}
                className="flex w-full items-center justify-between gap-4 px-5 py-4 text-left text-sm font-medium transition-colors hover:bg-white/[0.02] focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-[#5FAEB4]"
              >
                {item.title}
                <motion.svg
                  aria-hidden
                  viewBox="0 0 24 24"
                  className="size-4 shrink-0 text-[#94A9A7]"
                  fill="none"
                  stroke="currentColor"
                  strokeWidth={2}
                  strokeLinecap="round"
                  animate={{ rotate: isOpen ? 180 : 0 }}
                  transition={reduceMotion ? { duration: 0 } : { type: "spring", bounce: 0.2, duration: 0.35 }}
                >
                  <path d="m6 9 6 6 6-6" />
                </motion.svg>
              </button>
            </h3>
            <AnimatePresence initial={false}>
              {isOpen && (
                <motion.div
                  id={panelId}
                  role="region"
                  aria-labelledby={buttonId}
                  className="overflow-hidden"
                  initial={{ height: 0, opacity: 0 }}
                  animate={{ height: "auto", opacity: 1 }}
                  exit={{ height: 0, opacity: 0 }}
                  transition={reduceMotion ? { duration: 0 } : { type: "spring", bounce: 0, duration: 0.35 }}
                >
                  <div className="px-5 pb-5 text-sm leading-6 text-[#94A9A7]">{item.content}</div>
                </motion.div>
              )}
            </AnimatePresence>
          </div>
        );
      })}
    </div>
  );
}
```
