# Collapsible

URL: https://ark-ui.com/docs/react/components/collapsible
Markdown: https://ark-ui.com/docs/react/components/collapsible.md

An interactive component that can be expanded or collapsed.

---

---
id: collapsible
title: Collapsible
description: An interactive component that can be expanded or collapsed.
---



## Anatomy



```tsx
<Collapsible.Root>
  <Collapsible.Trigger>
    <Collapsible.Indicator />
  </Collapsible.Trigger>
  <Collapsible.Content />
</Collapsible.Root>
```

## Examples

```tsx
import { Collapsible } from '@ark-ui/react/collapsible'
import { ChevronRightIcon } from 'lucide-react'
import styles from 'styles/collapsible.module.css'

export const Basic = () => (
  <Collapsible.Root className={styles.Root}>
    <Collapsible.Trigger className={styles.Trigger}>
      What is Ark UI?
      <Collapsible.Indicator className={styles.Indicator}>
        <ChevronRightIcon />
      </Collapsible.Indicator>
    </Collapsible.Trigger>
    <Collapsible.Content className={styles.Content}>
      <div className={styles.Body}>
        Ark UI is a headless component library for building accessible, high-quality UI components for React, Solid,
        Vue, and Svelte.
      </div>
    </Collapsible.Content>
  </Collapsible.Root>
)
```

### Disabled

Set `disabled` to stop the collapsible from toggling.

```tsx
import { Collapsible } from '@ark-ui/react/collapsible'
import { ChevronRightIcon } from 'lucide-react'
import styles from 'styles/collapsible.module.css'

export const Disabled = () => (
  <Collapsible.Root className={styles.Root} disabled>
    <Collapsible.Trigger className={styles.Trigger}>
      System Requirements
      <Collapsible.Indicator className={styles.Indicator}>
        <ChevronRightIcon />
      </Collapsible.Indicator>
    </Collapsible.Trigger>
    <Collapsible.Content className={styles.Content}>
      <div className={styles.Body}>This section is currently unavailable.</div>
    </Collapsible.Content>
  </Collapsible.Root>
)
```

### Partial Collapse

Set `collapsedHeight` or `collapsedWidth` for a "show more/less" pattern. The content keeps that size when collapsed
instead of shrinking to 0px. Use the `--collapsed-height` or `--collapsed-width` variables in your CSS animations.

```tsx
import { Collapsible } from '@ark-ui/react/collapsible'
import { ChevronRightIcon } from 'lucide-react'
import styles from 'styles/collapsible.module.css'

export const PartialCollapse = () => (
  <Collapsible.Root className={styles.Root} collapsedHeight="100px">
    <Collapsible.Trigger className={styles.Trigger}>
      Read More
      <Collapsible.Indicator className={styles.Indicator}>
        <ChevronRightIcon />
      </Collapsible.Indicator>
    </Collapsible.Trigger>
    <Collapsible.Content className={styles.Content}>
      <div className={styles.Body}>
        <p>
          Ark UI is a headless component library for building accessible, high-quality UI components for React, Solid,
          Vue, and Svelte. It provides unstyled, fully accessible components that you can customize to match your design
          system.
        </p>
        <p>
          Built on top of Zag.js state machines, Ark UI ensures consistent behavior across all frameworks while giving
          you complete control over styling. Each component follows WAI-ARIA patterns for accessibility out of the box.
        </p>
        <p>
          Whether you're building a design system from scratch or need reliable primitives for your next project, Ark UI
          provides the foundation you need without imposing any visual constraints.
        </p>
      </div>
    </Collapsible.Content>
  </Collapsible.Root>
)
```

> Interactive elements in the collapsed area become `inert`, so keyboard users can't reach hidden content.

### Nested Collapsibles

Nest collapsibles to build hierarchical content.

