Accordion
Panels open to their real height on a spring while their contents rise in one after another.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/accordionThis adds components/keyframery/accordion.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { Accordion, AccordionHeader, AccordionItem, AccordionPanel, AccordionTrigger } from "@/components/keyframery/accordion"
export default function Usage() {
return (
<Accordion>
<AccordionItem value="returns">
<AccordionHeader>
<AccordionTrigger>Can I return it?</AccordionTrigger>
</AccordionHeader>
<AccordionPanel>Yes, within 30 days of delivery.</AccordionPanel>
</AccordionItem>
</Accordion>
)
}Anatomy
How the parts fit together:
Accordion
└── AccordionItem
├── AccordionHeader
│ └── AccordionTrigger
└── AccordionPanelExamples
Basic
One item open at a time. Opening another closes the first.
Several open at once
Pass multiple to let items open independently, and defaultValue to choose which start open.
Controlled
Pass value and onValueChange to open items from your own state.
Disabled item
Pass disabled to an item to keep it shut.
Motion
| Move | What you see |
|---|---|
| Height | A panel opens to its real height and closes back the same way. |
| Cascade | The panel's contents rise in one after another as it opens. |
| Spring | The chevron turns on a spring. |
Timing and springiness follow the motion style you set. To change how fast this accordion moves, pass speed:
<Accordion speed="fast">
…
</Accordion>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--accordion-border | Row dividers | --border |
--accordion-radius | Trigger corners | 8px |
--accordion-padding | Trigger vertical padding | 0.875rem |
--accordion-ink | Trigger and active icon text | --foreground |
--accordion-muted | Panel and resting icon text | --muted-foreground |
API reference
Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK accordion reference.
Accordion
Renders a <div>, and takes its props too.
Prop
Type
AccordionItem
Renders a <div>, and takes its props too.
Prop
Type
AccordionTrigger
Renders a <button>, and takes its props too.
Prop
Type
AccordionPanel
Renders a <div>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
AccordionHeader: a<h2>
Keyboard
| Key | What it does |
|---|---|
| Enter | Opens or closes the focused item. |
| Space | Opens or closes the focused item. |
| ↓ | Moves to the next item's trigger. |
| ↑ | Moves to the previous item's trigger. |
| Home | Moves to the first trigger. |
| End | Moves to the last trigger. |
Accessibility
Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.
Swap the import
Already using UI SDK's accordion with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.
// Before
import { … } from "@ui-sdk/react/accordion"
// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/accordion"Questions
How does the animated Accordion for UI SDK move?
Height: A panel opens to its real height and closes back the same way. Cascade: The panel's contents rise in one after another as it opens. Spring: The chevron turns on a spring.
Do I need Motion or Framer Motion for the animated Accordion?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
Can I keep my own styling and only take the motion?
Yes. Import from @/components/keyframery/primitives/accordion instead. It has the same parts and props as @ui-sdk/react/accordion and adds motion only.
What happens to the Accordion when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.