Skip to content
Navigation Core Stable

Accordion

.md

A stack of headed sections where one or several open at a time, with a collapse that animates without measuring, arrow-key navigation between headers and labelled regions for assistive tech.

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { Accordion } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import {
		Accordion,
		AccordionItem,
		AccordionTrigger,
		AccordionContent,
	} from "fancy-ui-svelte";

	let value = $state("shipping");
</script>

<Accordion type="single" collapsible bind:value class="w-full max-w-md">
	<AccordionItem value="shipping">
		<AccordionTrigger>How long does shipping take?</AccordionTrigger>
		<AccordionContent>Orders leave the warehouse within two working days.</AccordionContent>
	</AccordionItem>
	<AccordionItem value="returns">
		<AccordionTrigger>Can I return an item?</AccordionTrigger>
		<AccordionContent>
			Yes, within 30 days, as long as it is unused and in its original packaging.
		</AccordionContent>
	</AccordionItem>
	<AccordionItem value="support">
		<AccordionTrigger>How do I reach support?</AccordionTrigger>
		<AccordionContent>Write to us any time and we reply within one working day.</AccordionContent>
	</AccordionItem>
</Accordion>

Examples

Basic Usage

One item open at a time, and the open item can be closed again.

Multiple

Any number of items open at once, with one item disabled.

Controlled

The open item driven from outside through a bound value.

Props

PropTypeDefaultDescription
type "single" | "multiple""single""single" keeps one item open at a time, "multiple" lets any number be open.
value string | string[]-The open item, bindable. A string for type="single" ("" when none is open), a string array for type="multiple".
onValueChange (value: string | string[]) => void-Called with the new value each time an item toggles.
collapsible booleanfalseWith type="single", lets the open item be closed again. Without it one item stays open once opened.
disabled booleanfalseDisables every item.
orientation "horizontal" | "vertical""vertical"The axis the items stack on, and which arrow-key pair moves focus.
class string-Additional CSS classes, merged onto the root.
ref HTMLDivElement | nullnullBindable reference to the root element.
AccordionItem.value *string-This item's value: what the accordion's value holds while it is open.
AccordionItem.disabled booleanfalseDisables just this item; its trigger is skipped by the arrow keys.
AccordionItem.class string-Additional CSS classes, merged onto the item.
AccordionItem.ref HTMLDivElement | nullnullBindable reference to the item element.
AccordionTrigger.headingLevel 1 | 2 | 3 | 4 | 5 | 63The level of the heading that wraps the trigger button.
AccordionTrigger.disabled booleanfalseDisables just this trigger, on top of its item and the accordion.
AccordionTrigger.class string-Additional CSS classes, merged onto the trigger button.
AccordionTrigger.ref HTMLButtonElement | nullnullBindable reference to the trigger's button element.
AccordionContent.forceMount booleantrueKeeps the children mounted while the item is closed. Pass false to unmount them once the collapse has finished.
AccordionContent.class string-Additional CSS classes, merged onto the inner body so padding collapses with the panel.
AccordionContent.ref HTMLDivElement | nullnullBindable reference to the region element that animates.

Slots

SlotDescription
children The AccordionItems.
AccordionItem.children An AccordionTrigger and an AccordionContent.
AccordionTrigger.children The trigger's label.
AccordionContent.children The item's content.