Interactive
Password strength
Wires the .password-field reveal button (aria-pressed and the label follow) and scores the password from length, variety and common patterns into a four step meter with a live label. 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="field max-w-sm" data-m-password>
<label class="label" for="pw-new">New password</label>
<div class="password-field">
<input type="password" id="pw-new" class="input" autocomplete="new-password" value="monsoon">
<button type="button" class="password-field-toggle" aria-pressed="false" aria-label="Show password"></button>
</div>
<div class="password-strength"></div>
</div>JavaScript API
Attribute
data-m-password
Options
| Option | Description |
|---|---|
a .password-strength element inside, or data-m-password-meter="#id" |
Methods
| Method | Description |
|---|---|
Monsoon.password(el).score (0 to 4) | |
Monsoon.password(el).reveal(true) |
Events
| Event | Description |
|---|---|
monsoon:strength { score, label } |
Classes
5 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 password strength. On a <div> in the example. Sets block display, padding and hidden by default.CSS |
|
| Part | Part of the password strength. On a <button> in the example. Sets absolute position, offsets, grid display, alignment, width and text color.CSS |
|
| Base | Base class of the password strength. On a <div> in the example. Sets grid display, grid tracks, alignment, gap and background, and 4 custom properties.CSS |
|
| Modifier | Modifier, combined with the password-strength class. Not used in the example above. Sets height, background, corner radius and transition.CSS |
|
| Modifier | Modifier, combined with the password-strength class. Not used in the example above. Sets padding, 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>
<!-- Password strength: start from the base class, then add modifiers -->
<div class="field max-w-sm" data-m-password>
<label class="label" for="pw-new">New password</label>
<div class="password-field">
<input type="password" id="pw-new" class="input" autocomplete="new-password" value="monsoon">
<button type="button" class="password-field-toggle" aria-pressed="false" aria-label="Show password"></button>
</div>
<div class="password-strength"></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.