shadcn.io is not affiliated with official shadcn/ui
Collapsible examples · Card
Subtle Card Collapsible for React
A dashed, muted card with a View source code trigger that expands to a code block.
Some content is there for the curious. This quiet card, a dashed border on a muted background, hides a code block behind a View source code trigger with a chevron. Use it under a demo, in docs or anywhere the code is secondary.
Preview
Installation
FAQ
Which classes make this card quiet?
Collapsible has rounded-lg border-2 border-dashed bg-muted/50: a dashed outline on a muted fill, with no shadow. The code block inside uses bg-background so it stands out from the card.
How is the snippet marked up?
A pre with a code inside, rounded-md bg-background p-3 text-xs. The source is a string at the top of the file, so its line breaks and indentation are kept, and overflow-x-auto scrolls long lines.
Why is justify-between on the trigger?
It keeps View source code at the start and the chevron at the end of the full-width row. The trigger has the group class and sets aria-expanded while open, so group-aria-expanded:rotate-180 on ChevronDownIcon turns it, eased by transition-transform duration-200.
Related
- Card CollapsibleA card with a Features header that
- Simple CollapsibleA ghost Toggle button with a chevron that
- Outlined CollapsibleA box with a thick outline and a System
- Nested Card Content CollapsibleA Product Details card that expands to
- FAQ Item CollapsibleAn FAQ question with a plus that turns
- Card with Badge CollapsibleA card whose Premium Features header