Collapsible shows and hides a block of content when its trigger is clicked. Keep the state inside with defaultOpen or control it from outside with open and onOpenChange. Height animates through interpolate-size, and the closed panel gets hidden="until-found", so in-page search opens it on its own. The trigger accepts asChild and sets aria-expanded and aria-controls for you.
Browser support
Feature
Baseline
Your browser
interpolate-size
Lets height animate between zero and auto.
Your browser:
hidden="until-found"
The closed panel is found by in-page search and opens itself.
Your browser:
Preview
Hidden content
Installation
Usage
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible"
<Collapsible>
<CollapsibleTrigger>Toggle</CollapsibleTrigger>
<CollapsibleContent>Hidden content</CollapsibleContent>
</Collapsible>Examples
Basic
Hidden content
<Collapsible>
<CollapsibleTrigger asChild>
<Button variant="outline">Toggle</Button>
</CollapsibleTrigger>
<CollapsibleContent>Hidden content</CollapsibleContent>
</Collapsible>Open by default
Hidden content
<Collapsible defaultOpen>
<CollapsibleTrigger asChild>
<Button variant="outline">Toggle</Button>
</CollapsibleTrigger>
<CollapsibleContent>Hidden content</CollapsibleContent>
</Collapsible>Controlled
Closed
Hidden content
const [open, setOpen] = React.useState(false)
<Collapsible open={open} onOpenChange={setOpen}>
<CollapsibleTrigger asChild>
<Button variant="outline">Toggle</Button>
</CollapsibleTrigger>
<CollapsibleContent>Hidden content</CollapsibleContent>
</Collapsible>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | - | Controlled state. Together with onOpenChange it makes the component controlled. |
| defaultOpen | boolean | false | Initial state in uncontrolled mode. |
| onOpenChange | (open: boolean) => void | - | Called when the state changes. |
| asChild | boolean | false | Collapsible and CollapsibleTrigger: pass the props to the single child element instead of rendering a wrapper. |
| className | string | - | Additional CSS classes for Collapsible, CollapsibleTrigger and CollapsibleContent. |