One-time code input that fills itself

With two attributes, an iPhone offers the code from Messages right above the keyboard.

Last updated November 30, 2026 · Keyboards checked on real phones: iPhone (iOS 17 and 18), Galaxy S24 and S25, Pixel 9, Motorola Edge 50 Fusion

<label for="otp">Verification code</label>
<input id="otp" name="otp" type="text"
       inputmode="numeric" pattern="[0-9]*"
       autocomplete="one-time-code" maxlength="6">

What each part does

One box, not six

Six separate one-digit boxes look neat but break easily. Autofill and paste put the whole code into the first box. Screen readers announce six unlabeled fields. Moving focus between them needs JavaScript that often fights the keyboard. If you want the six-box look, draw it with CSS on a single input, for example with letter-spacing and a background pattern.

Make the message match

For iPhone to offer the code, the text message has to contain it clearly, ideally with the word "code". You can also add an origin-bound line at the end, such as @example.com #123456, so the code is only offered on your domain. This format is supported by Safari and by Chrome on Android.

Do not

What people actually type

On real phones, the keyboard for this field is not identical everywhere. The iPhone number pad has only digits. The Galaxy number pad adds a ".-" key and a comma, and Gboard on Pixel and Motorola adds a dash, comma, point and space. People who read a code like "123 456" from an email will type the space on Android. Strip everything that is not a digit before you check the code, rather than rejecting it.

otp.addEventListener('input', () => {
  otp.value = otp.value.replace(/\D/g, '').slice(0, 6);
});

A message that autofills

Your Example verification code is 482913.

@example.com #482913

The first line is for people. The last line binds the code to your domain: Safari offers it only on example.com, and Chrome on Android can read it through the WebOTP API with navigator.credentials.get({ otp: { transport: ['sms'] } }). Keep the last line exactly in that format, with the domain of the page that shows the field.

Errors and resends

Frequently asked questions

Why does my code not appear above the keyboard?

Check that the field has autocomplete="one-time-code", that only one field on the page has it, and that the message clearly contains the code.

Should a one-time code field use type="number"?

No. Use type="text" with inputmode="numeric", so leading zeros are kept.

Does autocomplete="one-time-code" work on Android?

Chrome on Android can suggest or read the code too, especially when the message ends with the @domain #code line.

Found a mistake or want a check added? Write to contact (at) mobileformcheck.com.