Animated Accordion, animated React component
A free React accordion that opens on a spring. The open entry lifts onto its own tile, its height eases to fit the text, the text follows a beat later and the plus turns into a minus. Single or multiple open, light or dark, with real buttons inside headings and Up, Down, Home and End to move between titles.
- Free
- Cards
- Spring
Like Animated Accordion? 256 more are in Pro.
Pro unlocks all 256 Pro components, every template and block, and everything we release next. Animated Accordion stays free.
Set it up, copy the code
Choose values for the main props and the JSX on the right updates to match.
single keeps one entry open at a time. multiple lets any number stay open.
Single mode only: whether the open entry can be closed again.
Light or dark surface.
Opens the entries one after another by itself until the visitor touches it. Never runs under reduced motion.
Your JSX
<AnimatedAccordion
type="single"
collapsible={true}
tone="light"
autoplay={false}
/>Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| items | AccordionEntry[] | sample questions | The entries: { id?, title, hint?, content }. Content can be text or any React node. |
| type | "single" | "multiple" | "single" | single keeps one entry open at a time. multiple lets any number stay open. |
| collapsible | boolean | true | Single mode only: whether the open entry can be closed again. |
| defaultOpen | string | string[] | first entry | The id, or ids for multiple, open at the start. |
| onChange | (open: string[]) => void | — | Called with the ids that are open after every change. |
| headingLevel | 1 | 2 | 3 | 4 | 5 | 6 | 3 | Heading level used for each title. Pick the one that fits your page outline. |
| tone | "light" | "dark" | "light" | Light or dark surface. |
| autoplay | boolean | false | Opens the entries one after another by itself until the visitor touches it. Never runs under reduced motion. |
| className | string | "" | Extra classes for the outer element. |
Add it to your project
- 1
Set up your project once
You need a Next.js project with Tailwind CSS and the
@/import alias. In its root folder, run this once. It createscomponents.jsonand thecn()helper insrc/lib/utils.ts:npx shadcn@latest init -d
Starting from nothing? The Quick Start walks through the whole thing.
- 2
Connect the registry
Run this once per project. It writes the Nexus UI entry into
components.jsonfor you:npx shadcn@latest registry add "@nexus-labs=https://www.nexus-ui.com/api/registry/{name}"Type it exactly as shown.
{name}is filled in by the CLI with the component you ask for, so you never replace it.
- 3
Add the component
Run this from your project root. It adds the component, the helpers it imports and its npm packages.
npx shadcn@latest add @nexus-labs/animated-accordion
- 4
Check what was added
With a project made as in the Quick Start (a
src/folder), these files land in it:components/animated-accordion/animated-accordion.tsxindex.ts - 5
Copying by hand? Skip the registry
Instead of steps 2 and 3 you can copy the files yourself, with no registry and no API key. Step 1 still applies, so that
cn()exists. Install the packages:npm install framer-motion
Then show the source and create each file at the path it gives:
- 6
Use it in a page
Installing only adds the files. Import the component in a page and render it. The Usage tab on the preview shows a fuller example with props:
// src/app/page.tsx import { AnimatedAccordion } from "@/components/animated-accordion"; export default function Page() { return ( <main> <AnimatedAccordion /> </main> ); }
Like Animated Accordion? 256 more are in Pro.
Pro unlocks all 256 Pro components, every template and block, and everything we release next. Animated Accordion stays free.
Animated Accordion questions
How do I install the animated accordion?
Run `npx shadcn@latest add @nexus-labs/animated-accordion`. It adds the AnimatedAccordion component and installs framer-motion.
How do I add my own questions?
Pass `items` as an array of `{ id?, title, hint?, content }`. `content` can be plain text or any React node, such as a paragraph with a link. `hint` is an optional small line under the title.
How do I let more than one panel stay open?
Set `type="multiple"`. The default, `type="single"`, keeps one entry open and closes the others. In single mode, `collapsible={false}` stops the open entry from being closed again.
Is it accessible?
Each title is a real button inside a heading, with `aria-expanded` and `aria-controls`, and each panel is a labelled region. Closed answers are removed from the page, so nothing hidden can be tabbed into. Up, Down, Home and End move between titles. With reduced motion on, panels open and close instantly.
Does it work in dark mode?
Yes. Set `tone="dark"` for a dark surface. Both tones are styled with fixed colours, so it looks the same whatever the page theme is.