Accordion
Expandable sections with built-in keyboard interaction.
Give your AI assistant this page as context.
Connect your library with MCPui/accordionUsage
Get this component from a saved library export or the connected CLI. The imports below refer to local files installed in your app.
Import styles/components.css, then styles/theme.css once. Wrap your app in ThemeScope from components/ui/utils so typography, focus and overlays share the theme. The installation guide covers runtime dependencies and React/Next.js setup.
import { Accordion } from './components/ui/accordion';
<Accordion items={[{value:"ownership",title:"Do I own the code?",content:"Yes. Export it and use it in your own project."},{value:"runtime",title:"Does it need a server?",content:"The exported components run independently."}]}/>Design system
This component consumes your semantic colors, spacing, typography and shape tokens. Import the compiled styles and your theme once as described in Export.
Behavior and accessibility
- Provide meaningful labels for interactive controls.
- Connect action callbacks to your application logic.
- Verify keyboard navigation and contrast in your application.
Status: experimental during early access. Sample previews do not send emails, process payments or upload files to a service.
Source and props
This is the exported source, using the same implementation as the editor.
"use client";
import { Accordion as Base } from "@base-ui/react/accordion";
import type { ReactNode } from "react";
export function Accordion({
items,
multiple = false,
value,
defaultValue,
onValueChange,
disabled = false,
keepMounted = false,
}: {
items: Array<{
value: string;
title: string;
content: ReactNode;
disabled?: boolean;
}>;
multiple?: boolean;
value?: string[];
defaultValue?: string[];
onValueChange?: (value: string[]) => void;
disabled?: boolean;
keepMounted?: boolean;
}) {
return (
<Base.Root
multiple={multiple}
value={value}
defaultValue={defaultValue}
onValueChange={onValueChange}
disabled={disabled}
className="cr-accordion"
>
{items.map((item) => (
<Base.Item
key={item.value}
value={item.value}
disabled={item.disabled}
className="cr-accordion-item"
>
<Base.Header>
<Base.Trigger className="cr-accordion-trigger">
{item.title}
<span aria-hidden="true">
<svg
width="18"
height="18"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.75"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<path d="M12 5v14M5 12h14" />
</svg>
</span>
</Base.Trigger>
</Base.Header>
<Base.Panel keepMounted={keepMounted} className="cr-accordion-panel">
{item.content}
</Base.Panel>
</Base.Item>
))}
</Base.Root>
);
}