Skip to content
IndexRequest a UIAboutContact

One-Time Code Input

Six code boxes that auto-advance, handle paste and verify at the last digit (demo code 123456).

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Design a six-box one-time code input for phone verification. Each box is a 44 by 52 pixel rounded square with a large centred digit, inputmode numeric, autocomplete one-time-code on the first box. Typing a digit moves focus to the next box, Backspace on an empty box moves back and clears, arrow keys move between boxes, pasting a six digit code fills all boxes. When all six digits are entered, verify: code 123456 turns the borders green and shows "Verified", anything else shakes the row, turns borders red and shows "Wrong code. Try again." with focus returning to the first box. Group with role group and aria-label "Verification code", each box labelled "Digit 1 of 6". Light minimal style, prefers-reduced-motion fallback. Plain HTML, CSS and JavaScript.

About this pattern

Definition

A one-time code input splits a short numeric code into separate boxes. Typing moves focus forward, Backspace moves it back and pasting fills all boxes at once.

Purpose & UX principles

  • Faster and clearer than a single field for 4 to 6 digit codes; supports autofill from SMS.
  • Accept paste of the whole code, ignore non-digits and verify automatically after the last digit.
  • Show clear error feedback and keep focus so people can correct without extra taps.

Interaction states

  • Empty, partially filled, verifying, success ("Verified") and error (shake, red border). The code 123456 succeeds; anything else fails.

Motion specification

  • Error shakes 4px for 300ms; success border turns green in 150ms.
  • Reduced motion: no shake, only the red border and message.

Responsive behaviour

  • Boxes are at least 44px wide on touch; they shrink evenly on narrow screens.
  • Use inputmode numeric and autocomplete one-time-code so phones offer the SMS code.

Code

HTML
<div class="bx"><div class="row" id="row" role="group" aria-label="Verification code"></div><p class="msg" id="msg" aria-live="polite">Enter the 6-digit code we sent you. Try 123456.</p><button id="rs" type="button">Clear</button></div>

Related patterns

Text Input

↗
Text InputInputs & Forms

Validation States

↗
Validation StatesInputs & Forms

Loading Button States

↗
Loading Button StatesButtons & Actions