Forms
One time code
A verification code field. Without JavaScript it is one input with spaced monospace characters over slot marks, so typing, paste and SMS autofill (autocomplete="one-time-code") work natively. Add data-m-otp and monsoon.js to get one cell per character (see Two factor and sign in).
Example
<div class="grid gap-5">
<div class="field">
<label class="label" for="otp-sms">Code from the text message</label>
<div class="otp">
<input id="otp-sms" class="otp-field" name="code" value="4829" inputmode="numeric" autocomplete="one-time-code" maxlength="6" pattern="[0-9]{6}" spellcheck="false" aria-describedby="otp-sms-hint">
</div>
<p class="hint" id="otp-sms-hint">Type or paste the 6 digits we sent to your phone.</p>
</div>
<div class="flex flex-wrap items-center gap-4">
<div class="otp otp-4 otp-sm otp-primary">
<input class="otp-field" type="password" name="pin" inputmode="numeric" autocomplete="off" maxlength="4" aria-label="Card PIN" value="1234">
</div>
<div class="otp otp-8 otp-sm">
<input class="otp-field" name="recovery" autocomplete="off" maxlength="8" aria-label="Recovery code" value="K7Q2" spellcheck="false">
</div>
</div>
</div>Classes
23 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 one time code. On a <div> in the example. Sets flex display, alignment, gap, width, absolute position and offsets, and 7 custom properties.CSS |
|
| Part | Part of the one time code. On an <input> in the example. Sets block display, width, height, padding, text size and text style, and 13 custom properties.CSS |
|
| Modifier | Modifier, combined with the otp class. Not used in the example above. Sets block display, width, height, padding, text size and text style, and 10 custom properties.CSS |
|
| Modifier | Modifier, combined with the otp class. Not used in the example above. Sets alignment, width, height, corner radius and background.CSS |
|
| Modifier | Modifier, combined with the otp class. Not used in the example above. A hook for state rules such as .otp-masked > .otp-input.CSS |
|
| Tone | Primary tone. On a <div> in the example. Sets --field-tone.CSS |
|
| Tone | Secondary tone. Not used in the example above. Sets --field-tone.CSS |
|
| Tone | Accent tone. Not used in the example above. Sets --field-tone.CSS |
|
| Tone | Neutral tone. Not used in the example above. Sets --field-tone.CSS |
|
| Tone | Success tone. Not used in the example above. Sets --field-tone.CSS |
|
| Tone | Warning tone. Not used in the example above. Sets --field-tone.CSS |
|
| Tone | Danger tone. Not used in the example above. Sets --field-tone.CSS |
|
| Tone | Info tone. Not used in the example above. Sets --field-tone.CSS |
|
| Size | Extra small size. Not used in the example above. Sets --otp-size and --field-radius.CSS |
|
| Size | Small size. On a <div> in the example. Sets --otp-size and --field-radius.CSS |
|
| Size | Medium, the default size. Not used in the example above. Sets --otp-size and --field-radius.CSS |
|
| Size | Large size. Not used in the example above. Sets --otp-size and --field-radius.CSS |
|
| Size | Extra large size. Not used in the example above. Sets --otp-size and --field-radius.CSS |
|
| Modifier | Modifier, combined with the otp class. On a <div> in the example. Sets --otp-length.CSS |
|
| Modifier | Modifier, combined with the otp class. Not used in the example above. Sets --otp-length.CSS |
|
| Modifier | Modifier, combined with the otp class. Not used in the example above. Sets --otp-length.CSS |
|
| Modifier | Modifier, combined with the otp class. Not used in the example above. Sets --otp-length.CSS |
|
| Modifier | Modifier, combined with the otp class. On a <div> in the example. Sets --otp-length.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">
<!-- One time code: start from the base class, then add modifiers -->
<div class="grid gap-5">
<div class="field">
<label class="label" for="otp-sms">Code from the text message</label>
<div class="otp">
<input id="otp-sms" class="otp-field" name="code" value="4829" inputmode="numeric" autocomplete="one-time-code" maxlength="6" pattern="[0-9]{6}" spellcheck="false" aria-describedby="otp-sms-hint">
</div>
<p class="hint" id="otp-sms-hint">Type or paste the 6 digits we sent to your phone.</p>
</div>
<div class="flex flex-wrap items-center gap-4">
<div class="otp otp-4 otp-sm otp-primary">
<input class="otp-field" type="password" name="pin" inputmode="numeric" autocomplete="off" maxlength="4" aria-label="Card PIN" value="1234">
</div>
<div class="otp otp-8 otp-sm">
<input class="otp-field" name="recovery" autocomplete="off" maxlength="8" aria-label="Recovery code" value="K7Q2" spellcheck="false">
<!-- the full example is in the Code tab above -->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.