Data display and layout
Collapse
A details element that opens and closes, with an arrow or plus icon.
Example
<details class="collapse collapse-arrow max-w-lg"><summary class="collapse-title">Does it need a build step?</summary><div class="collapse-content">No. Link one stylesheet and every component works with plain HTML.</div></details>Classes
5 classes. Click a name to copy it. Utilities on the same element always win over component defaults, so any of them can be adjusted with plain utility classes.
| Class | Type | What it does |
|---|---|---|
| Base | Base class of the collapse. On a <details> in the example. Sets overflow, border, corner radius, background, height and transition.CSS |
|
| Part | Part of the collapse. On a <summary> in the example. Sets flex display, alignment, gap, padding, font weight and pointer cursor.CSS |
|
| Part | Part of the collapse. On a <div> in the example. Sets padding and text color.CSS |
|
| Modifier | Modifier, combined with the collapse class. On a <details> in the example. Sets generated content, alignment, text color, transition, width and height.CSS |
|
| Modifier | Modifier, combined with the collapse class. Not used in the example above. Sets generated content, alignment, text color, transition, width and height.CSS |
Usage
Components ship inside the same stylesheet as the utilities. There is nothing else to install and no script to load: link Monsoon and write the markup.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">
<!-- Collapse: start from the base class, then add modifiers -->
<details class="collapse collapse-arrow max-w-lg"><summary class="collapse-title">Does it need a build step?</summary><div class="collapse-content">No. Link one stylesheet and every component works with plain HTML.</div></details>Theme it with --seed on any ancestor, for example style="--seed: #0d9488", and force a scheme with class="dark" or class="light" on a wrapper.
Accessibility
- Built on
detailsandsummary, so it opens with Enter or Space and screen readers announce expanded and collapsed. A sharednamemakes a group exclusive. - Every interactive part shows a visible focus ring with
:focus-visible, and tone colors pair with-foregroundtokens that keep text at 4.5:1 or better in light and dark mode.