Skip to Content
CodeUI

Accordion

@codeui/solid v0.3.0

Sections that reveal settings within a sidebar.

When to use

Accordion groups settings in a sidebar. The CodeImage pattern shows an icon, title, value summary, and chevron in each header. One section can be open at a time in the ready component.

A header is a 36px row with a 14px, weight-600 title, 8px before the icon, 10px between its parts and 12px after the chevron. Sections sit 4px apart. The open section sits on the inset fill with a 16px radius, and its icon turns to the accent. Hovering a closed header with a mouse fills it; the open header stays plain.

When to choose another component

Use Tabs for views that share one content area. For one independent disclosure, use an Accordion with a single item and collapsible.

Live demo

Padding around your code is 64 px.

accordion/basic.tsx
import { Accordion } from "@codeui/solid";
export default function Demo() {
	return <Accordion aria-label="Snippet appearance" defaultValue="frame" items={[
	{ value: "frame", title: "Frame", icon: <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor"><rect x="2" y="3" width="12" height="10" rx="2" /></svg>, summary: "64 px", content: <p>Padding around your code is 64 px.</p> },
	{ value: "window", title: "Window", summary: "macOS", content: <p>The title bar uses macOS window controls.</p> },
	{ value: "watermark", title: "Watermark", disabled: true, content: <p>Watermarks are unavailable for this snippet.</p> },
]} />;
}

Anatomy

Padding around your code is 64 px.

Tap a part to outline it in the demo.

  1. 01Rootaccordionclasses.root
  2. 02Itemaccordion-itemclasses.item
  3. 03Headeraccordion-headerclasses.header
  4. 04Triggeraccordion-triggerclasses.trigger
  5. 05Iconaccordion-iconclasses.icon
  6. 06Titleaccordion-titleclasses.title
  7. 07Summaryaccordion-summaryclasses.summary
  8. 08Chevronaccordion-chevronclasses.chevron
  9. 09Contentaccordion-contentclasses.content
ExportRendersclasses keydata-cuiRole
Rootdivrootaccordionnone
Itemdivitemaccordion-itemnone
Headerh3headeraccordion-headerheading
Triggerbuttontriggeraccordion-triggerbutton
Iconspaniconaccordion-iconnone
Titlespantitleaccordion-titlenone
Summaryspansummaryaccordion-summarynone
Chevronspanchevronaccordion-chevronnone
Contentdivcontentaccordion-contentregion

Variants

Padding around the snippet.

accordion/density.tsx
import * as A from "@codeui/solid/accordion/parts";
import { For } from "solid-js";
export default function Demo() {
	return <A.Root defaultValue={["frame"]} aria-label="Snippet settings">
		<For each={["frame", "window"]}>{value => <A.Item value={value}>
			<A.Header><A.Trigger density={value === "frame" ? "compact" : "comfortable"}>
				<A.Title>{value === "frame" ? "Frame" : "Window"}</A.Title>
				<A.Summary>{value === "frame" ? "64 px" : "macOS"}</A.Summary><A.Chevron />
			</A.Trigger></A.Header>
			<A.Content><p>{value === "frame" ? "Padding around the snippet." : "Window controls and title bar."}</p></A.Content>
		</A.Item>}</For>
	</A.Root>;
}

Set density="compact" or density="comfortable" on the Trigger part. It writes the corresponding data-density attribute.

Padding around the snippet.

Window controls and title bar.

accordion/multiple.tsx
import * as A from "@codeui/solid/accordion/parts";
import { For } from "solid-js";
export default function Demo() {
	return <A.Root multiple defaultValue={["frame", "window"]} aria-label="Snippet settings">
		<For each={["frame", "window"]}>{value => <A.Item value={value}>
			<A.Header><A.Trigger>
				<A.Title>{value === "frame" ? "Frame" : "Window"}</A.Title>
				<A.Summary>{value === "frame" ? "64 px" : "macOS"}</A.Summary><A.Chevron />
			</A.Trigger></A.Header>
			<A.Content><p>{value === "frame" ? "Padding around the snippet." : "Window controls and title bar."}</p></A.Content>
		</A.Item>}</For>
	</A.Root>;
}

Root multiple supports several open sections with array values. Inkstone sidebars use single selection. This parts example documents the supported API.

Padding around your code is 64 px.

accordion/motion.tsx
import { Accordion } from "@codeui/solid";
export default function Demo() {
	return <Accordion aria-label="Snippet appearance" motion="none" defaultValue="frame" items={[
	{ value: "frame", title: "Frame", icon: <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor"><rect x="2" y="3" width="12" height="10" rx="2" /></svg>, summary: "64 px", content: <p>Padding around your code is 64 px.</p> },
	{ value: "window", title: "Window", summary: "macOS", content: <p>The title bar uses macOS window controls.</p> },
	{ value: "watermark", title: "Watermark", disabled: true, content: <p>Watermarks are unavailable for this snippet.</p> },
]} />;
}

motion="none" disables content animation. With auto, the default, a click transitions the body's height and opacity over 200ms with the ease-out curve, and the › chevron turns 90° in step. These are transitions, not keyframes: a second click mid-way turns the body around from its current height, and the first click on a header always lands, because nothing restarts under the pointer. A closing body stays mounted until its transition ends. Keyboard toggles are instant: the kit reads the last input from <html data-cui-input>. Reduced motion keeps the fade and removes the height and chevron motion.

States

Padding around your code is 64 px.

accordion/controlled.tsx
import { Accordion } from "@codeui/solid";
import { createSignal } from "solid-js";
export default function Demo() {
	const [value, setValue] = createSignal<string | null>("frame");
	return <Accordion aria-label="Snippet appearance" value={value()} onChange={setValue} items={[
	{ value: "frame", title: "Frame", icon: <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor"><rect x="2" y="3" width="12" height="10" rx="2" /></svg>, summary: "64 px", content: <p>Padding around your code is 64 px.</p> },
	{ value: "window", title: "Window", summary: "macOS", content: <p>The title bar uses macOS window controls.</p> },
	{ value: "watermark", title: "Watermark", disabled: true, content: <p>Watermarks are unavailable for this snippet.</p> },
]} />;
}

value is a section value or null. onChange receives the next value. Omit value for uncontrolled state. No section opens unless defaultValue is set.

Padding around your code is 64 px.

accordion/required.tsx
import { Accordion } from "@codeui/solid";
import { createSignal } from "solid-js";
export default function Demo() {
	const [value, setValue] = createSignal<string | null>("frame");
	return <Accordion aria-label="Snippet appearance" collapsible={false} defaultValue="frame" items={[
	{ value: "frame", title: "Frame", icon: <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor"><rect x="2" y="3" width="12" height="10" rx="2" /></svg>, summary: "64 px", content: <p>Padding around your code is 64 px.</p> },
	{ value: "window", title: "Window", summary: "macOS", content: <p>The title bar uses macOS window controls.</p> },
	{ value: "watermark", title: "Watermark", disabled: true, content: <p>Watermarks are unavailable for this snippet.</p> },
]} />;
}

collapsible={false} keeps the selected section open. Set defaultValue to start with a section open.

Padding around your code is 64 px.

accordion/retained.tsx
import { Accordion } from "@codeui/solid";
import { createSignal } from "solid-js";
export default function Demo() {
	const [value, setValue] = createSignal<string | null>("frame");
	return <Accordion aria-label="Snippet appearance" keepMounted defaultValue="frame" items={[
	{ value: "frame", title: "Frame", icon: <svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor"><rect x="2" y="3" width="12" height="10" rx="2" /></svg>, summary: "64 px", content: <p>Padding around your code is 64 px.</p> },
	{ value: "window", title: "Window", summary: "macOS", content: <p>The title bar uses macOS window controls.</p> },
	{ value: "watermark", title: "Watermark", disabled: true, content: <p>Watermarks are unavailable for this snippet.</p> },
]} />;
}

keepMounted retains content when collapsed. Collapsed content is inert and hidden from assistive technology. Disabled entries cannot open and are skipped by keyboard navigation.

Ready API

Accordion

Renders single-selection sections from AccordionEntry[]. Each entry requires value, title, and content. Optional fields are icon, summary, and disabled.

Prop

Type

Styled parts API

Import parts from @codeui/solid/accordion/parts. Each export is a named function.

Root

Kobalte Accordion.Root. motion sets data-motion (auto or none). Parts use arrays for value, defaultValue, and onChange. Parts default collapsible to false. The ready component defaults it to true.

Prop

Type

Prop

Type

Item

Kobalte Accordion.Item. Its unique value identifies the section.

Prop

Type

Prop

Type

Kobalte Accordion.Header rendered as an h3. Its heading level can be changed with as.

Prop

Type

Trigger

Kobalte Accordion.Trigger rendered as a button inside Header.

Prop

Type

Prop

Type

Content

Kobalte Accordion.Content with a measured inner wrapper. It writes data-open while the body is open and keeps a closing body mounted until its height transition ends. Collapsed content has inert and aria-hidden.

Prop

Type

Icon

An aria-hidden span for the leading icon. The icon uses the accent color when expanded.

Prop

Type

Title

A span for the section label.

Prop

Type

Summary

A span for the current value at the end of the header.

Prop

Type

Chevron

An aria-hidden span with a default › chevron that turns 90° when expanded.

Prop

Type

useAccordionContext

Advanced, provider-scoped access to Kobalte's accordion context. Call it inside a descendant component of Root. It exposes the list state and selection manager. Calling it outside the provider throws. It takes no props and renders no DOM.

The remaining inherited props follow the Kobalte Accordion contract.

Styles export

accordionStyles

AccordionStyles maps each anatomy part key to a function that returns its class string. For a custom trigger, combine accordionStyles.trigger() with data-density="compact" or data-density="comfortable". Styles are exported from both @codeui/solid and @codeui/solid/accordion/parts.

Accessibility

Keyboard

KeyAction
Enter or SpaceToggles the focused section when collapsible.
ArrowDown or ArrowUpMoves to the next or previous enabled header.
Home or EndMoves to the first or last enabled header.
Tab or Shift+TabMoves between headers and focusable controls in open content.

ARIA

Headers contain buttons with aria-expanded and aria-controls. Content has role="region" and aria-labelledby pointing to its trigger. Icon and Chevron have aria-hidden="true". Disabled triggers expose disabled state.

Focus

Toggling leaves focus on the header. Opening content does not move focus into it. Collapsed content cannot receive focus. Arrow navigation skips disabled headers.

SSR notes

Root, headers, and initially expanded content render on the server. keepMounted also renders collapsed content. Solid generates linked IDs. Content height measurement and ResizeObserver run in client effects after hydration.

Theming hooks

Accordion reads --cui-surface-panel, --cui-surface-input (hovered closed header), --cui-text-default, --cui-text-muted, --cui-accent-focus (the open icon), --cui-radius-card, --cui-radius-md, --cui-space-1, --cui-space-2, --cui-space-2-5, --cui-space-3, and --cui-space-4. Typography uses --cui-font-size-sm, --cui-font-size-caption, --cui-font-size-xs, --cui-font-size-xl (the chevron), --cui-font-weight-normal, --cui-font-weight-semibold, and the matching --cui-font-line-height-sm, -caption and -xs.

Headers use --cui-control-height-sm (36px at comfortable density and 40px at touch density). Focus uses --cui-focus-width, --cui-focus-color, and --cui-focus-offset. Motion uses --cui-motion-duration-panel and --cui-motion-ease-out. Content writes the measured --cui-accordion-content-height; before it measures, the open body is auto tall, so server markup shows it.

See Inkstone foundations for the design rules.

Composition examples

The live demo composes the CodeImage sidebar header through entry icons and summaries. The multiple demo shows the corresponding parts structure.

Sheet holds settings on phones. Tabs switches between peer views.

On this page