shadcn.io is an independent project built on shadcn/ui
A collapsible hides one section behind a button.
Use it for a single show-more, like an address under an order status. For several sections in a list, use an Accordion so the arrow keys move between them. In React, React Aria connects the button to the panel.
Installation
Anatomy

Collapsible
├── CollapsibleTrigger
├── CollapsibleContent
└── CollapsibleIndicatorUsage
import { ChevronsUpDownIcon } from "lucide-react";
import { useState } from "react";
import { cn } from "@/lib/utils";
import { buttonVariants } from "@/components/ui/button";
import {
Collapsible, CollapsibleContent, CollapsibleTrigger,
} from "@/components/ui/collapsible";const CollapsibleDemo = () => {
const [isOpen, setIsOpen] = useState(false);
return (
<Collapsible
className="flex w-[350px] flex-col gap-2"
isExpanded={isOpen}
onExpandedChange={setIsOpen}
>
<div className="flex items-center justify-between gap-2 px-4">
<h4 className="font-semibold text-sm">Order #4189</h4>
<CollapsibleTrigger
className={cn(
buttonVariants({ size: "icon-xs", variant: "ghost" }),
"size-6"
)}
>
<ChevronsUpDownIcon aria-hidden="true" />
<span className="sr-only">Toggle details</span>
</CollapsibleTrigger>
</div>
<div className="flex items-center justify-between rounded-md border px-4 py-2 text-sm">
<span className="text-muted-foreground">Status</span>
<span className="font-medium">Shipped</span>
</div>
<CollapsibleContent className="flex flex-col gap-2">
<div className="rounded-md border px-4 py-2 text-sm">
<p className="font-medium">Shipping address</p>
<p className="text-muted-foreground">100 Market St, San Francisco</p>
</div>
<div className="rounded-md border px-4 py-2 text-sm">
<p className="font-medium">Items</p>
<p className="text-muted-foreground">2x Studio Headphones</p>
</div>
</CollapsibleContent>
</Collapsible>
);
};Accessibility
- Space
- Opens/closes the collapsible.
- Enter
- Opens/closes the collapsible.
Demos
Basic
A card holds one full-width trigger, Product details, and a chevron that turns when the panel is open. Inside is a short note and a Learn More button. Nothing outside reads the open state, so the collapsible keeps it. Use that when the trigger is the only control that should care, and treat the card as just a frame.
Settings
Two radius fields stay on screen. The bottom corners live in CollapsibleContent and show up when the icon button is pressed. The button's accessible name switches between show and hide, which is why open is controlled: the icon depends on it. Use this for advanced values that would double the form for most people, and do not hide a field this way if it has to be filled.
File Tree
Folders are nested collapsibles and files are plain buttons. Each level opens on its own, which is enough for a small static outline in a card. There is no selection, no typeahead, and no rename, so a real navigator should be a Tree View instead of stacked disclosures. Arrow keys will not walk these rows, because each trigger is its own button.
Rtl
The same order summary, in Arabic, with dir set to rtl. The status row and the hidden address follow the text, and the toggle sits at the inline end. Set direction on the collapsible when this block is translated even if the page around it is not. The chevron does not point to a physical side, so leave it, and keep margins logical or the rows drift.
FAQ
Should I use a Collapsible or an Accordion?
Use a Collapsible for one region that shows and hides on its own, like "Show more" or a settings group. When several sections sit together and work as one list, with arrow keys between the headers, use an Accordion instead of stacking Collapsibles.
How do I open a Collapsible from another button in React?
Hold the open state yourself and pass it in: the trigger still toggles it, and your other button writes the same state.
Pass isExpanded and update it in onExpandedChange, which receives the new boolean.
How do I make a Collapsible start open?
Set defaultExpanded on Collapsible.
It still opens and closes on its own afterwards. If people should find it the way they left it, save the state yourself and pass it back as the controlled value.
Does the content of a closed Collapsible stay in the page?
Yes, it stays mounted and hidden, so fields inside it still submit with a form.
How do I use my own button as the Collapsible trigger in React Aria?
Render your button through CollapsibleTrigger so it gets the open state and the ARIA attributes.
CollapsibleTrigger is already a React Aria button: style it, or pass the props your own button would take.
An icon-only trigger needs an aria-label.
How do I change or turn off the Collapsible animation?
The content animates its height when it opens and closes. Set disableAnimation on CollapsibleContent to open and close it at once, or edit the timing classes in the collapsible file in your components/ui folder. People who ask for reduced motion don't get the animation.
API Reference
Collapsible
data-slot="collapsible"
defaultExpanded?boolean
Whether the disclosure is expanded by default (uncontrolled).
onExpandedChange?(isExpanded: boolean) → void
Handler that is called when the disclosure expanded state changes.
- Parameters
isExpanded– boolean- Returns
void
isExpanded?boolean
Whether the disclosure is expanded (controlled).
className?string
Merged with the part's classes.
data-state"open" | "closed"
"open" or "closed".
- Type
"open" | "closed"
CollapsibleTrigger
data-slot="collapsible-trigger"
children?ReactNode
The content to display in the button.
isDisabled?boolean
Whether the button is disabled.
className?string
Forwarded to the part.
data-state"open" | "closed"
"open" or "closed".
- Type
"open" | "closed"
CollapsibleContent
data-slot="collapsible-content"
childrenReactNode
The children of the component.
disableAnimation?boolean
Opens and closes it at once, without the height animation.
- Default
false
labelElementType?ElementType
The HTML element used to render the label, e.g. label, or span.
- Default
"label"
role?"group" | "region"
The accessibility role for the disclosure's panel.
- Type
"group" | "region"- Default
"group"
style?CSSProperties
The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element.
render?DOMRenderFunction<E, T>
Overrides the default DOM element with a custom render function.
This allows rendering existing components with built-in styles and behaviors
such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if <button> is expected, you cannot render an
<a>).
- Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop
as appropriate.
- Type
DOMRenderFunction<E, T>
className?string
Merged with the part's classes.
data-state"open" | "closed"
"open" or "closed".
- Type
"open" | "closed"
--disclosure-panel-heightstringCollapsibleIndicator
<span> data-slot="collapsible-indicator"
className?string
Merged with the part's classes.












