PIN code
Boxes for a one-time code or a PIN. It is one real input drawn as boxes, so phones can fill the code from a text message, pasting a whole code works, and screen readers read it as one field.
One-time code
Put an input in .pin. maxlength sets the number of boxes. Typing moves to the next box, Backspace goes back, and paste fills them all.
<div class="stack gap-2 items-start">
<label class="form-label" for="pin-1">Code from your email</label>
<div class="pin"><input id="pin-1" class="pin-input" inputmode="numeric" autocomplete="one-time-code" maxlength="6"></div>
</div>Split, letters, hidden
data-split="3" adds a dash after every third box. data-momo-pin="text" also takes letters (shown in capitals). .pin-mask shows dots, for a PIN.
<div class="stack gap-5 items-start">
<div class="pin" data-split="3"><input class="pin-input" inputmode="numeric" autocomplete="one-time-code" maxlength="6" aria-label="Code, 6 digits"></div>
<div class="pin" data-momo-pin="text" data-split="4"><input class="pin-input" maxlength="8" aria-label="Recovery code"></div>
<div class="pin pin-mask pin-sm"><input class="pin-input" inputmode="numeric" autocomplete="off" maxlength="4" aria-label="PIN"></div>
</div>Check it
When the last box is filled the input fires momo:pin-complete. Show the result with Momo.pin.valid(el) or Momo.pin.invalid(el) (a red shake), and Momo.pin.clear(el) to start again. Add data-momo-pin-submit to the form to send it by itself. Try 246810:
<form class="stack gap-3 items-start" id="pin-check" onsubmit="event.preventDefault()">
<div class="pin pin-lg"><input class="pin-input" inputmode="numeric" autocomplete="one-time-code" maxlength="6" aria-label="Verification code"></div>
<p class="text-sm text-muted m-0">No code yet? <button class="btn btn-sm btn-ghost" type="button" onclick="Momo.pin.clear('#pin-check .pin')">Clear</button></p>
</form>Notes
- Keep
autocomplete="one-time-code"for codes sent by text: phones offer the code above the keyboard. Useautocomplete="off"for a PIN. - Give it a label (
<label for>oraria-label): the boxes themselves are hidden from screen readers. - Sizes:
.pin-smand.pin-lg. On a narrow phone the boxes shrink to fit.