skip to content

Your app asks the user to type a six-digit code sent by SMS. Which HTML autocomplete value makes phones offer that code, and how should the input be marked up?

level: middleimportance: should knowfreq 40%

answer

  1. single-use verification code
  2. one field, not six boxes
  3. suggestion above the keyboard
  4. never leave the page to read the SMS
  5. numeric keypad, but not type=number

basics

~20 s

Use a single input with autocomplete="one-time-code". That token lets mobile browsers surface a code just received by SMS as a one-tap suggestion. Splitting the code across six separate boxes defeats it, because the token describes one whole code.

solid answer

~50 s

Mark it as one text input carrying `autocomplete="one-time-code"`, and pair it with `inputmode="numeric"` so the numeric keypad appears. That token is the signal mobile platforms look for: when a matching code arrives by SMS, the browser or OS offers it above the keyboard for a single tap, so the user never leaves your page to go read the message. Two markup decisions wreck it. The first is splitting the code into six single-character boxes for looks — the token describes one complete code, so the suggestion has nowhere sensible to land and the user is back to reading and retyping. The second is `autocomplete="off"`, added on the theory that a security code should never be remembered; `one-time-code` already means single-use, and suppression only removes the help. Keep the field labelled properly and allow paste — blocking paste is the other classic way to make this flow miserable.

code

html · 7 lines
html
<label for="otp">Verification code</label>
<input id="otp"
       name="otp"
       type="text"
       inputmode="numeric"
       autocomplete="one-time-code"
       maxlength="6">

go deeper

for a junior

Recall the token name — autocomplete="one-time-code" — and that it goes on a single input, with inputmode="numeric" for the keypad and a real label.

for a middle

Explain what the token enables: the platform offers a just-received code above the keyboard, removing the app switch that loses users mid-flow. Be able to say why type="number" is the wrong choice.

for a senior

Diagnose why a shipped verification screen never shows the suggestion — six split inputs, a suppressed autofill token, or aggressive keystroke filtering — and weigh the design against the completion rate of the flow.

for a principal

Own the verification experience as a funnel: where codes are delivered, how markup, message format and expiry interact, and what the fallback is when the platform suggestion does not appear on a given device.

## The token `one-time-code` is one of the autofill field names defined in HTML, alongside `username`, `current-password` and `new-password`. It states that the field expects a short, single-use verification code — the kind delivered by SMS for two-factor sign-in or transaction confirmation. The markup is deliberately boring: ```html <label for="otp">Verification code</label> <input id="otp" name="otp" type="text" inputmode="numeric" autocomplete="one-time-code"> ``` `type="text"` with `inputmode="numeric"` is the usual choice over `type="number"`, because a verification code is a string of digits rather than a quantity — leading zeros matter, spinners and scroll-to-change do not belong on it, and grouping separators are meaningless. ## What the token buys On mobile platforms the operating system or browser watches for an arriving message that looks like a verification code for the site the user is on. When the focused field is marked `one-time-code`, the code is offered as a suggestion directly above the keyboard. One tap fills it. The user never switches to the messaging app, never memorises six digits, never comes back to a page that has meanwhile been evicted from memory. That last point is the real payoff. App-switching mid-flow is where verification funnels leak: the user leaves to read the message, gets distracted, returns to a reloaded page or an expired code. Eliminating the switch is worth more than any amount of styling on the input. Behaviour differs across platforms in the details — how the message must be formatted, whether the site's origin must appear in it, whether a suggestion appears at all — so treat the token as an enabling signal rather than a guarantee. The flow must remain fully usable by typing. ## Why the six-box design fights it A popular visual treatment gives each digit its own square box, with scripting to advance focus as you type. It photographs well and it fights every mechanism that would have helped: - **Autofill.** The token describes one complete code. Six fields each claiming to be *the* one-time code is incoherent, and the platform suggestion has no single destination. - **Paste.** Users who copy the code from the message expect one paste to land it. Distributing pasted characters across six inputs requires code you have to write and get right, and many implementations simply drop everything after the first character. - **Correction.** Backspacing through auto-advancing boxes is a well-known usability sore point, and it is worse with a screen reader, which encounters six unlabelled single-character fields instead of one labelled control. If the design is non-negotiable, the honest approach is a single real input that owns the value, label, autofill token and paste behaviour, with the boxes as presentation over it — but the simplest correct answer in an interview is that one input is what the platform expects. ## Things that quietly break it **Suppressing autofill.** `autocomplete="off"` on a verification code is a reflex worth resisting. `one-time-code` already conveys single use; the token is a description, not a request to remember anything. **Blocking paste.** Intercepting paste events on the field is sometimes justified as anti-phishing. It mainly punishes the ordinary user who copied the code, and pushes them to retype from a second device. **Missing label.** The field still needs a real `<label>` — the autofill token speaks to the platform, not to the user or to assistive technology. **Over-restrictive input filtering.** Stripping non-digits on every keystroke can conflict with how a suggestion is inserted, and it interferes with paste of a code that arrives with a space or a dash. Validate on submit instead of policing every character. ## Related but distinct There is also a scripted route where a page can be handed the message content programmatically rather than through the autofill dropdown; that is a JavaScript browser API and belongs to the browser-platform side of the boundary, not to your markup. The markup answer is the token — and the token alone already delivers the one-tap experience on the major mobile platforms without any script. For authenticator-app codes rather than SMS, the same token is still the right description of the field: it says "single-use verification code", and a password manager that stores the shared secret can use that to offer the current code the same way. ## The short version One labelled input, `inputmode="numeric"`, `autocomplete="one-time-code"`, paste allowed, validation on submit. Everything fancier is a chance to lose the one-tap fill you were trying to enable.

  • Why prefer type="text" with inputmode="numeric" over type="number" for a verification code?
    A code is a digit string, not a quantity. `type="number"` brings spinner controls, scroll-wheel changes and locale grouping rules, and it can discard leading zeros — all wrong for a code. `type="text"` keeps the value as typed, while `inputmode="numeric"` still raises the numeric keypad on mobile. You get the keyboard benefit without the numeric widget's semantics.
  • Should you also add autocomplete="off" so the code is never remembered?
    No. `one-time-code` already describes a single-use value; adding `off` only removes the platform suggestion you were trying to enable, and contradicts the token you just wrote. Nothing about the token asks the browser to persist the code for later reuse — it exists to surface a code arriving right now.
  • The design calls for six separate digit boxes. What do you lose, and what would you do?
    You lose the one-tap fill, since the token describes one whole code and the suggestion has no single destination; you also lose clean pasting and make backspace correction and screen-reader navigation worse. Keep one real labelled input that owns the value and the token, and treat the boxes as presentation layered over it — or push back on the design.

saying these in an interview costs you the question

  • Splits the code into six inputs each marked one-time-code
  • Adds autocomplete="off" to a verification code field
  • Uses type="number" so leading zeros are lost
  • Blocks paste into the code field
  • Thinks the token requires a JavaScript API to work

context