# FAQ accordion

> Questions on hairlines that open like they mean it: the answer eases to its height, the plus folds into a minus.

The FAQ is where visitors decide, and most accordions jump open and slam shut. Here the answer eases open to its real height while its text settles in out of a slight blur, and the plus turns half a circle as its upright folds flat into a minus. Closing fades the words first, then lets the space go. In single mode, opening one question closes the other in the same motion.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/faq-accordion.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/faq-accordion
- Registry item (source): https://hairlineui.com/r/faq-accordion.json

## Usage

```tsx
import { FaqAccordion } from "@/components/faq-accordion";

<FaqAccordion
  defaultOpen={[0]}
  items={[{ question: "Can I use it for client work?", answer: "Yes, one licence covers it." }]}
/>
```

## In a FAQ section

Answers can be any React: links, lists, small tables.

```tsx
import { FaqAccordion } from "@/components/faq-accordion";

const faqs = [
  { question: "Can I get a refund?", answer: <>Within 14 days. <a href="/refunds" className="underline">Read the policy</a>.</> },
  { question: "Do you offer team plans?", answer: "Yes: five seats or more get 20% off." },
];

export function Faq() {
  return (
    <section className="mx-auto grid max-w-5xl gap-10 md:grid-cols-[1fr_1.4fr]">
      <h2 className="text-3xl font-medium tracking-tight">Questions, answered</h2>
      <FaqAccordion items={faqs} defaultOpen={[0]} />
    </section>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `{ question; answer; id? }[]` | – | Each question, and its answer as text or any React. |
| `type` | `"single" \| "multiple"` | `"single"` | One answer open at a time, or any number. |
| `defaultOpen` | `number[]` | `[]` | Questions open at first, by index. |

## States

- **closed**: The question at 80% ink on a hairline, with a plus; hover brings it to full.
- **opening**: The answer’s row grows to its real height (460ms) and its text rises 6px out of a 4px blur; the plus turns 180° into a minus.
- **closing**: The words fade in 160ms, then the space closes, so text never gets squeezed.
- **single / multiple**: One open at a time, or any number.

## What it handles

The FAQ is where visitors decide, and most accordions jump open and slam shut. This one eases open to the answer’s real height and works properly with the keyboard.

- **It opens to the real height**: The answer eases open to its own height, whatever its length, without measuring it first.
- **It closes without squeezing**: The words fade first and then the space closes, so the text is never crushed.
- **One at a time, or many**: In single mode, opening one question closes the other in the same motion. Choose which start open.
- **Answers can be anything**: Text, links, lists or small tables. An answer is any React.
- **Keyboard navigation**: Up and Down move between questions, and Home and End jump to the first and last.
- **Correct markup**: Each question is a heading with a button that has aria-expanded, and closed answers are out of the tab order.

## Replaces

an accordion library, height animation code, ARIA attributes, keyboard navigation, single or multiple logic

## Where it fits

- **Landing page FAQs**: The questions that stop visitors from signing up, answered in place.
- **Pricing page questions**: Billing, refunds and plan limits next to the plans.
- **Help centres and docs**: Short answers that expand without leaving the page.
- **Product and checkout pages**: Shipping, returns and licence questions where people decide.

## Notes

- Each question is a heading with a button (aria-expanded, aria-controls); each answer is a labelled region, hidden from the tab order when closed.
- Up and Down move between questions, Home and End jump to the first and last, as the ARIA accordion pattern describes.
- Height is animated with grid rows, so answers can be any length without measuring.
- With reduced motion, answers open and close in place.

License: MIT (https://hairlineui.com/license#components)
