---
title: "Collapsible"
description: "A single section that expands to reveal content."
category: "Layout & Navigation"
slug: collapsible
url: /components/collapsible
since: "0.2.0"
status: "stable"
---

# Collapsible

A single section that expands to reveal content.

## Import

```svelte
import { Collapsible } from '@elluzion/iv-ui';
```

## Preview

A titled section that starts closed.

```svelte
<script lang="ts">
	import { Collapsible } from '@elluzion/iv-ui';
</script>

<Collapsible title="Request headers">
	<pre class="code">accept: application/json
x-request-id: 8f2c1a</pre>
</Collapsible>

<style>
	.code {
		margin: 0;
		font-family: var(--iv_font-mono);
		font-size: var(--iv_text-sm);
		color: var(--iv_foreground-dim);
	}
</style>
```

## Usage

- Use for one-off disclosure; use `Accordion` when sections form a set.
- `open` is bindable; `defaultOpen` sets the uncontrolled initial state.
- `trigger` replaces the default title and chevron content.

## Examples

### Controlled

Bind `open` and drive it from outside the component.

```svelte
<script lang="ts">
	import { Button, Collapsible } from '@elluzion/iv-ui';

	let open = $state(false);
</script>

<div class="stack">
	<Collapsible title="Advanced options" bind:open>
		<p>Timeout, retry budget, and the cache policy for this route.</p>
	</Collapsible>
	<div class="row">
		<Button size="sm" variant="outline" onclick={() => (open = true)}>Open</Button>
		<Button size="sm" variant="ghost" onclick={() => (open = false)}>Close</Button>
	</div>
</div>

<style>
	.stack {
		display: flex;
		flex-direction: column;
		gap: var(--iv_spacing-md);
	}

	.row {
		display: flex;
		gap: var(--iv_spacing-sm);
	}
</style>
```

### Custom trigger

The trigger snippet replaces the title with custom content.

```svelte
<script lang="ts">
	import { IconTerminal2 } from '@tabler/icons-svelte';
	import { Collapsible, Shortcut } from '@elluzion/iv-ui';
</script>

<Collapsible defaultOpen>
	{#snippet trigger()}
		<span class="trigger">
			<IconTerminal2 size={14} />
			Console
			<Shortcut keys={['⌘', 'K']} />
		</span>
	{/snippet}
	<p>Open the command palette with the shortcut shown above.</p>
</Collapsible>

<style>
	.trigger {
		display: inline-flex;
		align-items: center;
		gap: var(--iv_spacing-sm);
	}
</style>
```

### Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` | `string` | `''` | Trigger text. |
| `open` **bindable** | `boolean` | — | Open state. Bind with `bind:open`. |
| `defaultOpen` | `boolean` | `false` | Open on first render when uncontrolled. |
| `disabled` | `boolean` | `false` | Disables interaction and applies the disabled treatment. |
| `className` | `string` | `''` | Extra classes merged onto the root element. |

`class`, `id`, `style`, `aria-*`, and `data-*` are forwarded through rest props.

### Events

| Event | Handler type | Description |
| --- | --- | --- |
| `change` | `(e: CustomEvent<{ open: boolean }>) => void` | Called with `{ open }` after the panel toggles. |

The legacy `on:name` form is accepted for every event.

### Snippets

| Snippet | Type | Description |
| --- | --- | --- |
| `trigger` | `Snippet` | Custom trigger content. |
| `children` | `Snippet` | Content rendered inside the component. |

### Tokens used

`--iv_border` · `--iv_ease-out` · `--iv_font-ui` · `--iv_foreground` · `--iv_foreground-dim` · `--iv_leading-base` · `--iv_outline-width` · `--iv_radius` · `--iv_spacing-lg` · `--iv_spacing-md` · `--iv_surface-overlay` · `--iv_surface-raised` · `--iv_text-body` · `--iv_text-btn` · `--iv_transition-fast` · `--iv_weight-medium`

See the [token reference](/foundations/tokens.md) for values.

### CSS hooks

`.iv-chevron` · `.iv-collapsible` · `.iv-open` · `.iv-panel` · `.iv-trigger` · `.iv-trigger-label`

## Accessibility

| Keys | Action |
| --- | --- |
| `Tab` | Moves focus to the trigger. |
| `Enter / Space` | Opens or closes the section. |

- The trigger is a native button with `aria-expanded` and `aria-controls`.
- The panel uses `role="region"` and is labelled by the trigger.
- Animation is skipped when reduced motion is requested.

## Related

- [Accordion](/components/accordion.md)
- [Card](/components/card.md)
- [Tabs](/components/tabs.md)
- [Separator](/components/separator.md)