Navigation and overlays
Lightbox
A full screen dark viewer for one image with a caption, a counter, close and previous or next controls. Uses a <dialog> or :target links.
Example
<button type="button" commandfor="photo" command="show-modal" 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">View photo</button><dialog id="photo" class="lightbox" closedby="any" aria-label="Photo viewer"><img class="lightbox-image" src="https://picsum.photos/seed/monsoon/1200/800" alt="Rain over a mountain lake"><p class="lightbox-caption">Rain over the lake, early morning.</p><span class="lightbox-counter">3 / 12</span><a href="#" class="lightbox-prev" aria-label="Previous photo"></a><a href="#" class="lightbox-next" aria-label="Next photo"></a><button type="button" commandfor="photo" command="close" class="lightbox-close" aria-label="Close"></button></dialog>Classes
7 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 lightbox. On a <dialog> in the example. Sets overflow, background, fixed position, offsets, stacking order and hidden by default.CSS |
|
| Part | Part of the lightbox. On an <img> in the example. Sets width, height, corner radius, shadow and transition.CSS |
|
| Part | Part of the lightbox. On a <p> in the example. Sets width, text size, text style and text color.CSS |
|
| Part | Part of the lightbox. On a <span> in the example. Sets absolute position, offsets, text size and text color.CSS |
|
| Part | Part of the lightbox. On a <button> in the example. Sets absolute position, offsets, grid display, alignment, width and height.CSS |
|
| Part | Part of the lightbox. On an <a> in the example. Sets generated content, width, height, background, corner radius and text color.CSS |
|
| Part | Part of the lightbox. On an <a> in the example. Sets generated content, width, height, background, corner radius and text color.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">
<!-- Lightbox: start from the base class, then add modifiers -->
<button type="button" commandfor="photo" command="show-modal" 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">View photo</button><dialog id="photo" class="lightbox" closedby="any" aria-label="Photo viewer"><img class="lightbox-image" src="https://picsum.photos/seed/monsoon/1200/800" alt="Rain over a mountain lake"><p class="lightbox-caption">Rain over the lake, early morning.</p><span class="lightbox-counter">3 / 12</span><a href="#" class="lightbox-prev" aria-label="Previous photo"></a><a href="#" class="lightbox-next" aria-label="Next photo"></a><button type="button" commandfor="photo" command="close" class="lightbox-close" aria-label="Close"></button></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". - Give meaningful images an
alttext and decorative onesalt="". Initials avatars should expose the full name to screen readers. - 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.