Skip to content
All components
Data display

Accordion

Stack related sections under headings that each expand or collapse, so people can scan the headings and open only what they need.

A disclosure list built on Radix Accordion.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add accordion

Then import it from @/components/ui/accordion. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Multiple open

Let several sections stay open at once with type multiple. Suits settings or reference pages where readers compare sections; defaultValue opens the first one. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@/components/ui/accordion"

export function AccordionMultipleOpen() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <Accordion type="multiple" defaultValue={["notifications"]} className="flex w-full flex-col gap-2">
        <AccordionItem value="notifications">
          <AccordionTrigger>Notification settings</AccordionTrigger>
          <AccordionContent>
            Email digests are sent every Monday. Mentions and direct messages
            notify you immediately.
          </AccordionContent>
        </AccordionItem>
        <AccordionItem value="privacy">
          <AccordionTrigger>Privacy settings</AccordionTrigger>
          <AccordionContent>
            Your profile is visible to members of your workspace only.
          </AccordionContent>
        </AccordionItem>
        <AccordionItem value="sessions">
          <AccordionTrigger>Active sessions</AccordionTrigger>
          <AccordionContent>
            Two devices are signed in. Sign out of a device from its row.
          </AccordionContent>
        </AccordionItem>
      </Accordion>
    </div>
  )
}

Controlled expand all

Control open sections from the parent, with an expand-all action. value and onValueChange keep the open list in parent state so an external button can open or close every section. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@/components/ui/accordion"
import { Button } from "@/components/ui/button"

const policies = [
  {
    value: "shipping",
    title: "How long does shipping take?",
    body: "Orders leave the warehouse within two business days. Delivery takes three to five business days after that.",
  },
  {
    value: "returns",
    title: "Can I return an item?",
    body: "Unused items can be returned within 30 days. Start a return from your order history; the label is free.",
  },
  {
    value: "warranty",
    title: "What does the warranty cover?",
    body: "Manufacturing defects for two years from delivery. Accidental damage is not covered.",
  },
]

function ControlledAccordion() {
  const [open, setOpen] = React.useState<string[]>(["returns"])
  const allOpen = open.length === policies.length

  return (
    <div className="flex w-full max-w-md flex-col gap-3">
      <div className="flex justify-end">
        <Button
          type="button"
          size="xs"
          intent="neutral"
          emphasis="ghost"
          onClick={() => setOpen(allOpen ? [] : policies.map((policy) => policy.value))}
        >
          {allOpen ? "Collapse all policies" : "Expand all policies"}
        </Button>
      </div>
      <Accordion type="multiple" value={open} onValueChange={setOpen} className="flex flex-col gap-2">
        {policies.map((policy) => (
          <AccordionItem key={policy.value} value={policy.value}>
            <AccordionTrigger>{policy.title}</AccordionTrigger>
            <AccordionContent>{policy.body}</AccordionContent>
          </AccordionItem>
        ))}
      </Accordion>
    </div>
  )
}

export function AccordionControlledExpandAll() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <ControlledAccordion />
    </div>
  )
}

Disabled item

Keep an unavailable section visible but not operable. The trigger text says why it is unavailable instead of hiding the section. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@/components/ui/accordion"

export function AccordionDisabledItem() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <Accordion type="single" collapsible className="flex w-full flex-col gap-2">
        <AccordionItem value="profile">
          <AccordionTrigger>Profile details</AccordionTrigger>
          <AccordionContent>Name, photo and the time zone used for reminders.</AccordionContent>
        </AccordionItem>
        <AccordionItem value="billing" disabled>
          <AccordionTrigger>Billing details (available to workspace owners)</AccordionTrigger>
          <AccordionContent>Payment method and invoices.</AccordionContent>
        </AccordionItem>
      </Accordion>
    </div>
  )
}

Always one open

Keep exactly one step open with a non-collapsible single accordion. Opening a step closes the previous one, and the open step cannot be closed by itself. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@/components/ui/accordion"

export function AccordionAlwaysOneOpen() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <Accordion type="single" defaultValue="step-1" className="flex w-full flex-col gap-2">
        <AccordionItem value="step-1">
          <AccordionTrigger>Step 1: Choose a plan</AccordionTrigger>
          <AccordionContent>Pick the plan that matches your team size. You can change it later.</AccordionContent>
        </AccordionItem>
        <AccordionItem value="step-2">
          <AccordionTrigger>Step 2: Invite your team</AccordionTrigger>
          <AccordionContent>Add teammates by email; they receive an invitation link.</AccordionContent>
        </AccordionItem>
        <AccordionItem value="step-3">
          <AccordionTrigger>Step 3: Connect your calendar</AccordionTrigger>
          <AccordionContent>Connecting is optional and can be done from settings at any time.</AccordionContent>
        </AccordionItem>
      </Accordion>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Accordion

