Prototyper UI

Accordion

vertically stacked collapsible content panels

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/accordion.json
npx shadcn@latest add https://prototyper-ui.com/r/accordion.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/accordion.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/accordion.json

This will add the following files to your project:

  • components/ui/accordion.tsx

Usage

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

<Accordion>
  <AccordionItem>
    <AccordionTrigger>Is it accessible?</AccordionTrigger>
    <AccordionContent>
      Yes. It adheres to the WAI-ARIA Accordion pattern.
    </AccordionContent>
  </AccordionItem>
</Accordion>

Anatomy

<Accordion>
  <AccordionItem>
    <AccordionTrigger />
    <AccordionContent />
  </AccordionItem>
</Accordion>
Sub-componentdata-slotPurposeRequired
AccordionaccordionRoot provider, manages expanded stateYes
AccordionItemaccordion-itemWrapper for a single collapsible sectionYes
AccordionTriggeraccordion-triggerButton that toggles the panel open/closedYes
AccordionContentaccordion-contentCollapsible content panelYes

Examples

Disabled

Loading...

Styling

Data Slots

Use data-slot attributes to target specific parts of the accordion:

Slot nameElement
accordionRoot wrapper
accordion-itemIndividual collapsible section
accordion-triggerToggle button (includes chevron)
accordion-trigger-iconChevron icon inside the trigger
accordion-contentCollapsible content panel

Customization Examples

/* Remove border between items */
[data-slot="accordion-item"] {
  @apply border-b-0;
}

/* Custom trigger icon color */
[data-slot="accordion-trigger-icon"] {
  @apply text-primary;
}
{/* Override content padding via className */}
<AccordionContent className="pb-6">
  {/* ... */}
</AccordionContent>

API Reference

Accordion

Root component that manages the expanded/collapsed state of all items.

Prop

Type

All Base UI Accordion.Root props are forwarded via ...props.

AccordionItem

Wrapper for a single collapsible section containing a trigger and content panel.

Prop

Type

All Base UI Accordion.Item props are forwarded via ...props.

AccordionTrigger

Button that toggles the visibility of the associated content panel.

Prop

Type

All Base UI Accordion.Trigger props are forwarded via ...props.

AccordionContent

Collapsible content panel that animates open and closed.

Prop

Type

All Base UI Accordion.Panel props are forwarded via ...props.

Accessibility

Keyboard Interactions

KeyAction
SpaceToggles the focused accordion item open/closed
EnterToggles the focused accordion item open/closed
ArrowDownMoves focus to the next accordion trigger
ArrowUpMoves focus to the previous accordion trigger
HomeMoves focus to the first accordion trigger
EndMoves focus to the last accordion trigger
TabMoves focus to the next focusable element

ARIA Attributes

  • Each trigger renders with role="button" inside a heading element.
  • aria-expanded indicates whether the associated panel is open.
  • aria-controls on each trigger links to its corresponding content panel.
  • aria-disabled is set on disabled triggers.
  • Each content panel renders with role="region".
  • aria-labelledby on each panel links back to its corresponding trigger.

On this page