```tsx
import { Collapsible } from '@ark-ui/react/collapsible'
import { ChevronRightIcon } from 'lucide-react'
import styles from 'styles/collapsible.module.css'

export const Nested = () => (
  <Collapsible.Root className={styles.Root}>
    <Collapsible.Trigger className={styles.Trigger}>
      Getting Started
      <Collapsible.Indicator className={styles.Indicator}>
        <ChevronRightIcon />
      </Collapsible.Indicator>
    </Collapsible.Trigger>
    <Collapsible.Content className={styles.Content}>
      <div className={styles.Body}>
        <p>Welcome to the Ark UI documentation. Here are some topics to explore:</p>

        <Collapsible.Root className={styles.Nested}>
          <Collapsible.Trigger className={styles.Trigger}>
            Installation
            <Collapsible.Indicator className={styles.Indicator}>
              <ChevronRightIcon />
            </Collapsible.Indicator>
          </Collapsible.Trigger>
          <Collapsible.Content className={styles.Content}>
            <div className={styles.Body}>
              <p>Install Ark UI using your preferred package manager:</p>
              <code>npm install @ark-ui/react</code>
            </div>
          </Collapsible.Content>
        </Collapsible.Root>

        <Collapsible.Root className={styles.Nested}>
          <Collapsible.Trigger className={styles.Trigger}>
            Styling
            <Collapsible.Indicator className={styles.Indicator}>
              <ChevronRightIcon />
            </Collapsible.Indicator>
          </Collapsible.Trigger>
          <Collapsible.Content className={styles.Content}>
            <div className={styles.Body}>
              <p>Ark UI components are unstyled by default. Use CSS modules, Tailwind, or any styling solution.</p>
            </div>
          </Collapsible.Content>
        </Collapsible.Root>
      </div>
    </Collapsible.Content>
  </Collapsible.Root>
)
```

### Lazy Mount

Set `lazyMount` to mount the content on first open and `unmountOnExit` to remove it on collapse. With both, the content
is in the DOM only while expanded.

```tsx
import { Collapsible } from '@ark-ui/react/collapsible'
import { ChevronRightIcon } from 'lucide-react'
import styles from 'styles/collapsible.module.css'

export const LazyMount = () => (
  <Collapsible.Root className={styles.Root} lazyMount unmountOnExit>
    <Collapsible.Trigger className={styles.Trigger}>
      Session Details
      <Collapsible.Indicator className={styles.Indicator}>
        <ChevronRightIcon />
      </Collapsible.Indicator>
    </Collapsible.Trigger>
    <Collapsible.Content className={styles.Content}>
      <div className={styles.Body}>
        This content is lazily mounted when first opened and removed from the DOM when collapsed.
      </div>
    </Collapsible.Content>
  </Collapsible.Root>
)
```

### Root Provider

Use `RootProvider` with the `useCollapsible` hook to access the state and methods from outside the component.

```tsx
import { Collapsible, useCollapsible } from '@ark-ui/react/collapsible'
import { ChevronRightIcon } from 'lucide-react'
import styles from 'styles/collapsible.module.css'

export const RootProvider = () => {
  const collapsible = useCollapsible()

  return (
    <div className="stack">
      <output>
        collapsible: {String(collapsible.open)}, visible: {String(collapsible.visible)}
      </output>
      <Collapsible.RootProvider className={styles.Root} value={collapsible}>
        <Collapsible.Trigger className={styles.Trigger}>
          Toggle Panel
          <Collapsible.Indicator className={styles.Indicator}>
            <ChevronRightIcon />
          </Collapsible.Indicator>
        </Collapsible.Trigger>
        <Collapsible.Content className={styles.Content}>
          <div className={styles.Body}>
            This panel can be toggled by the button above, which uses the useCollapsible hook for state management.
          </div>
        </Collapsible.Content>
      </Collapsible.RootProvider>
    </div>
  )
}
```

## Guides

### Indicator Animation

Rotate the indicator on open with the `data-state` attribute:

```css
[data-collapsible-indicator] {
  transition: transform 200ms;

  &[data-state='open'] {
    transform: rotate(180deg);
  }
}
```

### Open vs Visible

`useCollapsible` and `useCollapsibleContext` expose both `open` and `visible`.

- **`open`**: the intended state. It changes as soon as the collapsible is toggled.
- **`visible`**: whether the content is shown. It stays `true` while the exit animation plays, even though `open` is
  already `false`, and turns `false` when the animation ends.