Reveal sections of related content through repeated disclosure controls.

Accordion props
PropTypeDefaultDescription
valuestring | string[] | undefined—The controlled stateful value of the accordion item whose content is expanded. The controlled stateful value of the accordion items whose contents are expanded.
defaultValuestring | string[] | undefined—The value of the item whose content is expanded when the accordion is initially rendered. Use defaultValue if you do not need to control the state of an accordion. The value of the items whose contents are expanded when the accordion is initially rendered. Use defaultValue if you do not need to control the state of an accordion.
onValueChange((value: string) => void) | ((value: string[]) => void) | undefined—The callback that fires when the state of the accordion changes.
disabledboolean | undefined—Whether or not an accordion is disabled from user interaction.
orientation("horizontal" | "vertical") | undefined—The layout in which the Accordion operates.
dir("ltr" | "rtl") | undefined—The language read direction.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (14)
Accordion inherited props
PropTypeDefaultDescription
type(required)"single" | "multiple"—Expansion mode: single uses one item value; multiple uses an array of expanded item values.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

AccordionContent

Content region within the root composition. Keep required providers, labels and related controls from the complete example.

AccordionContent props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
forceMounttrue | undefined—Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
Inherited props (14)
AccordionContent inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

AccordionItem

One item within its parent composition. Keep parent context and the value, label or state required by the source API.

AccordionItem props
PropTypeDefaultDescription
disabledboolean | undefined—Whether or not an accordion item is disabled from user interaction.
value(required)string—A string value for the accordion item. All items within an accordion should use a unique value.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (14)
AccordionItem inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

AccordionTrigger

Interactive control that opens or toggles the associated content. Preserve its accessible name and the required root context.

AccordionTrigger props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (19)
AccordionTrigger inherited props
PropTypeDefaultDescription
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLButtonElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLButtonElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLButtonElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLButtonElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
namestring | undefined—Name used by the control's form submission or primitive form integration.
type"button" | "submit" | "reset" | undefined—Expansion mode: single uses one item value; multiple uses an array of expanded item values.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
refReact.Ref<HTMLButtonElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

Accessibility & usage

From registry/ui/accordion.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Frequently asked questions, policies or help content where most readers need one or two answers out of many.
  • Long settings or reference pages split into named groups that are rarely needed all at once.
  • Step-by-step content shown one step at a time (type single without collapsible keeps exactly one open).
  • Mobile layouts where showing every section in full would make the page very long.

When not to use

  • A single optional region, such as 'Show details'; a collapsible is simpler and not a list of headed sections.
  • Switching between alternative views of the same content where one is always shown; use tabs.
  • Content most people need; hiding it adds a click and makes the page harder to search with find-in-page.
  • Navigation menus; use navigation components with links.

Anatomy

Accordion
Radix root. type="single" (one open; add collapsible to allow none) or type="multiple"; value/defaultValue/onValueChange, disabled, orientation and dir.
AccordionItem
One section with a unique value; can be disabled. Styled as a bordered surface.
AccordionTrigger
A button inside a Radix Header (rendered as h3) that toggles its item and carries aria-expanded and aria-controls; a decorative chevron rotates when open.
AccordionContent
The region the trigger controls, labelled by the trigger; animates height and is removed from the tab order when closed.

Keyboard & interaction

  • Enter or Space on a trigger opens or closes its section (WAI-ARIA accordion pattern).
  • Arrow Down and Arrow Up move focus between triggers, Home and End jump to the first and last; Tab moves into open content and on to the next trigger.
  • Disabled items are skipped and cannot toggle; disabling the root disables every item.
  • In type single, opening one section closes the previous; without collapsible the open section cannot be closed directly.
  • Use value and onValueChange to control open sections from outside, for example an 'Expand all' button in type multiple.
  • Open and close animations stop when the user prefers reduced motion.

Responsive behavior

  • Triggers span the full width and wrap long headings onto several lines; the chevron stays at the end.
  • Keep each trigger at least 24 CSS pixels tall (the default padding gives more) and leave space between items for touch.
  • Long content inside a section must reflow at 320 CSS pixels; avoid fixed-width tables or code without their own scroll region.
  • On large screens, consider showing the content directly if there are only a few short sections.

Content guidelines

  • Write triggers as the question or topic a reader is scanning for ('How long does shipping take?'), front-loading the key words.
  • Keep trigger text short and specific; do not repeat the same prefix on every item.
  • Answer directly in the first sentence of the content.
  • If an item is disabled, say why in its label or nearby text.
  • Order sections by how often people need them, not alphabetically by default.

Alternatives

  • Collapsible — One optional region with its own trigger, not a set of headed sections.
  • Tabs — Mutually exclusive views where exactly one panel is visible and the labels are short.
  • Card — Short sections that are all useful at once and can simply be shown.

Resources