On this page
Collapsible
Headless, unstyled single panel shown and hidden by a button. Wires aria-expanded, aria-controls and role="region", and measures the panel so CSS can animate its size.
Use for
- one section that shows and hides its content
- a show more toggle or an advanced options panel
Practices
| Guidance | Practice |
|---|---|
| Do | Animate the panel size with --collapsible-panel-height and --collapsible-panel-width, set from the measured panel while it opens or closes. |
| Don’t | Pass id to the trigger or panel. The primitive owns both to pair them. |
| Don’t | Hide content by hand with display: none. The panel unmounts once closed. |
| Don’t | Stack several for a set of sections. Use Accordion instead. |
API reference
Collapsible.Root
Holds the open state. Renders a div, or the render element, with data-open or data-closed, and data-disabled.
| Prop | Type | Description |
|---|---|---|
open | boolean | Whether the panel is open, when controlled. |
defaultOpen | boolean | Whether the panel is open on mount, when uncontrolled.Default: false |
onOpenChange | (open: boolean) => void | Called with the new open state. |
disabled | boolean | Stops the trigger from toggling.Default: false |
Collapsible.Trigger
A button that toggles the panel. Carries aria-expanded, aria-controls, aria-disabled, and the same data attributes as the root.
Collapsible.Panel
The content, as role="region" labelled by the trigger. Carries data-open or data-closed. Unmounts once closed and its exit transition ends, and skips the enter transition on first mount.
Examples
A toggle
<Collapsible.Root>
<Collapsible.Trigger>Advanced options</Collapsible.Trigger>
<Collapsible.Panel>…</Collapsible.Panel>
</Collapsible.Root>Related
- Accordion
usePanelSize