Primitives
Accordion
Collapsible sections built on native details and summary. Works without JavaScript.
Basic
Each item is a <details>. Click a title, or focus it and press Enter or Space, to toggle it. Several items can be open at once.
Titles render in a span by default. Set titleTag to a heading level when the titles belong in the page outline, as in an FAQ section.
How long does shipping take?
Orders ship within two working days.
Can I return an item?
Yes, within 30 days of delivery.
Do you ship abroad?
We ship to every country in the EU.
---
import Accordion from '@alfadormx/blocks/primitives/Accordion.astro';
import type { AccordionItem } from '@alfadormx/blocks/types/accordion';
const items: AccordionItem[] = [
{
id: 'shipping',
title: 'How long does shipping take?',
content: '<p>Orders ship within two working days.</p>',
},
{
title: 'Can I return an item?',
content: '<p>Yes, within 30 days of delivery.</p>',
},
{
title: 'Do you ship abroad?',
content: '<p>We ship to every country in the EU.</p>',
},
];
---
<Accordion items={items} />Single
mode="single" gives every item the same name, so the browser closes the open item when another opens. No JavaScript involved.
How long does shipping take?
Orders ship within two working days.
Can I return an item?
Yes, within 30 days of delivery.
Do you ship abroad?
We ship to every country in the EU.
---
import Accordion from '@alfadormx/blocks/primitives/Accordion.astro';
import type { AccordionItem } from '@alfadormx/blocks/types/accordion';
const items: AccordionItem[] = [
{
id: 'shipping',
title: 'How long does shipping take?',
content: '<p>Orders ship within two working days.</p>',
},
{
title: 'Can I return an item?',
content: '<p>Yes, within 30 days of delivery.</p>',
},
{
title: 'Do you ship abroad?',
content: '<p>We ship to every country in the EU.</p>',
},
];
---
<Accordion items={items} mode="single" />Open by default
How long does shipping take?
Orders ship within two working days.
Can I return an item?
Yes, within 30 days of delivery.
Do you ship abroad?
We ship to every country in the EU.
---
import Accordion from '@alfadormx/blocks/primitives/Accordion.astro';
import type { AccordionItem } from '@alfadormx/blocks/types/accordion';
const items: AccordionItem[] = [
{
id: 'shipping',
title: 'How long does shipping take?',
content: '<p>Orders ship within two working days.</p>',
},
{
title: 'Can I return an item?',
content: '<p>Yes, within 30 days of delivery.</p>',
},
{
title: 'Do you ship abroad?',
content: '<p>We ship to every country in the EU.</p>',
},
];
---
<Accordion items={items} defaultOpen={[0, 2]} />Rich content from slots
An item-N slot (0-based) replaces that item’s content. Keep slotted answers to static markup.
What is in the box?
- The device
- A USB-C cable
Can I return an item?
Yes, within 30 days of delivery.
---
import Accordion from '@alfadormx/blocks/primitives/Accordion.astro';
import type { AccordionItem } from '@alfadormx/blocks/types/accordion';
const items: AccordionItem[] = [
{
id: 'shipping',
title: 'How long does shipping take?',
content: '<p>Orders ship within two working days.</p>',
},
{
title: 'Can I return an item?',
content: '<p>Yes, within 30 days of delivery.</p>',
},
{
title: 'Do you ship abroad?',
content: '<p>We ship to every country in the EU.</p>',
},
];
---
<Accordion items={[{ title: 'What is in the box?' }, items[1]]}>
<Fragment slot="item-0">
<ul>
<li>The device</li>
<li>A USB-C cable</li>
</ul>
</Fragment>
</Accordion>Nested
An Accordion can sit inside another’s slot. Each chevron follows its own item, so an inner item stays closed and unrotated while its parent is open.
Delivery options
How long does shipping take?
Orders ship within two working days.
Do you ship abroad?
We ship to every country in the EU.
Can I return an item?
Yes, within 30 days of delivery.
---
import Accordion from '@alfadormx/blocks/primitives/Accordion.astro';
import type { AccordionItem } from '@alfadormx/blocks/types/accordion';
const items: AccordionItem[] = [
{
id: 'shipping',
title: 'How long does shipping take?',
content: '<p>Orders ship within two working days.</p>',
},
{
title: 'Can I return an item?',
content: '<p>Yes, within 30 days of delivery.</p>',
},
{
title: 'Do you ship abroad?',
content: '<p>We ship to every country in the EU.</p>',
},
];
---
<Accordion items={[{ title: 'Delivery options' }, items[1]]} defaultOpen={[0]}>
<Fragment slot="item-0">
<Accordion items={[{ ...items[0], id: undefined }, items[2]]} />
</Fragment>
</Accordion>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| items | AccordionItem[] | — | Items rendered in order, one `<details>` each |
| mode | AccordionMode | 'multiple' | 'single' lets one item be open at a time through the native `name` attribute; 'multiple' lets items open independently (default: 'multiple') |
| name | string | — | Group name written to every `<details>` in 'single' mode; generated when omitted. Ignored in 'multiple' |
| defaultOpen | number[] | [] | Indices of items open on first render; at most one in 'single' mode (default: []) |
| titleTag | AccordionTitleTag | 'span' | Element wrapping each title inside `<summary>`; pick a heading to add titles to the outline (default: 'span') |
| icon | Omit<IconConfig, 'ariaLabel'> | false | { name: 'heroicons:chevron-down' } | Decorative icon at the end of each summary row, rotated while the item is open; `false` hides it (default: { name: 'heroicons:chevron-down' }) |
| class | string | — | Custom classes for the root wrapper |
| itemClass | string | — | Custom classes for each `<details>` (default: 'border-b border-border') |
| summaryClass | string | — | Custom classes for each `<summary>` row |
| titleClass | string | — | Custom classes for each title element (default: 'm-0 font-semibold text-normal') |
| contentClass | string | — | Custom classes for each content panel (default: 'pb-4 text-muted') |
| iconClass | string | — | Custom classes for each icon (default: 'size-5 shrink-0 text-muted') |