To get an SMS code to autofill, put the code in a predictable spot in the message, mark the input field as a one-time code and keep the message short and single-purpose. On iPhone the keyboard suggests the code when it recognizes the format. On Android an app can read the code through the platform's SMS Retriever, with the message formatted to match.
The input field
On the web, set autocomplete="one-time-code" on the code input and use a numeric input mode. iPhones then offer the code above the keyboard. Don't split the code into six separate boxes without handling paste, or autofill will fill only the first one.
The message format
- Lead with the code or put it right after a short label: "123456 is your Acme code."
- One code per message, 4 to 8 digits.
- Say what the code is for and when it expires.
- Don't add links. A link in an OTP is a phishing signal.
Where the platform supports domain-bound codes, add the website at the end in the form @acme.example #123456 so the code only offers itself on the right site.
Android
An app using SMS Retriever needs the message to end with an app-specific hash that the app computes, and the message has to stay under the length limit. If you serve both a web page and an app, test each path separately.
Keep it to one segment
A code that fits in 160 characters is one segment. An emoji drops the limit to 70. Long, branded texts can split and arrive out of order, which breaks autofill. Our OTP sending rules post covers segments and separation from marketing traffic.
Expiry and resend rules
| Rule | Suggestion |
|---|---|
| Code lifetime | A few minutes |
| Resend cooldown | 30 to 60 seconds |
| Attempts | A small cap, then lock and require a new code |
| New code | Invalidates the old one |
Send reliably
Send each code with an Idempotency-Key, one per request, so a retry doesn't send two different codes. Add a login and verification campaign on Ready once the brand is approved. See SMS OTP and verification API.
The takeaway
Format the message, mark the field and keep codes short. Test on real iPhone and Android devices before launch. The API integration guide covers the send path.