Skip to main content
Kobalte

Collapsible

Since v0.5.0@kobalte/core/collapsibleSourceDisclosure

An interactive component which expands/collapses a content.

Import

import { Collapsible } from "@kobalte/core/collapsible";
// or
import { Root, Trigger, ... } from "@kobalte/core/collapsible";
// or (deprecated)
import { Collapsible } from "@kobalte/core";

Features

Anatomy

The collapsible consists of:

  • Collapsible: The root container for a collapsible.
  • Collapsible.Trigger: The button that expands/collapses the collapsible content.
  • Collapsible.Content: Contains the content to be rendered when the collapsible is expanded.
<Collapsible>
<Collapsible.Trigger />
<Collapsible.Content />
</Collapsible>

Example

import { Collapsible } from "@kobalte/core/collapsible";
export function BasicExample() {
return (
<Collapsible class={style.collapsible}>
<Collapsible.Trigger class={style.collapsible__trigger}>
<span>What is Kobalte?</span>
<ChevronDownIcon class={style["collapsible__trigger-icon"]} />
</Collapsible.Trigger>
<Collapsible.Content class={style.collapsible__content}>
<p class={style["collapsible__content-text"]}>
Kobalte is a UI toolkit for building accessible web apps and design
systems with SolidJS. It provides a set of low-level UI components and
primitives which can be the foundation for your design system
implementation.
</p>
</Collapsible.Content>
</Collapsible>
);
}
.collapsible {
width: 300px;
}
.collapsible__trigger {
display: inline-flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding: 14px;
font-weight: 600;
border: 1px solid hsl(240 5% 84%);
color: hsl(240 4% 16%);
text-align: left;
outline: none;
}
.collapsible__trigger:focus-visible {
outline: 2px solid hsl(200 98% 39%);
outline-offset: 2px;
}
.collapsible__trigger-icon {
width: 20px;
height: 20px;
transition: transform 250ms;
}
.collapsible__trigger[data-expanded] .collapsible__trigger-icon {
transform: rotateZ(180deg);
}
.collapsible__content {
width: 100%;
overflow: hidden;
border: 1px solid hsl(240 5% 84%);
border-top: none;
color: hsl(240 4% 16%);
animation: slideUp 300ms ease-out;
}
.collapsible__content[data-expanded] {
animation: slideDown 300ms ease-out;
}
.collapsible__content-text {
padding: 16px;
}
@keyframes slideDown {
from {
height: 0;
}
to {
height: var(--kb-collapsible-content-height);
}
}
@keyframes slideUp {
from {
height: var(--kb-collapsible-content-height);
}
to {
height: 0;
}
}
[data-theme*="dark"] .collapsible__trigger,
[data-theme*="dark"] .collapsible__content {
border-color: hsl(240 5% 65%);
color: hsl(0 0% 100% / 0.9);
}

Usage

Animating content size

We expose the CSS custom properties --kb-collapsible-content-width and --kb-collapsible-content-height which you can use to animate the size of the content when it opens/closes.

style.css
.collapsible__content {
overflow: hidden;
animation: slideUp 300ms ease-out;
}
.collapsible__content[data-expanded] {
animation: slideDown 300ms ease-out;
}
@keyframes slideDown {
from {
height: 0;
}
to {
height: var(--kb-collapsible-content-height);
}
}
@keyframes slideUp {
from {
height: var(--kb-collapsible-content-height);
}
to {
height: 0;
}
}

API Reference

Collapsible

Collapsible is equivalent to the Root import from @kobalte/core/collapsible (and deprecated Collapsible.Root).

PropDescription
openboolean
The controlled open state of the collapsible.
defaultOpenboolean
The default open state when initially rendered. Useful when you do not need to control the open state.
onOpenChange(open: boolean) => void
Event handler called when the open state of the collapsible changes.
disabledboolean
Whether the collapsible is disabled.
forceMountboolean
Used to force mounting the collapsible content when more control is needed. Useful when controlling animation with SolidJS animation libraries.
Data attributeDescription
data-expandedPresent when the collapsible is expanded.
data-closedPresent when the collapsible is collapsed.
data-disabledPresent when the collapsible is disabled.

Collapsible.Trigger and Collapsible.Content share the same data-attributes.

Rendered elements

ComponentDefault rendered element
Collapsiblediv
Collapsible.Triggerbutton
Collapsible.Contentdiv

Accessibility

Keyboard Interactions

KeyDescription
SpaceWhen focus is on the trigger, opens/closes the collapsible.
EnterWhen focus is on the trigger, opens/closes the collapsible.

Last updated: 7/16/26, 7:09 AM