Accordion
An accordion stacks sections under their titles and opens them one at a time, so a long page stays short.
When to use
Section titled “When to use”- 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.
Anatomy
Section titled “Anatomy”- 1Open section header
- 2Content
- 3Closed section
- 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).
Variants
Section titled “Variants”| 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> )}<script setup lang="ts">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." },]</script>
<template> <Accordion type="single" collapsible class="w-full max-w-md"> <AccordionItem v-for="item in questions" :key="item.q" :value="item.q"> <AccordionTrigger>{{ item.q }}</AccordionTrigger> <AccordionContent>{{ item.a }}</AccordionContent> </AccordionItem> </Accordion></template>import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
const questions = [ ('Berapa lama clearance selesai?', 'Biasanya 5–7 hari kerja setelah dokumenmu lengkap. Kamu dapat kabar di setiap langkah.'), ('Lagu apa saja yang bisa kamu cover?', 'Lagu yang ada di katalog kami. Cari judulnya di menu Katalog.'), ('Kapan royalti dibayar?', 'Setiap bulan, paling lambat tanggal 25, ke rekening yang terdaftar di akunmu.'),];
class AccordionDemo extends StatelessWidget { const AccordionDemo({super.key});
@override Widget build(BuildContext context) { return ConstrainedBox( constraints: const BoxConstraints(maxWidth: 448), child: ShadAccordion<int>( children: [ for (var i = 0; i < questions.length; i++) ShadAccordionItem(value: i, title: Text(questions[i].$1), child: Text(questions[i].$2)), ], ), ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/accordion.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/accordion.jsonAccessibility
Section titled “Accessibility”- Each trigger is a button with
aria-expandedandaria-controlspointing 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.
