Components / Layout
Accordion
Collapsible sections that open with a smooth height animation.
Yes. Copy any component into personal or commercial projects, no attribution needed.
Installation
Requires React 18+ and Tailwind CSS.
- 1
Install dependencies
$ npm install motion - 2
Add the component
Copy the code from the Code tab above into
components/ui/accordion.tsx. - 3
Use it
example.tsximport { Accordion } from "@/components/ui/accordion"; const faqs = [ { id: "free", title: "Is it free to use?", content: "Yes. Copy any component into personal or commercial projects, no attribution needed.", }, { id: "deps", title: "What do I need installed?", content: "React, Tailwind CSS, and the motion package. That's it.", }, { id: "customize", title: "Can I customize the styles?", content: "Absolutely. The code lives in your project, so change anything you like.", }, ]; export default function AccordionDemo() { return <Accordion items={faqs} defaultOpen={["free"]} className="max-w-md" />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| items | { id: string; title: string; content: ReactNode }[] | — | Sections to show. |
| allowMultiple | boolean | false | Allow several sections open at once. |
| defaultOpen | string[] | [] | Ids of sections open at first. |