---
title: Accordion
description: Collapsible sections with optional anchor copy-link.
---

Accordions collapse/expand client-side. Giving an item an `id` adds a copy-link
button that copies `#<id>` to the clipboard.

## Closed by default

```ts
accordions([
  { title: 'Why pure TypeScript?', content: '<p>No React, no runtime dependencies.</p>' },
  { title: 'How do styles stay isolated?', content: '<p>Everything is namespaced.</p>' },
]);
```

## Open by default, with anchors

```ts
accordion(
  { title: 'Single accordion, open', content: '<p>This one starts expanded.</p>', id: 'open-acc', defaultOpen: true },
);
```

## Props

<PropsTable
  labels={{ prop: 'Option', type: 'Type', default: 'Default' }}
  type={{
    title: { type: 'string', required: true, description: 'Accordion header.' },
    content: { type: 'string', default: "''", description: 'Collapsible body (HTML allowed).' },
    id: { type: 'string', description: 'Anchor id; also enables the copy-link button.' },
    defaultOpen: { type: 'boolean', default: 'false', description: 'Start expanded.' },
  }}
/>

## Notes

- `accordions(items)` wraps a list of `AccordionOptions` in a
  `data-cpd-accordions` container; `accordion(options)` builds a single item.
- The `aria-expanded` attribute is set server-side from `defaultOpen`, then
  maintained by the runtime.
