Interactive
Number counter
The .input-counter buttons call stepDown() and stepUp(), repeat while held, follow min, max and step, and disable at the limits. 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-center gap-4">
<div class="input-counter" data-m-counter>
<button type="button" class="input-counter-button" aria-label="Decrease">-</button>
<input type="number" class="input" value="2" min="1" max="10" aria-label="Guests">
<button type="button" class="input-counter-button" aria-label="Increase">+</button>
</div>
<div class="input-counter input-group-sm" data-m-counter>
<button type="button" class="input-counter-button" aria-label="Decrease">-</button>
<input type="number" class="input input-sm" value="0.5" min="0" max="5" step="0.25" aria-label="Weight in kilograms">
<button type="button" class="input-counter-button" aria-label="Increase">+</button>
</div>
</div>JavaScript API
Attribute
data-m-counter
Options
| Option | Description |
|---|---|
min, max and step on the number input |
Methods
| Method | Description |
|---|---|
Monsoon.counter(el).increment() | |
Monsoon.counter(el).decrement() |
Events
| Event | Description |
|---|---|
monsoon:change { value } | |
input and change on the native input |
Classes
3 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 |
|---|---|---|
| Part | Part of the number counter. On a <div> in the example. Sets flex display, alignment, width, inline-flex display, corner radius and margin.CSS |
|
| Part | Part of the number counter. On a <button> in the example. Sets grid display, alignment, width, text size, text style and text color, and --_line and --_shadow.CSS |
|
| Base | Base class of the number counter. On an <input> in the example. Sets block display, width, height, padding, text size and text style, and 9 custom properties.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>
<!-- Number counter: start from the base class, then add modifiers -->
<div class="flex flex-wrap items-center gap-4">
<div class="input-counter" data-m-counter>
<button type="button" class="input-counter-button" aria-label="Decrease">-</button>
<input type="number" class="input" value="2" min="1" max="10" aria-label="Guests">
<button type="button" class="input-counter-button" aria-label="Increase">+</button>
</div>
<div class="input-counter input-group-sm" data-m-counter>
<button type="button" class="input-counter-button" aria-label="Decrease">-</button>
<input type="number" class="input input-sm" value="0.5" min="0" max="5" step="0.25" aria-label="Weight in kilograms">
<button type="button" class="input-counter-button" aria-label="Increase">+</button>
</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. - 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.