Navigation and overlays
Modal
A centered dialog over a blurred backdrop. Open it with command="show-modal" (or link to its id for a :target fallback), close it with command="close", a form with method="dialog" or Escape. Five widths, a top aligned variant and a bottom sheet on phones.
Example
<button type="button" commandfor="delete-modal" command="show-modal" class="inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:opacity-90">Delete project</button><dialog id="delete-modal" class="modal modal-bottom" aria-labelledby="delete-title"><div class="modal-box"><div class="modal-header"><h2 id="delete-title" class="modal-title">Delete this project?</h2></div><button type="button" commandfor="delete-modal" command="close" class="modal-close" aria-label="Close"></button><p class="modal-body text-muted-foreground">All deployments, domains and analytics for Acme Web will be removed. This cannot be undone.</p><form method="dialog" class="modal-actions"><button class="inline-flex items-center justify-center gap-2 rounded-lg border border-border bg-surface px-4 py-2 text-sm font-medium hover:bg-muted">Cancel</button><button class="inline-flex items-center justify-center rounded-lg bg-danger px-4 py-2 text-sm font-medium text-danger-foreground hover:opacity-90" value="delete">Delete</button></form></div><form method="dialog" class="modal-backdrop"><button aria-label="Close">Close</button></form></dialog>Classes
14 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 modal. On a <dialog> in the example. Sets overflow, fixed position, offsets, stacking order, hidden by default and alignment, and --modal-w, --modal-speed and --modal-from.CSS |
|
| Part | Part of the modal. On a <div> in the example. Sets stacking order, transform, transition, width, height and overflow.CSS |
|
| Part | Part of the modal. On a <div> in the example. Sets flex display, alignment, gap, margin and padding.CSS |
|
| Part | Part of the modal. On a <h2> in the example. Sets text size, font weight and text style.CSS |
|
| Part | Part of the modal. On a <p> in the example. Sets text size and text style.CSS |
|
| Part | Part of the modal. On a <form> in the example. Sets flex display, alignment, gap, margin and width.CSS |
|
| Part | Part of the modal. On a <button> in the example. Sets absolute position, offsets, grid display, alignment, width and height.CSS |
|
| Part | Part of the modal. On a <form> in the example. Sets fixed position, offsets, block display, text color, width and height.CSS |
|
| Size | Small size. Not used in the example above. Sets --modal-w.CSS |
|
| Size | Large size. Not used in the example above. Sets --modal-w.CSS |
|
| Size | Extra large size. Not used in the example above. Sets --modal-w.CSS |
|
| Modifier | Modifier, combined with the modal class. Not used in the example above. Sets height, and --modal-w.CSS |
|
| Modifier | Modifier, combined with the modal class. Not used in the example above. Sets alignment and padding, and --modal-from.CSS |
|
| Modifier | Modifier, combined with the modal class. On a <dialog> in the example. Sets alignment, padding, width, height, border and corner radius, and --modal-from.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">
<!-- Modal: start from the base class, then add modifiers -->
<button type="button" commandfor="delete-modal" command="show-modal" class="inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:opacity-90">Delete project</button><dialog id="delete-modal" class="modal modal-bottom" aria-labelledby="delete-title"><div class="modal-box"><div class="modal-header"><h2 id="delete-title" class="modal-title">Delete this project?</h2></div><button type="button" commandfor="delete-modal" command="close" class="modal-close" aria-label="Close"></button><p class="modal-body text-muted-foreground">All deployments, domains and analytics for Acme Web will be removed. This cannot be undone.</p><form method="dialog" class="modal-actions"><button class="inline-flex items-center justify-center gap-2 rounded-lg border border-border bg-surface px-4 py-2 text-sm font-medium hover:bg-muted">Cancel</button><button class="inline-flex items-center justify-center rounded-lg bg-danger px-4 py-2 text-sm font-medium text-danger-foreground hover:opacity-90" value="delete">Delete</button></form></div><form method="dialog" class="modal-backdrop"><button aria-label="Close">Close</button></form></dialog>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 the native
dialogelement. Opened withshowModal()(or a command button) it goes to the top layer, makes the rest of the page inert, closes with Escape and returns focus to the button that opened it. - Use
buttonfor actions andafor navigation. Icon only buttons need anaria-label; decorative icons carryaria-hidden="true". - 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.