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.

basic
---
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.

single
---
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.

default-open
---
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.

slotted
---
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.

nested
---
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

PropTypeDefaultDescription
itemsAccordionItem[]—Items rendered in order, one `<details>` each
modeAccordionMode'multiple''single' lets one item be open at a time through the native `name` attribute; 'multiple' lets items open independently (default: 'multiple')
namestring—Group name written to every `<details>` in 'single' mode; generated when omitted. Ignored in 'multiple'
defaultOpennumber[][]Indices of items open on first render; at most one in 'single' mode (default: [])
titleTagAccordionTitleTag'span'Element wrapping each title inside `<summary>`; pick a heading to add titles to the outline (default: 'span')
iconOmit<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' })
classstring—Custom classes for the root wrapper
itemClassstring—Custom classes for each `<details>` (default: 'border-b border-border')
summaryClassstring—Custom classes for each `<summary>` row
titleClassstring—Custom classes for each title element (default: 'm-0 font-semibold text-normal')
contentClassstring—Custom classes for each content panel (default: 'pb-4 text-muted')
iconClassstring—Custom classes for each icon (default: 'size-5 shrink-0 text-muted')