Skip to content

Accordion

Download .md

An accordion stacks sections under their titles and opens them one at a time, so a long page stays short.

  • Use it for questions and answers, settings groups, and details that only some people need.
  • Use Tabs to switch between views of the same thing, and a page when every section matters.
  • Don’t hide required information in a closed section: people may never open it.
  • On phones, an accordion also turns table rows into sections; see the Responsive table pattern.
React

Vue

1234
  1. 1Open section header
  2. 2Content
  3. 3Closed section
  4. 4Chevron

Items separated by a border-b on border. Each item has a trigger (py-4 text-sm font-medium, with a chevron that turns 180° when open) and its content (pb-4 text-sm).

Mode Use it for
One open at a time (default) Questions and answers, where one answer is enough to read.
Several open (multiple) Settings groups that people compare.
React Vue Flutter Type Default Use
multiple type="single" / "multiple" ShadAccordion / ShadAccordion.multiple mode one open How many sections can be open.
always closable collapsible always closable boolean false in Vue Lets the open section close again.
value / defaultValue v-model / default-value initialValue value none The open section.
AccordionItem value AccordionItem value ShadAccordionItem value value none Names a section.
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
const questions = [
{ q: "Berapa lama clearance selesai?", a: "Biasanya 5–7 hari kerja setelah dokumenmu lengkap. Kamu dapat kabar di setiap langkah." },
{ q: "Lagu apa saja yang bisa kamu cover?", a: "Lagu yang ada di katalog kami. Cari judulnya di menu Katalog." },
{ q: "Kapan royalti dibayar?", a: "Setiap bulan, paling lambat tanggal 25, ke rekening yang terdaftar di akunmu." },
]
export default function AccordionDemo() {
return (
<Accordion className="w-full max-w-md">
{questions.map(({ q, a }) => (
<AccordionItem key={q} value={q}>
<AccordionTrigger>{q}</AccordionTrigger>
<AccordionContent>{a}</AccordionContent>
</AccordionItem>
))}
</Accordion>
)
}
Terminal window
npx shadcn@latest add https://design.sosialoka.tech/r/react/accordion.json
  • Each trigger is a button with aria-expanded and aria-controls pointing at its content.
  • Enter and Space open and close a section; Tab moves between triggers.
  • Keep the trigger text a full question or title, so it makes sense on its own.