### Content Animation

Animate the content size with the `--height` and `--width` CSS variables. With `collapsedHeight` or `collapsedWidth`,
use `--collapsed-height` or `--collapsed-width` as the start and end point:

```css
@keyframes expand {
  from {
    height: var(--collapsed-height, 0);
  }
  to {
    height: var(--height);
  }
}

@keyframes collapse {
  from {
    height: var(--height);
  }
  to {
    height: var(--collapsed-height, 0);
  }
}

[data-collapsible-content] {
  &[data-state='open'] {
    animation: expand 250ms;
  }
  &[data-state='closed'] {
    animation: collapse 250ms;
  }
}
```

## API Reference

### Props

### Root

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`collapsedHeight`**
Type: `string | number`
Required: false
Default Value: `undefined`
Description: The height of the content when collapsed.

**`collapsedWidth`**
Type: `string | number`
Required: false
Default Value: `undefined`
Description: The width of the content when collapsed.

**`defaultOpen`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: The initial open state of the collapsible when rendered.
Use when you don't need to control the open state of the collapsible.

**`disabled`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether the collapsible is disabled.

**`hiddenUntilFound`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether the closed content stays searchable with the browser's find-in-page.
Uses `hidden="until-found"`, and opens the collapsible when a match is found inside it.

**`hideMode`**
Type: `HideMode`
Required: false
Default Value: `'display-none'`
Description: How to hide content when mounted but not present.
- `'display-none'`: HTML `hidden` attribute. Effects stay alive.
- `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+.

**`ids`**
Type: `ElementIds`
Required: false
Default Value: `undefined`
Description: The ids of the elements in the collapsible. Useful for composition.

**`lazyMount`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether to enable lazy mounting

**`onExitComplete`**
Type: `VoidFunction`
Required: false
Default Value: `undefined`
Description: The callback invoked when the exit animation completes.

**`onOpenChange`**
Type: `(details: OpenChangeDetails) => void`
Required: false
Default Value: `undefined`
Description: The callback invoked when the open state changes.

**`open`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: The controlled open state of the collapsible.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

**`state`**
Type: `{}`
Required: false
Default Value: `undefined`
Description: The state of the part, forwarded to the `render` function. Set by the component, not the consumer.

**`unmountOnExit`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether to unmount on exit.

#### Data Attributes

**`data-collapsible-root`**: <uid>
**`data-state`**: "open" | "closed"
**`data-disabled`**: Present when disabled

### Content

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<CollapsibleContentState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-collapsible-content`**: <uid>
**`data-collapsible`**: 
**`data-state`**: "open" | "closed"
**`data-disabled`**: Present when disabled
**`data-has-collapsed-size`**: Present when the content has collapsed width or height

### Indicator

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-collapsible-indicator`**: <uid>
**`data-state`**: "open" | "closed"
**`data-disabled`**: Present when disabled

### RootProvider

#### Props

**`value`**
Type: `UseCollapsibleReturn`
Required: true
Default Value: `undefined`
Description: undefined

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### Trigger

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<CollapsibleTriggerState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-collapsible-trigger`**: <uid>
**`data-state`**: "open" | "closed"
**`data-disabled`**: Present when disabled

### Context

**API:**

| Property | Type | Description |
|----------|------|-------------|
| `open` | `boolean` | Whether the collapsible is open. |
| `visible` | `boolean` | Whether the collapsible is visible (open or closing) |
| `disabled` | `boolean` | Whether the collapsible is disabled |
| `setOpen` | `(open: boolean, reason?: OpenChangeReason) => void` | Function to open or close the collapsible. |
| `measureSize` | `VoidFunction` | Function to measure the size of the content. |
| `getRootState` | `() => RootState` | Returns the state of the root |
| `getContentState` | `() => ContentState` | Returns the state of the content |


## Accessibility

### Keyboard Support

**`Space`**
Description: Opens/closes the collapsible.

**`Enter`**
Description: Opens/closes the collapsible.
