Visitors on a phone expect the SMS code to appear above the keyboard, ready to tap. When it doesn't, they switch apps, lose their place, and sometimes abandon the form. In most cases the fix is markup, not a new SMS provider. Getting autocomplete one-time-code sms verification form field best practices right means putting one attribute on one input, keeping the rest of the field intact, and then proving that browser autofill still works after the Detected Form widget connects your form.
This guide covers the token itself, when it helps and when it backfires, the markup that survives the widget, the mistakes that quietly disable SMS autofill, and a repeatable manual test pass you can run before launch.
What autocomplete="one-time-code" actually does
The autocomplete attribute tells the browser what kind of value a field expects, so it can offer a matching suggestion. one-time-code is the token reserved for a single-use verification code, the kind sent by SMS or read from an authenticator. It is intended for the input that receives the code itself. It is not a token for the phone number, the name, or the email that precede it.
The usual pattern is a short text-style input with a numeric keypad, a length limit, and the token:
<label for="otp">Enter the 6-digit code we texted you</label>
<input
id="otp"
name="otp"
type="text"
inputmode="numeric"
autocomplete="one-time-code"
maxlength="6"
pattern="[0-9]{6}"
required
>
Each attribute does a different job. inputmode="numeric" asks mobile browsers for a number-friendly keyboard without the quirks of type="number" (spinner arrows, scroll-wheel changes, lost leading zeros). maxlength and pattern are part of native validation: the browser blocks submission and shows a message when the value is missing or the wrong shape, which is the behavior described in MDN's guide to client-side form validation. The name attribute is what carries the value to the server as a name/value pair when the form is submitted, as covered in MDN's explanation of sending form data.
What the token does not do: it does not send the SMS, does not validate the code against your backend, does not guarantee a suggestion appears, and does not replace server-side checks. It is a hint. The browser and operating system decide whether and how to surface it.
When the token helps, and when it hurts
The token is most valuable on a single OTP input, typically a verification step after a phone number has already been captured. On an iOS or Android device, a correctly configured field can receive the code from the notification with one tap instead of a manual copy.
It gets murky in two setups:
- Split six-box inputs. Designs that render six separate one-character inputs break the model. Each box is its own field, so there is no single place for the browser to put a whole code. If you keep the visual look, use one real input with the token and
maxlength, then style it, or accept that autofill will not work and provide a clear manual path. - Combined name and phone forms. If your form asks for name, phone and code together, the OTP field still gets the token, but the phone field needs its own correct token (
telortel-national), and the two must not be confused. Mislabeling the code field astelinvites the browser to fill a phone number into the code box.
A useful rule: one real input for the code, clearly labeled, with the token on exactly that input and nothing else.
Markup that survives the Detected Form widget
The Detected Form widget connects an existing HTML form to WidgetJar; it does not rebuild your form. That is good news for autofill, because the attributes you already wrote stay in place. Your job is to make sure nothing about the connection strips or duplicates them.
Before and after connecting the widget, confirm in the browser's element inspector that:
- The OTP input still has a unique
idand anamethat matches what your handler expects. autocomplete="one-time-code"is still on that input and has not been copied onto the phone field.- The
label forvalue still points at the OTP input'sid. inputmode,maxlength,patternandrequiredremain unchanged.- There is still exactly one OTP input, not a duplicate rendered by any add-on.
If fields arrive empty after connecting a widget, missing or duplicated name attributes are a common cause; our guide to missing name attributes and dropped submissions walks through that audit. If the browser seems to be filling the wrong fields, the field-mapping approach in native browser autofill overwriting values is the closer match.
Common reasons SMS autofill fails
Most failures trace back to one of these:
- Wrong token casing or spelling. Tokens are lowercase and hyphenated.
one-time-codeworks;OneTimeCode,one_time_codeorotpdo not. - The token on the wrong field. Putting
one-time-codeon the phone input invites a code into the phone box. The phone field wantstelortel-national; see form autocomplete attribute best practices for the full field-by-field map. - A non-text input type.
type="number"brings spinner behavior and value quirks. Prefertype="text"withinputmode="numeric"unless you have a specific reason otherwise. - JavaScript masking that fights input. A keyup handler that rewrites the value on every keystroke can break a pasted or autofilled code. Test with a real
pasteand with a real notification tap, not just typing. - Missing autocomplete on the phone field. If the browser cannot tell where the phone number goes, the whole flow becomes unreliable on return visits.
- A hidden or off-screen input. Autofill targets the field the user actually sees. A code input that is visually hidden until a timer finishes will usually miss the suggestion.
Accessibility notes
Autofill is a convenience; the field must work without it. Keep a visible <label> tied to the input rather than relying on placeholder text, which disappears on typing. Announce the purpose plainly, for example "Enter the 6-digit code we texted you." If you add hints, connect them with aria-describedby instead of stuffing them into the label.
When the code is wrong, show an inline error next to the field and keep focus there, following the patterns in our contact form error messages guide. Rely on native constraint validation where you can, and make sure any custom message is exposed, not just painted in red. If your OTP step appears inside a modal, the dialog needs a name and contained focus per the WAI-ARIA modal dialog pattern, and the code field should receive focus when the dialog opens.
A four-scenario manual test pass
Run this after the Detected Form widget is connected, on a real form with a real SMS provider in a staging environment:
- iOS Safari. Submit the phone number, receive the SMS, and long-press or tap the code suggestion above the keyboard. Confirm the full code lands in the OTP input and that validation passes.
- Android Chrome. Repeat with the notification tap and with the keyboard suggestion, if offered. Confirm leading zeros are preserved.
- Desktop Chrome. Check that browser autofill does not invent a value in the code field, and that pasting a code works cleanly with any masking script.
- Password-manager extension. With at least one manager active, confirm it does not duplicate the field, overwrite a typed code, or block submission.
Log, for each scenario: browser and version, OS version, whether a suggestion appeared, whether the value landed correctly, the validation result, and a screenshot of the submitted payload in the network tab.
Pre-launch checklist
- One real OTP input with
autocomplete="one-time-code",type="text",inputmode="numeric", a length limit and a pattern. - Phone field carries
autocomplete="tel"ortel-nationaland its own correctname. - Visible label tied by
for/id; hints linked witharia-describedby. - Inline, announced error message when the code is wrong; focus stays on the field.
- No split-box inputs unless you accept that autofill will not work.
- Masking or formatting scripts tested with paste and with real SMS autofill.
- All four test scenarios logged with evidence before you ship.
Next step
Once the markup is right and the test pass is logged, connect the form with the Detected Form widget so its submissions land in WidgetJar without touching your backend, then re-run the same four scenarios to confirm SMS autofill and validation still behave exactly as they did before.