Accordion
The <x-wirekit:: component creates collapsible content sections with single or multiple open modes. It follows the WAI-ARIA Accordion pattern.
- Accordion (this component) — a coordinated group of panels with optional single-open behavior and card chrome. Opening one panel can close the others.
- Collapsible — a single independent show/hide (a "read more", an advanced-options panel), or a stack of them with no coordination.
- FAQ — this accordion, specialized for questions, that also emits FAQPage structured data derived from what it renders. Use it for a real question list instead of hand-building one here.
Usage
Width & Layout
The accordion fills its parent width. Control the width with Tailwind classes directly on the component:
<x-wirekit::accordion class="max-w-lg">
…
</x-wirekit::accordion>
Modes
Single mode
Opening one item closes all others, as choosing one radio button clears the rest. It suits steps a reader takes one at a time:
Multiple mode
Any combination of items can be open, as with checkboxes. It suits details a reader compares side by side:
Starting Open
open renders an item open from the first paint: its panel shows and its header says so before any script runs, so nothing moves when the page starts. In single mode one item is open at a time, so give open to one; when more items carry it, the first stays open and the others close as the page starts.
A link to an item still opens it, and in single mode it takes the place of the one that started open (Linking to an Item).
To start the items of every accordion in multiple mode open, set components. in the configuration. It applies to an item that does not say otherwise, and in multiple mode only: in single mode a default cannot say which one item to open, so there only an item with open starts open.
With Icons
Use the header named slot to render custom header content with icons:
Variants
The variant prop changes the container chrome. bordered (default) is a
self-contained card; flush drops the outline so the accordion sits inline in
page content (ideal for an FAQ block); separated turns each item into its own
standalone card with a gap between them.
Size
size="lg" gives the trigger roomier padding and a larger title — useful for
marketing pages and touch-first layouts.
Long Titles
A long title wraps within the width the accordion has, and the chevron stays at the end of the header, centered on the title's lines. Switch the preview to 390 to see the titles break:
Find in Page
A closed item's content stays findable by the browser's own search (Ctrl+F or ⌘+F). When a match lands in a closed item, the browser opens it, scrolls to it and highlights the text, and the item's header reports it as expanded. In single mode, the item that was open closes, the same as when its header is clicked.
Closed content is still out of sight, out of the tab order and hidden from screen readers until it opens. Turn it off for content that must stay closed until someone chooses to open it, such as the answer to a quiz question:
<x-wirekit::accordion :findable="false">
<x-wirekit::accordion.item title="Show the answer">The answer is 42.</x-wirekit::accordion.item>
</x-wirekit::accordion>
A Livewire component with #[Lazy] inside a closed item that stays findable, or anything else that waits for x-intersect there, loads with the page rather than when the reader opens it, in a browser that supports hidden="until-found": the closed item keeps its box, so it counts as in view. Set :findable="false" where such content should wait for the reader.
This is a progressive enhancement. It works in browsers that support hidden="until-found"; in the rest, a closed item is hidden entirely and the browser search does not look inside it.
A closed until-found panel stays in the layout. It keeps its box, so get and get report it as visible while the screen is drawn correctly and the reader sees nothing. Playwright's own visibility notion is built on the same geometry.
That matters wherever you ask "is this open?" from outside the component, and the geometry gives the wrong answer:
- In a test, read the
hiddenattribute, not the geometry. A test that measures the box reads every closed item as open, and the number it reports looks plausible enough not to question. - In your own styling, put padding and borders on the element inside the panel. On the panel itself they paint as an empty strip under every closed item. This component and collapsible both do exactly that, for exactly this reason.
Linking to an Item
An item's id stands on the item itself, so a link to it lands there, and the accordion opens it when the page loads, when the address changes, and when the reader follows the link again after closing the item. A link to an element inside a closed item opens that item too, and brings the element into view.
{{-- 1. The item a link can name. --}}
<x-wirekit::accordion>
<x-wirekit::accordion.item title="How long does shipping take?" id="shipping">
Two to three working days.
</x-wirekit::accordion.item>
</x-wirekit::accordion>
{{-- 2. On this page or another one: opens the item and scrolls to it. --}}
<a href="/help#shipping">Shipping times</a>
In single mode, the item that was open closes, the same as when the linked item's header is clicked. An id that names no item leaves every item as it was.
Animation
A panel eases its height open and shut. Set :animate="false" to have it appear and disappear instantly instead.
<x-wirekit::accordion :animate="false">
{{-- The accordion's items --}}
</x-wirekit::accordion>
The easing reads --transition-wk-duration from the element, so a theme that sets the duration to zero gets no motion without touching this prop. It is skipped entirely under prefers-reduced-motion: reduce: the panel still opens, without sliding.
Printing
A printed page shows every item open, the ones the reader closed as well, and leaves the arrows out: paper has no button to open an item with. On screen the accordion keeps the state the reader left it in.
Props
<x-wirekit::accordion>
| Prop | Type | Default | Description |
|---|---|---|---|
mode |
string |
'single' |
'single' (only one open at a time) or 'multiple' |
variant |
string |
'bordered' |
'bordered' (card with outline), 'flush' (inline, dividers only), or 'separated' (each item its own card) |
size |
string |
'md' |
Row density — 'md' or 'lg' (roomier padding + larger trigger text) |
level |
int |
3 |
Heading level (1–6) each item's trigger is wrapped in. Set it to match the surrounding outline — 2 directly under the page <h1>, 4 inside an <h3> section |
findable |
bool |
true |
Let the browser's find in page search closed items and open the one a match lands in. See Find in Page |
animate |
bool |
true |
Ease a panel's height open and shut. Skipped under prefers-reduced-motion: reduce. See Animation |
scope |
string|null |
null |
Scoped personalization key |
<x-wirekit::accordion.item>
| Prop | Type | Default | Description |
|---|---|---|---|
id |
string|null |
auto-generated | The item's id, also the start of its header's and panel's ids. A link to it opens the item. See Linking to an Item |
title |
string |
'' |
Header text (or use the header named slot) |
titleLang |
string|null |
null |
The language of title where it differs from the page's, written on the title alone, so the panel keeps the page's language |
open |
bool|null |
null |
Render the item open from the first paint. In single mode the first item with open stays open. Unset, it follows components.accordion.item.open in multiple mode. See Starting Open |
scope |
string|null |
null |
Scoped personalization key |
Accessibility
- Each header is a heading containing a
<button>(allows AT heading navigation). The level comes from the accordion'slevelprop and defaults to<h3>— set it so the accordion does not skip a level in the page's outline - Button:
aria-expanded(dynamic),aria-controls(linked to panel) - Panel:
role="region",aria-labelledby(linked to button). A closed findable panel carries neither until it opens: it stays in the layout, and as a named region it would be listed among the page's landmarks with nothing in it, next to any other region of the same name - Chevron rotates 180° when open — decorative,
aria-hidden="true" - Arrow keys,
HomeandEndmove focus between the headers and open nothing on the way — a panel opens onEnterorSpace, so a reader can pass through a long accordion without waiting for every panel to reveal itself - Those keys apply while focus is on a header. Inside an open panel they belong to the content,
so
Homestill moves the caret to the start of a line in a field you put there
Keyboard Interaction
| Key | Action |
|---|---|
Tab |
Move focus to the next focusable element: the next header, or a link or field inside an open panel |
Shift+Tab |
Move focus to the previous focusable element |
Enter / Space |
Toggle the focused panel |
ArrowDown / ArrowUp |
Move between accordion headers |
Home / End |
Move to the first / last header |
Pitfalls
- Keep an accordion one level deep where you can. Every nested level is another set of headings for a reader to keep track of. For data that really is nested, reach for
<x-wirekit::.tree-view> - Don't open every panel on load. If everything is open, the accordion is a stack of headings and the disclosure does nothing. Open the panels a reader needs first: one in single mode, the few that belong together in multiple mode. The
components.default opens every item of a multiple-mode accordion, so set it only where each panel is short.accordion. item. open
Design Tokens
| Token | Used for |
|---|---|
--color-wk-bg-elevated |
Accordion container background |
--color-wk-border |
Outer border + per-item separator |
--border-wk-width |
Border width |
--radius-wk-lg |
Container border radius |
Config Defaults
The defaults live in config/ under components.. Override them globally:
'components' => [
'accordion' => [
'mode' => 'multiple', // allow multiple items open by default
'findable' => false, // keep closed items out of the browser's find in page
'animate' => false, // panels appear instantly instead of easing their height
'item' => [
'open' => true, // items start open in multiple mode unless the call says otherwise
],
],
],
Further Reading
- WAI-ARIA Accordion Pattern — the authoring pattern this component implements
- MDN:
aria-expanded - MDN:
role="region" - HTML
<details>vs ARIA Accordion — when to choose each