sveltelean Primitives
Version v0.18.0
An exclusive group
Shipping Orders ship within two working days from the Rotterdam warehouse.
Returns Thirty days, with the original packaging.
Warranty Two years on parts and labour, from the date of delivery.
Code
<script lang="ts">
	import '@svelte-lean/styles/accordion.css';
</script>

<details data-slean="accordion" name="faq" open>
	<summary>Shipping</summary>
	Orders ship within two working days from the Rotterdam warehouse.
</details>
<details data-slean="accordion" name="faq">
	<summary>Returns</summary>
	Thirty days, with the original packaging.
</details>
<details data-slean="accordion" name="faq">
	<summary>Warranty</summary>
	Two years on parts and labour, from the date of delivery.
</details>
The items share a name, so opening one closes the other. Works with JavaScript disabled.

Examples

Several open

Items without a name
Notifications Email for mentions and replies; nothing else.
Privacy Your profile is visible to your team only.
Sessions Two browsers are signed in.
Code
<script lang="ts">
	import '@svelte-lean/styles/accordion.css';
</script>

<!-- No name: every item opens and closes on its own. -->
<details data-slean="accordion" open>
	<summary>Notifications</summary>
	Email for mentions and replies; nothing else.
</details>
<details data-slean="accordion" open>
	<summary>Privacy</summary>
	Your profile is visible to your team only.
</details>
<details data-slean="accordion">
	<summary>Sessions</summary>
	Two browsers are signed in.
</details>
Without a shared name, each item opens and closes on its own.

Ghost

One section that shows and hides
Why is the delivery date a range? The carrier confirms the day once the parcel leaves the warehouse. Until then, the range covers the shortest and the longest route.
Code
<script lang="ts">
	import '@svelte-lean/styles/accordion.css';
</script>

<details data-slean="accordion" data-variant="ghost">
	<summary>Why is the delivery date a range?</summary>
	The carrier confirms the day once the parcel leaves the warehouse. Until then, the range
	covers the shortest and the longest route.
</details>
The ghost variant drops the border and the surface: one show-and-hide section in running content.

In a form

Advanced settings
Advanced settings
Code
<script lang="ts">
	import '@svelte-lean/styles/accordion.css';
	import '@svelte-lean/styles/field.css';
	import '@svelte-lean/styles/input.css';
</script>

<div data-slean="field">
	<label for="accordion-repo" data-slean-part="label">Repository name</label>
	<input id="accordion-repo" name="repository" value="harbour-survey" data-slean="input" />
</div>

<!-- Fields in a closed item are still submitted with the form. -->
<details data-slean="accordion" data-variant="ghost">
	<summary>Advanced settings</summary>
	<div data-slean-part="panel" class="stack">
		<div data-slean="field">
			<label for="accordion-branch" data-slean-part="label">Default branch</label>
			<input id="accordion-branch" name="branch" value="main" data-slean="input" />
		</div>
		<div data-slean="field">
			<label for="accordion-topics" data-slean-part="label">Topics</label>
			<input id="accordion-topics" name="topics" placeholder="maps, tides" data-slean="input" />
		</div>
	</div>
</details>

<style>
	.stack {
		display: grid;
		gap: 1rem;
	}
</style>
Fields inside a closed item are still submitted with the form.

Expand and collapse all

Bound open state
Install Add the packages with your package manager.
Configure Register the Vite plugin in vite.config.ts.
Deploy Build once; the output is static HTML and CSS.
Code
<script lang="ts">
	import '@svelte-lean/styles/accordion.css';
	import '@svelte-lean/styles/button.css';

	const sections = [
		{ id: 'install', title: 'Install', text: 'Add the packages with your package manager.' },
		{ id: 'configure', title: 'Configure', text: 'Register the Vite plugin in vite.config.ts.' },
		{ id: 'deploy', title: 'Deploy', text: 'Build once; the output is static HTML and CSS.' }
	];
	let open: Record<string, boolean> = $state({ install: true, configure: false, deploy: false });

	function setAll(value: boolean) {
		for (const section of sections) open[section.id] = value;
	}
</script>

<div class="actions">
	<button type="button" data-slean="button" data-variant="outlined" data-color="neutral" data-size="small" onclick={() => setAll(true)}>
		Expand all
	</button>
	<button type="button" data-slean="button" data-variant="text" data-color="neutral" data-size="small" onclick={() => setAll(false)}>
		Collapse all
	</button>
