Accordion

A vertically stacked set of interactive headings that each reveal an associated section of content.

Anatomy

<script>
  import {
    Accordion,
    AccordionItem,
    AccordionItemTrigger,
    AccordionItemContent,
  } from "@saas-ui/svelte/components/accordion";
</script>

<Accordion.Root collapsible>
  <AccordionItem value="item-1">
    <AccordionItemTrigger>Section 1</AccordionItemTrigger>
    <AccordionItemContent>Content for section 1</AccordionItemContent>
  </AccordionItem>
  <AccordionItem value="item-2">
    <AccordionItemTrigger>Section 2</AccordionItemTrigger>
    <AccordionItemContent>Content for section 2</AccordionItemContent>
  </AccordionItem>
</Accordion.Root>

Examples

Basic Accessibility

Basic accordion with default styling and collapsible behavior.

Controlled Accessibility

Controlled accordion with pre-selected item using the value prop.

Disabled Item Accessibility

Individual accordion items can be disabled to prevent interaction.

Multiple Accessibility

Multiple accordion items can be expanded at the same time using the multiple prop.

Sizes Accessibility

Use the size prop to change the size of the accordion. Available sizes: sm, md, lg.

Variants Accessibility

Use the variant prop to change the visual style. Available variants: outline, subtle, enclosed, plain.

With Icon Accessibility

Accordion items with icons in the trigger for visual context.

Props

Accordion.Root

The root container component for the accordion.

Prop Type Default Description
children Snippet - Content to render inside the accordion (composition API).
items AccordionItem[] - Array of items for simple usage.
collapsible boolean false Whether accordion items can be collapsed.
multiple boolean false Whether multiple accordion items can be open at once.
defaultValue string[] - The default value(s) of the accordion items to open.
id string - Unique identifier for the accordion. Required for accessibility.
size "sm" | "md" | "lg" "md" The size of the accordion.
variant "outline" | "subtle" | "enclosed" | "plain" "outline" The visual style of the accordion.
onPrefetch (value: string) => void - Callback invoked when hovering over an item (for prefetching content). Similar to Astro's link prefetching, this allows preloading data before selection.
class string - Additional CSS classes to apply.

AccordionItem

A single accordion item containing a trigger and content.

Prop Type Default Description
children Snippet - The content of the accordion item (trigger and content).
value string - The unique value of the item.
disabled boolean false Whether the item is disabled.
class string - Additional CSS classes to apply.

AccordionItemTrigger

The clickable header that expands/collapses the content.

Prop Type Default Description
children Snippet - The content of the trigger.
class string - Additional CSS classes to apply.

AccordionItemContent

The collapsible content section of an accordion item.

Prop Type Default Description
children Snippet - The content of the accordion item.
class string - Additional CSS classes to apply.