Two factor and sign in
Phone number
Phone number with a country picker: a searchable list with flags and dial codes, formatting as you type for the selected country, typing or pasting +44 or 0044 switches the country, and a hidden field with the E.164 number. Without the script the native select and tel input still work. 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
<form class="grid gap-5 max-w-sm" action="#" onsubmit="event.preventDefault()">
<div class="field">
<label class="label" for="mfa-phone">Mobile number</label>
<div class="phone-input" data-m-auth-phone data-m-auth-phone-name="phone_e164">
<select class="phone-input-select select" name="country" aria-label="Country">
<option value="US">United States (+1)</option>
<option value="BR" selected>Brazil (+55)</option>
<option value="GB">United Kingdom (+44)</option>
<option value="PT">Portugal (+351)</option>
<option value="DE">Germany (+49)</option>
<option value="IN">India (+91)</option>
</select>
<input id="mfa-phone" class="phone-input-field input" type="tel" name="phone" value="11987650474" autocomplete="tel-national" aria-describedby="mfa-phone-hint">
</div>
<p class="hint" id="mfa-phone-hint">We'll text a code to this number. Message rates may apply.</p>
</div>
<div class="field">
<label class="label" for="mfa-phone-2">Backup number</label>
<div class="phone-input" data-m-auth-phone data-m-auth-phone-countries="US,CA,GB,PT,ES,FR,DE,IT,JP">
<select class="phone-input-select select" name="backup_country" aria-label="Country">
<option value="US" selected>United States (+1)</option>
<option value="GB">United Kingdom (+44)</option>
</select>
<input id="mfa-phone-2" class="phone-input-field input" type="tel" name="backup_phone" autocomplete="tel-national">
</div>
</div>
</form>JavaScript API
Attribute
data-m-auth-phone
Options
| Option | Description |
|---|---|
data-m-auth-phone-name="phone_e164" (hidden input with +15550100123) | |
data-m-auth-phone-countries="US,BR,GB,PT" (limit the list) |
Methods
| Method | Description |
|---|---|
Monsoon.authPhone(el).value (country, dial, national, e164, valid) | |
Monsoon.authPhone(el).country = "BR" | |
Monsoon.authPhone(el).open() | |
Monsoon.authPhone(el).close() |
Events
| Event | Description |
|---|---|
monsoon:auth-phone { country, dial, national, e164, valid } |
Classes
13 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 phone number. On a <div> in the example. Sets flex display and width.CSS |
|
| Part | Part of the phone number. On a <select> in the example. Sets alignment, width, corner radius and padding.CSS |
|
| Part | Part of the phone number. On an <input> in the example. Sets alignment, width, margin, corner radius and stacking order.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets alignment, width, corner radius, inline-flex display, gap and height.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets block display, alignment, width, height, overflow and corner radius.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets grid display, alignment, text size, font weight, text style and text color.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets text color.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets absolute position, offsets, stacking order, grid display, gap and width.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets width, height, padding, text size, text color and background.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets height, margin, padding and overflow.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets grid display, grid tracks, alignment, gap, padding and text size.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets overflow and text style.CSS |
|
| Modifier | Modifier, combined with the phone-input class. Not used in the example above. Sets margin, padding, text size, 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>
<!-- Phone number: start from the base class, then add modifiers -->
<form class="grid gap-5 max-w-sm" action="#" onsubmit="event.preventDefault()">
<div class="field">
<label class="label" for="mfa-phone">Mobile number</label>
<div class="phone-input" data-m-auth-phone data-m-auth-phone-name="phone_e164">
<select class="phone-input-select select" name="country" aria-label="Country">
<option value="US">United States (+1)</option>
<option value="BR" selected>Brazil (+55)</option>
<option value="GB">United Kingdom (+44)</option>
<option value="PT">Portugal (+351)</option>
<option value="DE">Germany (+49)</option>
<option value="IN">India (+91)</option>
</select>
<input id="mfa-phone" class="phone-input-field input" type="tel" name="phone" value="11987650474" autocomplete="tel-national" aria-describedby="mfa-phone-hint">
</div>
<!-- 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.