Two factor and sign in
QR code
A QR code generated in the browser (byte mode, error correction level M, versions 1 to 10, up to 213 bytes) as a crisp SVG. Dark modules stay on a light tile in dark mode too, so every camera can read it. Three sizes. 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="flex flex-wrap items-end gap-6">
<div class="qr qr-sm" data-m-qr data-m-qr-value="https://example.com" data-m-qr-label="QR code for example.com"></div>
<div class="qr" data-m-qr data-m-qr-value="WIFI:T:WPA;S:Example Guest;P:monsoon-rain-42;;" data-m-qr-label="QR code to join the Example Guest network"></div>
<div class="qr qr-lg" 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 for an authenticator app"></div>
</div>JavaScript API
Attribute
data-m-qr
Options
| Option | Description |
|---|---|
data-m-qr-value="any text or URL" | |
data-m-qr-label="QR code" (accessible name) | |
data-m-qr-border="2" | |
data-m-qr-mask="0" (0 to 7, chosen automatically when left out) |
Methods
| Method | Description |
|---|---|
Monsoon.qr(el).value | |
Monsoon.qr(el).value = "https://example.com" | |
Monsoon.qr(el).version | |
Monsoon.qr(el).modules (rows of 0 and 1) |
Events
| Event | Description |
|---|---|
monsoon:qr-render { version, size, mask } | |
monsoon:qr-error { message } |
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 |
|---|---|---|
| Modifier | Modifier, combined with the qr-code class. 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 |
|
| Base | Base class of the qr code. Not used in the example above. Sets block display, width and height.CSS |
|
| Modifier | Modifier, combined with the qr-code class. On a <div> in the example. Sets corner radius, and --qr-size.CSS |
|
| Modifier | Modifier, combined with the qr-code class. On a <div> in the example. Sets corner radius, and --qr-size.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>
<!-- QR code: start from the base class, then add modifiers -->
<div class="flex flex-wrap items-end gap-6">
<div class="qr qr-sm" data-m-qr data-m-qr-value="https://example.com" data-m-qr-label="QR code for example.com"></div>
<div class="qr" data-m-qr data-m-qr-value="WIFI:T:WPA;S:Example Guest;P:monsoon-rain-42;;" data-m-qr-label="QR code to join the Example Guest network"></div>
<div class="qr qr-lg" 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 for an authenticator app"></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.