Display
Accordion
A stack of questions or sections that open one at a time. Use it for FAQs and for details the customer only sometimes needs.
import * as Accordion from '@statix/ui/accordion';Playground
<Accordion.Root type="single" class="border-y">
<Accordion.Item value="backups">
<Accordion.Trigger>How do backups work?</Accordion.Trigger>
<Accordion.Content>We back up your website every night …</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="move">
<Accordion.Trigger>Can I move my existing website to Statix?</Accordion.Trigger>
<Accordion.Content>Yes. We move the website …</Accordion.Content>
</Accordion.Item>
</Accordion.Root>Examples
FAQ
The FAQ style from the landing page: 17px questions, hairlines between rows and a chevron that turns when open. Add border-y to the root to close the list at the top and bottom.
<script lang="ts">
import * as Accordion from '@statix/ui/accordion';
const questions = [
{
value: 'backups',
q: 'How do backups work?',
a: 'We back up your website every night at 03:10 and keep each backup for 30 days. You can restore any of them yourself in the customer area.'
},
{
value: 'move',
q: 'Can I move my existing website to Statix?',
a: 'Yes. Send us your current login details and we move the website, the domain and the mailboxes for you. Your website stays online during the move.'
},
{
value: 'broken',
q: 'What happens if my website breaks?',
a: 'Call Jonas Weber on 040 468 970 790. We check the website, restore the last working backup if needed and tell you what went wrong.'
},
{
value: 'cancel',
q: 'How do I cancel my contract?',
a: 'Open Contracts in the customer area and choose the contract. Hosting contracts end at the close of the paid period.'
}
];
</script>
<Accordion.Root type="single" value="backups" class="w-full max-w-2xl border-y border-border">
{#each questions as item (item.value)}
<Accordion.Item value={item.value}>
<Accordion.Trigger>{item.q}</Accordion.Trigger>
<Accordion.Content>{item.a}</Accordion.Content>
</Accordion.Item>
{/each}
</Accordion.Root>Several open at once
Set type="multiple" when sections are independent, here the parts of a contract inside a card.
WordPress Hosting for yoga-berger.de, 19 € per month.
Renews on 1 March 2027. Notice period one month.
<script lang="ts">
import * as Accordion from '@statix/ui/accordion';
</script>
<div class="w-full max-w-xl rounded-card bg-card px-7 py-2 shadow-card">
<Accordion.Root type="multiple" value={['contract']}>
<Accordion.Item value="contract">
<Accordion.Trigger>Contract</Accordion.Trigger>
<Accordion.Content>
<p>WordPress Hosting for yoga-berger.de, 19 € per month.</p>
<p>Renews on 1 March 2027. Notice period one month.</p>
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="invoices">
<Accordion.Trigger>Invoices</Accordion.Trigger>
<Accordion.Content>
The last invoice was paid on 2 November. <a href="#invoices">Open all invoices</a>
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="payment">
<Accordion.Trigger>Payment method</Accordion.Trigger>
<Accordion.Content>Direct debit, IBAN ending in 4410.</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
</div>FAQ section
Next to a section heading, as on the landing page. The triggers sit inside h3 headings by default; change it with level.
Common questions
<script lang="ts">
import * as Accordion from '@statix/ui/accordion';
</script>
<section class="grid w-full gap-8 tablet:grid-cols-[0.8fr_1.2fr] tablet:gap-16">
<h2 class="text-section text-ink">Common questions</h2>
<Accordion.Root type="single" class="border-y border-border">
<Accordion.Item value="domain">
<Accordion.Trigger level={3}>Can I keep my domain?</Accordion.Trigger>
<Accordion.Content>
Yes. We transfer yoga-berger.de to Statix. Your email keeps working during the transfer.
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="mailboxes">
<Accordion.Trigger level={3}>How many mailboxes are included?</Accordion.Trigger>
<Accordion.Content
>WordPress Hosting includes five mailboxes with 10 GB each.</Accordion.Content
>
</Accordion.Item>
<Accordion.Item value="support">
<Accordion.Trigger level={3}>When can I reach support?</Accordion.Trigger>
<Accordion.Content>Monday to Friday, 8:00 to 20:00, on 040 468 970 790.</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
</section>Guidelines
Do
- Write triggers as the question the customer would ask: "How do backups work?".
- Keep answers short. Link to a help page for anything longer than a paragraph.
- Open the most asked question by default with value.
Don't
- Do not hide required information, prices or legal terms in a closed item.
- Do not nest accordions.
- Do not use an accordion for two items. Show both.
Accessibility
- Each trigger is a <button> with aria-expanded and aria-controls, wrapped in a heading (h3 unless you set level).
- Enter and Space toggle an item. Up and Down arrows move between triggers, Home and End jump to the first and last.
- The chevron is decorative and hidden from screen readers.
- Pick a heading level that fits the page outline. Under an h2 section heading, keep the default 3.
API reference
Accordion.Root
renders<div> and accepts its attributes| Prop | Type | Default |
|---|---|---|
type * | 'single' | 'multiple' single allows one open item, multiple allows any number. | – |
value bind | string | string[] The open item (single) or items (multiple). | – |
onValueChange | (value: string | string[]) => void Called when items open or close. | – |
disabled | boolean Disables every item. | false |
loop | boolean Arrow keys wrap around. | true |
orientation | 'vertical' | 'horizontal' Direction of arrow-key navigation. | 'vertical' |
ref bind | HTMLDivElement | null The root element. | – |
class | ClassValue Merged with the root classes. | – |
| Data attribute | Meaning |
|---|---|
data-slot="accordion" | Always present. |
data-orientation | "vertical" or "horizontal". |
Accordion.Item
renders<div> and accepts its attributesOne row. Draws a hairline under every item except the last.
| Prop | Type | Default |
|---|---|---|
value | string Identifies the item. Generated when omitted. | – |
disabled | boolean Disables this item. | false |
ref bind | HTMLDivElement | null The item element. | – |
class | ClassValue Merged with the item classes. | – |
| Data attribute | Meaning |
|---|---|
data-slot="accordion-item" | Always present. |
data-state | "open" or "closed". |
data-disabled | Present when disabled. |
Accordion.Trigger
renders<button> inside a heading and accepts its attributes| Prop | Type | Default |
|---|---|---|
level | 1 | 2 | 3 | 4 | 5 | 6 Level of the wrapping heading. | 3 |
ref bind | HTMLButtonElement | null The button. | – |
class | ClassValue Merged with the trigger classes. | – |
| Data attribute | Meaning |
|---|---|
data-slot="accordion-trigger" | Always present. |
data-state | "open" or "closed". |
data-slot="accordion-trigger-icon" | The chevron. Style it from the trigger with **:data-[slot=accordion-trigger-icon]. |
Accordion.Content
renders<div> and accepts its attributesThe answer. Animates its height. The class prop goes to the inner wrapper, so padding changes stay inside the animation.
| Prop | Type | Default |
|---|---|---|
forceMount | boolean Keeps the content in the DOM when closed. | false |
ref bind | HTMLDivElement | null The outer element. | – |
class | ClassValue Merged with the inner wrapper classes. | – |
| Data attribute | Meaning |
|---|---|
data-slot="accordion-content" | Always present. |
data-state | "open" or "closed". |