</div>
{#each sections as section (section.id)}
	<details data-slean="accordion" bind:open={open[section.id]}>
		<summary>{section.title}</summary>
		{section.text}
	</details>
{/each}
bind:open on each item; two buttons write every value.

Rich content

Controls, lists and links inside items
Notifications
Plan

Team plan, renews on 1 March.

  • Ten seats
  • Audit log
Help Read the documentation or write to the support team.
Code
<script lang="ts">
	import '@svelte-lean/styles/accordion.css';
	import '@svelte-lean/styles/checkbox.css';
</script>

<details data-slean="accordion" name="settings" open>
	<summary>Notifications</summary>
	<div data-slean-part="panel" class="stack">
		<label><input type="checkbox" role="switch" data-slean="checkbox" checked /> Mentions</label>
		<label><input type="checkbox" role="switch" data-slean="checkbox" /> Weekly digest</label>
	</div>
</details>
<details data-slean="accordion" name="settings">
	<summary>Plan</summary>
	<div data-slean-part="panel">
		<p>Team plan, renews on 1 March.</p>
		<ul>
			<li>Ten seats</li>
			<li>Audit log</li>
		</ul>
	</div>
</details>
<details data-slean="accordion" name="settings">
	<summary>Help</summary>
	Read the <a href="/docs">documentation</a> or write to the support team.
</details>

<style>
	.stack {
		display: grid;
		gap: 0.5rem;
	}
</style>
An item takes any markup; the panel part wraps content that needs one element.

Usage

Plain markup with a stylesheet: install @svelte-lean/styles. No JavaScript runs.

npm install @svelte-lean/styles
stylesheets
import '@svelte-lean/styles/accordion.css';

Put data-slean="accordion" on each <details>. Items that are adjacent siblings join into one list; anything between them starts a new list.

Give every group its own name: the browser groups all <details> of the document that share a value. Render open on at most one item of a group. Leave name off when several items may be open.

Text can follow the summary directly; the item pads it. Wrap content that needs one element (a grid of fields) in data-slean-part="panel".

Anatomy

PartElementdata-slean-partRequiredNotes
root<details data-slean="accordion">–yesOne per item, no wrapper. Adjacent items join into one list; the same name on every item keeps one open; data-variant="ghost" is the bare look.
summary<summary>–yesThe first child of each item; the header the reader activates.
panelone element after the summarypanelnoWraps content that needs one element. The item pads its content and animates its height without it.

Keyboard

KeyWhenResult
Enter/Spacefocus on a summaryToggles its item (native)
Tab/Shift+TabanywhereMoves between summaries and into open content (native)

Styling

accordion.css draws each item's border and surface, joins adjacent items (one shared border, the outer corners rounded once), the summary row with its hover fill and inset focus ring, the chevron, the content padding, and the height transition on ::details-content where interpolate-size is supported. The ghost variant (data-variant) drops the border, the surface and the inline padding. The tokens it reads:

TokenDefault (light)Applies to
--slean-space-4calc(var(--slean-spacing) * 4)padding-inline, margin-inline, padding-block-end
--slean-bordervar(--slean-neutral-6)border, border-block-start
--slean-radius-lgcalc(var(--slean-radius) * 1.4)border-radius
--slean-surfaceoklch(100% 0 0)background
--slean-fgvar(--slean-neutral-12)color
--slean-space-3calc(var(--slean-spacing) * 3)gap
--slean-control-height-lg2.75remmin-block-size
--slean-space-2calc(var(--slean-spacing) * 2)padding-block
--slean-font-weight-medium500font-weight
--slean-duration-fast100mstransition
--slean-easecubic-bezier(0.2, 0, 0, 1)transition
--slean-icon-chevron-downurl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E")mask
--slean-duration-normal160mstransition
--slean-focus-ringvar(--slean-focus-ring-width) solid var(--slean-focus-ring-color)outline
--slean-focus-ring-width2pxoutline-offset
--slean-mutedvar(--slean-neutral-3)background
--slean-control-height-md2.25remmin-block-size
--slean-radius-smcalc(var(--slean-radius) * 0.6)border-radius
--slean-focus-ring-offset2pxoutline-offset

State selectors the stylesheet targets, all from the platform or ARIA: ::details-content, :focus-visible, :hover, [open].

Variant attributes: data-variant (ghost).

Controlled integration

The open attribute of each item is its state. Bind it per item; an item closed by its exclusive sibling fires toggle, and the binding follows.

faq.svelte
<script lang="ts">
	// Each item's open attribute is its state; bind it. Opening one item of the group closes
	// the other, and Svelte's binding follows through the toggle event.
	const items = [
		{ id: 'shipping', title: 'Shipping', text: 'Orders ship within two working days.' },
		{ id: 'returns', title: 'Returns', text: 'Thirty days, with the original packaging.' }
	];
	let open: Record<string, boolean> = $state({ shipping: true, returns: false });
	const current = $derived(items.find((item) => open[item.id])?.title ?? 'none');
</script>

{#each items as item (item.id)}
	<details data-slean="accordion" name="checkout-faq" bind:open={open[item.id]}>
		<summary>{item.title}</summary>
		{item.text}
	</details>
{/each}
<p>Open: {current}</p>

Under the hood

Runtime and size
Tier
0 · Native
Behavior JS
0 B brotli · 0 B gzip · fixtures/results.json (native-only) · method
Platform features
<details name>, <summary>, toggle, ::details-content, interpolate-size
Shared listeners
none
Per-instance listeners
none
Lazy state
none
Native base
<details> + <summary>, exclusive groups through name

Tier 0: no behavior module. The Vite plugin maps accordion to no module, and the native-only fixture proves the path ships no Svelte Lean JavaScript.

Why this implementation

A disclosure is a button that shows and hides a region and announces its expanded state; an accordion is a list of them where opening one closes the others. The platform has both: <details> and <summary> are the disclosure, and <details> elements with the same name form an exclusive group. Enter and Space toggle an item, each summary is announced as a button with its expanded state, and find-in-page opens the item that holds a match. None of it needs a script.

So the primitive is the attribute on each item, with no wrapper: the stylesheet joins adjacent items into one bordered list, and data-variant="ghost" draws a single section bare. One element and one name for both uses (ADR 0011 §1.5).

The browser owns

  • the open state of every item (the open attribute) and the toggle event
  • closing the open item when another item with the same name opens
  • Enter and Space on each summary, and the summary as a button with an expanded state
  • opening a closed item when find-in-page matches its content

Svelte Lean owns

  • accordion.css: joining adjacent items into a bordered list, the ghost look, the summary row, the chevron, the content padding and the height transition
  • the contract: one name per accordion, at most one item rendered open per name
  • documentation
Accessibility
  • Each <summary> is exposed as a button with an expanded state; no ARIA attribute is needed.
  • Enter and Space toggle an item; Tab moves between summaries and into open content. The optional arrow-key movement of the WAI-ARIA accordion pattern is not provided.
  • A heading inside <summary> is valid HTML, but screen readers differ in whether they still expose it as a heading, so the contract does not require one.
  • <details> has no disabled state; render content that must stay visible outside the accordion.
Platform features
FeatureBaselineOutside the target
<details>, <summary>, the toggle eventWidely availableNot applicable within the support policy
name for exclusive groupsNewly available since September 2024 (Chrome 120, Safari 17.2, Firefox 130)Every item opens on its own
Find-in-page opens a closed itemChrome 97, Firefox 139, Safari 26.2The match inside a closed item is not found
::details-contentNewly available since September 2025 (Chrome 131, Safari 18.4, Firefox 143)The open item carries the content padding; no transition
interpolate-size: allow-keywordsChrome 129; not in Firefox or SafariThe content appears without a transition
Without JavaScript

Fully functional, exclusive groups included: the browser reads the name attribute.

Server rendering and hydration

Static HTML. Render open on the item that starts expanded; the server output is the final state.

Nothing is attached. An item the reader opens before hydration stays open after it.

Compatibility

Exclusive groups are Baseline since September 2024 (Chrome 120, Safari 17.2, Firefox 130); in older browsers every item opens on its own. Find-in-page opens a closed item in Chrome 97, Firefox 139 and Safari 26.2. The height animates only where interpolate-size exists (Chrome 129, not Firefox or Safari); elsewhere the content appears without a transition.

Tests and source