Two factor and sign in
Authenticator app setup
Two step setup for a time based authenticator: a QR code drawn in the browser from an otpauth:// URI (no image, no dependency), the setup key in groups of four with a copy button behind a "Can't scan the code?" disclosure, then the first code to confirm. Needs monsoon.js for the QR code and the code cells.
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="auth-card auth-card-wide" action="#" onsubmit="event.preventDefault()">
<header class="auth-header auth-header-start">
<span class="auth-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="6.5" y="2.5" width="11" height="19" rx="2.5"/><path d="M10.5 18.5h3"/><path d="M9.5 9.5h5M9.5 12.5h3"/></svg></span>
<h2 class="auth-title">Set up your authenticator app</h2>
<p class="auth-description">Codes from an app keep working without signal and can't be intercepted like text messages.</p>
</header>
<ol class="auth-setup">
<li class="auth-setup-step">
<p class="auth-setup-title">Scan this QR code</p>
<p class="auth-setup-text">Open your authenticator app, tap Add account and point the camera at the code.</p>
<div class="auth-setup-scan">
<div class="qr" data-m-qr data-m-qr-value="otpauth://totp/Example:you%40example.com?secret=JBSWY3DPEHPK3PXP&issuer=Example&algorithm=SHA1&digits=6&period=30" data-m-qr-label="QR code to add Example to your authenticator app"></div>
<details class="auth-secret">
<summary class="auth-secret-toggle">Can't scan the code?</summary>
<div class="auth-secret-panel">
<span>Enter this setup key in your app instead.</span>
<div class="auth-secret-key">
<code class="auth-secret-value"><span>JBSW</span><span>Y3DP</span><span>EHPK</span><span>3PXP</span></code>
<button type="button" class="copy-btn" data-m-copy="JBSWY3DPEHPK3PXP" aria-label="Copy setup key"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="11.5" height="11.5" rx="2"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></button>
</div>
<dl class="auth-secret-meta">
<dt>Account</dt><dd>you@example.com</dd>
<dt>Type</dt><dd>Time based, 6 digits, every 30 s</dd>
</dl>
</div>
</details>
</div>
</li>
<li class="auth-setup-step">
<p class="auth-setup-title">Enter the 6 digit code</p>
<p class="auth-setup-text">Type the code your app shows for Example.</p>
<div class="otp otp-sm" data-m-otp data-m-otp-separator="3">
<input class="otp-field" name="code" maxlength="6" inputmode="numeric" autocomplete="one-time-code" aria-label="Verification code">
</div>
<div class="flex flex-wrap gap-2">
<button class="btn btn-primary">Verify and turn on</button>
<button type="button" class="btn btn-ghost">Cancel</button>
</div>
</li>
</ol>
</form>JavaScript API
Attribute
data-m-qr
Options
| Option | Description |
|---|---|
data-m-qr-value="otpauth://totp/Issuer:account?secret=...&issuer=Issuer" | |
data-m-qr-label="Scan with your authenticator app" | |
data-m-qr-border="2" (quiet zone in modules) |
Methods
| Method | Description |
|---|---|
Monsoon.qr(el).value = "otpauth://..." | |
Monsoon.qr(el).version | |
Monsoon.qr(el).modules |
Events
| Event | Description |
|---|---|
monsoon:qr-render { version, size, mask } | |
monsoon:qr-error { message } | |
monsoon:otp-complete { code } |
Classes
20 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 |
|---|---|---|
| Modifier | Modifier, combined with the auth-setup class. On a <form> in the example. Sets grid display, gap, width, padding, text color and background, and 4 custom properties.CSS |
|
| Modifier | Modifier, combined with the auth-setup class. On a <form> in the example. Sets width.CSS |
|
| Modifier | Modifier, combined with the auth-setup class. On a <header> in the example. Sets grid display, alignment, gap and text style.CSS |
|
| Modifier | Modifier, combined with the auth-setup class. On a <header> in the example. Sets alignment, text style and width.CSS |
|
| Part | Part of the authenticator app setup. On a <span> in the example. Sets grid display, alignment, width, height, margin and text color, and --tone.CSS |
|
| Part | Part of the authenticator app setup. On a <h2> in the example. Sets margin, text size, font weight and text style.CSS |
|
| Part | Part of the authenticator app setup. On a <p> in the example. Sets width, margin, text size, text style and text color.CSS |
|
| Base | Base class of the authenticator app setup. On an <ol> in the example. Sets grid display, gap, margin and padding, and --tone.CSS |
|
| Part | Part of the authenticator app setup. On a <li> in the example. Sets grid display, gap, width, padding, generated content and absolute position.CSS |
|
| Modifier | Modifier, combined with the auth-setup class. Not used in the example above. Sets generated content, background and shadow.CSS |
|
| Part | Part of the authenticator app setup. On a <p> in the example. Sets margin, text size, font weight and text style.CSS |
|
| Part | Part of the authenticator app setup. On a <p> in the example. Sets margin, text size, text style and text color.CSS |
|
| Part | Part of the authenticator app setup. On a <div> in the example. Sets flex display, alignment, gap and width.CSS |
|
| Part | Part of the authenticator app setup. On a <details> in the example. Sets text size, text color and transform.CSS |
|
| Part | Part of the authenticator app setup. On a <summary> in the example. Sets inline-flex display, alignment, gap, font weight, text color and corner radius.CSS |
|
| Part | Part of the authenticator app setup. On a <div> in the example. Sets grid display, gap and margin.CSS |
|
| Part | Part of the authenticator app setup. On a <div> in the example. Sets flex display, alignment, gap, padding, background and border.CSS |
|
| Part | Part of the authenticator app setup. On a <code> in the example. Sets flex display, alignment, gap, width, text size and font weight.CSS |
|
| Part | Part of the authenticator app setup. On a <dl> in the example. Sets grid display, grid tracks, gap, margin, text color and font weight.CSS |
|
| Part | Part of the authenticator app setup. On a <div> in the example. Sets grid display, alignment, width, padding, text color and background, and --qr-size, --qr-light and --qr-dark.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>
<!-- Authenticator app setup: start from the base class, then add modifiers -->
<form class="auth-card auth-card-wide" action="#" onsubmit="event.preventDefault()">
<header class="auth-header auth-header-start">
<span class="auth-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="6.5" y="2.5" width="11" height="19" rx="2.5"/><path d="M10.5 18.5h3"/><path d="M9.5 9.5h5M9.5 12.5h3"/></svg></span>
<h2 class="auth-title">Set up your authenticator app</h2>
<p class="auth-description">Codes from an app keep working without signal and can't be intercepted like text messages.</p>
</header>
<ol class="auth-setup">
<li class="auth-setup-step">
<p class="auth-setup-title">Scan this QR code</p>
<p class="auth-setup-text">Open your authenticator app, tap Add account and point the camera at the code.</p>
<div class="auth-setup-scan">
<div class="qr" data-m-qr data-m-qr-value="otpauth://totp/Example:you%40example.com?secret=JBSWY3DPEHPK3PXP&issuer=Example&algorithm=SHA1&digits=6&period=30" data-m-qr-label="QR code to add Example to your authenticator app"></div>
<details class="auth-secret">
<summary class="auth-secret-toggle">Can't scan the code?</summary>
<!-- 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
- Built on
detailsandsummary, so it opens with Enter or Space and screen readers announce expanded and collapsed. A sharednamemakes a group exclusive. - 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.