Interactive
Countdown timer
Counts down to a date: each .countdown-value with a data-unit updates every second, the timer label for screen readers changes once a minute, and an event fires at zero. 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="countdown" role="timer" data-m-countdown="2027-01-01T00:00:00">
<div class="countdown-box"><span class="countdown-value" data-unit="days"></span><span class="countdown-label">Days</span></div>
<div class="countdown-box"><span class="countdown-value" data-unit="hours"></span><span class="countdown-label">Hours</span></div>
<div class="countdown-box"><span class="countdown-value" data-unit="minutes"></span><span class="countdown-label">Minutes</span></div>
<div class="countdown-box"><span class="countdown-value" data-unit="seconds"></span><span class="countdown-label">Seconds</span></div>
</div>JavaScript API
Attribute
data-m-countdown="2027-01-01T00:00:00"
Options
| Option | Description |
|---|---|
data-unit="days", "hours", "minutes" or "seconds" on each value; without days the hours keep counting |
Methods
| Method | Description |
|---|---|
Monsoon.countdown(el).left |
Events
| Event | Description |
|---|---|
monsoon:tick { days, hours, minutes, seconds, total } | |
monsoon:countdown-end |
Classes
4 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 countdown timer. On a <div> in the example. Sets flex display, alignment and gap.CSS |
|
| Part | Part of the countdown timer. On a <div> in the example. Sets flex display, alignment, width, padding, border and corner radius.CSS |
|
| Part | Part of the countdown timer. On a <span> in the example. Sets text size, font weight, text style and generated content.CSS |
|
| Part | Part of the countdown timer. On a <span> in the example. Sets margin, text size, font weight, text style and text color.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>
<!-- Countdown timer: start from the base class, then add modifiers -->
<div class="countdown" role="timer" data-m-countdown="2027-01-01T00:00:00">
<div class="countdown-box"><span class="countdown-value" data-unit="days"></span><span class="countdown-label">Days</span></div>
<div class="countdown-box"><span class="countdown-value" data-unit="hours"></span><span class="countdown-label">Hours</span></div>
<div class="countdown-box"><span class="countdown-value" data-unit="minutes"></span><span class="countdown-label">Minutes</span></div>
<div class="countdown-box"><span class="countdown-value" data-unit="seconds"></span><span class="countdown-label">Seconds</span></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
- 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.