Interactive
Color picker
A saturation and brightness area, hue and opacity sliders, a hex, rgb or oklch field, swatches and the eyedropper where the browser has one, over a native color input. Needs monsoon.js.
Needs monsoon.js. The styles work on their own, and the behavior comes from the optional interactive layer: add <script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script> or import 'monsooncss/js'. See the interactive layer.
Example
<div class="flex flex-wrap items-start gap-6">
<div class="color-picker" data-m-color-picker data-m-color-picker-swatches="#4f46e5,#0ea5e9,#10b981,#f59e0b,#ef4444,#ec4899,#64748b,#0f172a">
<input type="color" class="color-input" name="brand" value="#4f46e5" aria-label="Brand color">
</div>
<div class="color-picker" data-m-color-picker data-m-color-picker-inline data-m-color-picker-format="oklch">
<input type="color" class="color-input" value="#0ea5e9" aria-label="Accent color">
</div>
</div>JavaScript API
Attribute
data-m-color-picker
Options
| Option | Description |
|---|---|
data-m-color-picker-format="oklch" (hex, rgb or oklch, also what the input stores) | |
data-m-color-picker-swatches="#4f46e5,#0ea5e9" | |
data-m-color-picker-alpha="false" | |
data-m-color-picker-inline |
Methods
| Method | Description |
|---|---|
Monsoon.colorPicker(el).value | |
Monsoon.colorPicker(el).value = "oklch(70% 0.15 200)" | |
Monsoon.colorPicker(el).rgba | |
Monsoon.colorPicker(el).open() |
Events
| Event | Description |
|---|---|
monsoon:change { value, hex, rgba } | |
input and change on the native input |
Classes
18 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 color picker. On a <div> in the example. Sets inline-flex display, static position, stacking order, shadow and animation, and --tone and --_checker.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets inline-flex display, alignment, gap, height, padding and text size.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets width, background, corner radius and shadow.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets width and text style.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets fixed position, offsets, stacking order, margin, padding and overflow, and --tone and --tone-fg.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets border, height, background, corner radius, shadow and crosshair cursor.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets absolute position, offsets, width, height, background and border.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets flex display, alignment and gap.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets alignment, grid display and gap.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets offsets, background, height, corner radius, shadow and pointer cursor.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets offsets, height, corner radius, shadow, pointer cursor and background.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets width, background, corner radius and shadow.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets generated content, width, height and background.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets flex display and gap.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets alignment.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets alignment, width and text size.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets grid display, grid tracks and gap.CSS |
|
| Modifier | Modifier, combined with the color-picker class. Not used in the example above. Sets border, background, corner radius, shadow, pointer cursor and transition.CSS |
Usage
The styles ship inside the same stylesheet as the utilities, and the behavior comes from the optional monsoon.js script, which enhances any element with a matching data-m attribute, including markup added later.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">
<script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script>
<!-- Color picker: start from the base class, then add modifiers -->
<div class="flex flex-wrap items-start gap-6">
<div class="color-picker" data-m-color-picker data-m-color-picker-swatches="#4f46e5,#0ea5e9,#10b981,#f59e0b,#ef4444,#ec4899,#64748b,#0f172a">
<input type="color" class="color-input" name="brand" value="#4f46e5" aria-label="Brand color">
</div>
<div class="color-picker" data-m-color-picker data-m-color-picker-inline data-m-color-picker-format="oklch">
<input type="color" class="color-input" value="#0ea5e9" aria-label="Accent color">
</div>
</div>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
- Give every control a visible
labellinked withfor, or anaria-labelwhen the purpose is obvious from context. Link help and error text witharia-describedby; invalid styles use:user-invalid, so they appear only after the user interacts. - 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.