Accordion
Also called collapsible sections or expandable FAQ
A vertical stack of headings that each expand to reveal their content when clicked, so long pages stay short and easy to scan.
import { Accordion } from '@base-ui/react/accordion';
const FAQ = [
{
id: 'cancel',
question: 'Can I cancel anytime?',
answer: 'Yes. Your plan stays active until the end of the billing period.'
},
{
id: 'refunds',
question: 'Do you offer refunds?',
answer: 'We refund unused months on yearly plans within 30 days.'
},
{
id: 'switch',
question: 'Can I switch plans later?',
answer: 'Upgrade or downgrade from Billing; we prorate the difference.'
}
];
// Without `multiple`, opening one answer closes the one that was open.
export function PricingFaq() {
return (
<Accordion.Root
defaultValue={['cancel']}
className='w-96 divide-y border-y'
>
{FAQ.map(({ id, question, answer }) => (
<Accordion.Item key={id} value={id}>
<Accordion.Header>
<Accordion.Trigger className='group flex w-full items-center justify-between gap-4 py-4 text-left text-sm font-medium outline-none focus-visible:underline'>
{question}
<svg
viewBox='0 0 16 16'
fill='none'
stroke='currentColor'
strokeWidth={1.5}
aria-hidden='true'
className='size-4 shrink-0 transition-transform duration-250 group-data-panel-open:rotate-180'
>
<path d='m4 6 4 4 4-4' />
</svg>
</Accordion.Trigger>
</Accordion.Header>
{/* Base UI measures the answer and exposes it as --accordion-panel-height. */}
<Accordion.Panel className='h-(--accordion-panel-height) overflow-hidden text-sm text-muted-foreground transition-[height] duration-250 ease-[cubic-bezier(0.23,1,0.32,1)] data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none'>
<p className='pb-4'>{answer}</p>
</Accordion.Panel>
</Accordion.Item>
))}
</Accordion.Root>
);
}Turn the pricing FAQ into an accordion: each question is a button with aria-expanded, clicking it expands the answer by animating its height over 250ms with cubic-bezier(0.23, 1, 0.32, 1), and the chevron rotates 180°. Allow only one answer open at a time, start with the first one open, and skip the height animation when prefers-reduced-motion is set.
Paste into Layerwise or any AI coding tool.
What is Accordion?
An accordion shows a list of headings, such as FAQ questions, with the details hidden. Clicking a heading slides its section open, and a chevron rotates to show the state. Some accordions close the open section when you open another; others let several stay open.
Use accordions for FAQs, groups of settings, and long reference content where people need only one or two sections. Content that most people need to read should stay visible, since hiding it costs a click. Make each heading a real button with aria-expanded.
Animate the height so content does not jump, over about 200 to 300ms with an ease-out curve. The native <details> element opens and closes with no script, giving several of them the same name lets only one stay open, and interpolate-size: allow-keywords lets CSS animate to height: auto in Chromium browsers.
Often confused with
- Tabs
- Tabs show one panel at a time in the same spot. An accordion stacks sections vertically and can open more than one.
Related terms
All termsHeight auto animation
An animation that opens or closes a panel to the exact height of its content, even though that height is unknown ahead of time.
Tabs
A row of labels that switches between panels of related content in the same spot, showing one panel at a time.
Layout animation
An animation that smoothly moves and resizes elements when the layout changes, such as list items gliding to new spots after a sort or filter.
Reduced motion
An operating system setting that asks apps to minimize movement, which websites detect with the prefers-reduced-motion media query.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.