SMS OTP Web Verification: WebOTP API, Form Markup, and Origin-Bound Messages
How to verify phone numbers with SMS OTP using WebOTP, semantic forms, origin-bound SMS text, iframe policies, and browser fallbacks.
This page summarises Chrome Developers documentation on verifying phone numbers with SMS one-time passwords (OTPs). The same guidance appears in the SMS OTP form verification guide and Verify phone numbers on the web with the WebOTP API. Together they describe a layered flow: semantic form markup, autocomplete="one-time-code", an origin-bound SMS last line (@domain #code), and optional JavaScript via the WebOTP API (OTPCredential).
Delivering an OTP by SMS is common for phone verification, account recovery, step-up authentication, and payment confirmation. Switching between the browser and a messaging app to copy a code adds friction, increases drop-off, and exposes users to phishing on spoofed domains.
Combining semantic
<form>markup,<input autocomplete="one-time-code" inputmode="numeric">, origin-bound SMS formatting (@domain #code), and the WebOTP API (OTPCredential) creates a layered, progressively enhanced verification flow.— Chrome Developers, SMS OTP form verification
WebOTP API: what it does and when to use it
Section titled “WebOTP API: what it does and when to use it”The WebOTP API lets a site programmatically read a specially formatted SMS bound to the site’s domain, fill the verification field, and complete verification with minimal user action.
The WebOTP API lets your app receive specially-formatted messages bound to your app’s domain. From this, you can programmatically obtain an OTP from an SMS message and verify a phone number for the user more easily.
— Chrome Developers, Verify phone numbers on the web with the WebOTP API
Typical uses include phone number as an account identifier, two-step sign-in, and payment confirmation. WebOTP does not replace server-side checks: sending the code back to your server still proves possession of the number at verification time.
Implementation has three parts: a properly annotated <input>, JavaScript that calls navigator.credentials.get(), and SMS body text your backend sends. You can try flows on chrome.dev/web-otp-demo or the desktop-oriented web-otp-demo.glitch.me.
Secure context and feature detection
Section titled “Secure context and feature detection”WebOTP requires a secure context (https:// in production, or http://localhost during local development). On plain HTTP, feature detection fails.
Guard the API behind 'OTPCredential' in window. Do not load a third-party polyfill for SMS reading; that needs OS-level integration. When WebOTP is unavailable, rely on autocomplete="one-time-code" and manual entry (see Progressive enhancement without WebOTP).
SMS OTP form markup: single input and autocomplete
Section titled “SMS OTP form markup: single input and autocomplete”Semantic markup matters for accessibility, validation, and cross-browser autofill.
Wrap the control in a <form method="POST"> with an explicit <button type="submit">. Use one <input> for the code—not six single-digit boxes, which break autocomplete="one-time-code", hinder paste, and complicate screen readers.
| Approach | Recommendation |
|---|---|
| Input type | type="text" with inputmode="numeric" |
| Avoid | type="number" (spinners, leading zeros, scroll-wheel changes) |
| Avoid | type="tel" (meant for full phone numbers) |
| Autofill hint | autocomplete="one-time-code" |
| UX | Visible <label>, hints above the field via aria-describedby so keyboards do not hide instructions |
Always use a single
<input>element rather than splitting digits across multiple boxes.— Chrome Developers, SMS OTP form verification
For a segmented look without splitting the DOM, style one field (for example monospace font and letter-spacing); the SMS OTP form verification guide includes a full example with pattern, maxlength, and submit handling.
Origin-bound SMS format: @domain #code on the last line
Section titled “Origin-bound SMS format: @domain #code on the last line”Both WebOTP and Safari’s domain-bound autocomplete="one-time-code" depend on the last line of the SMS.
Correct example:
Your verification code is 123456.
@example.com #123456Rules from Format the SMS message and Origin-bound SMS message format:
- Start with human-readable text that includes the code for users on another device.
- Put
@<host>and#<otp>on the final line;@must be the first character of that line, with nothing after it. - Use only the host: no
https://, port, or path. - Exactly one space between
@domainand#code; no spaces inside the domain or between#and the digits.
The human-readable part should contain a four-to-ten character alphanumeric OTP string with at least one digit before the last line, per Verify phone numbers on the web with the WebOTP API. Malformed variants (scheme in @, extra lines after the binding line, missing #, sender in contacts breaking consent on Android) are listed in that document’s format section.
Integrating navigator.credentials.get() and AbortController
Section titled “Integrating navigator.credentials.get() and AbortController”Call navigator.credentials.get({ otp: { transport: ['sms'] }, signal }) when the OTP step is active—for example after the user requests a code and again on “Resend code”. The SMS must arrive after get() runs on the same device that called it (except the desktop Chrome sync case below).
On success you receive an OTPCredential with code and type: "otp". Set the input value, then submit via form.requestSubmit()—not form.submit(), which skips submit listeners and constraint validation.
Manage an AbortController across all exit paths: Pass an AbortSignal (
signal: ac.signal) tonavigator.credentials.get(). Callac.abort()whenever: The user manually submits the form … A new SMS code is requested … The verification component, dialog, or route unmounts.— Chrome Developers, SMS OTP form verification
The SMS OTP form verification guide shows stopSmsOtpListener(), resend handling, and abort-on-submit in one lifecycle. The older sample on Verify phone numbers on the web with the WebOTP API uses DOMContentLoaded and form.submit(); prefer tying the listener to your UI step and using requestSubmit() for new work.
Minimal shape:
if ('OTPCredential' in window) { const ac = new AbortController(); navigator.credentials.get({ otp: { transport: ['sms'] }, signal: ac.signal, }).then(otp => { input.value = otp.code; form.requestSubmit(); });}Cross-origin iframe WebOTP: 3D Secure and payment flows
Section titled “Cross-origin iframe WebOTP: 3D Secure and payment flows”Embedded issuer challenges (for example shop.example embedding bank.example) need three coordinated settings:
- SMS last line lists both origins: top-level first, then iframe—
@shop.example #123456 @bank.example(SMS OTP form verification). - Parent sends
Permissions-Policy: otp-credentials=(self "https://bank.example"). - Iframe has
allow="otp-credentials"and a descriptivetitle.
Inside the iframe, use the same form markup and WebOTP lifecycle. Try web-otp-iframe-demo.stackblitz.io. If otp-credentials delegation is unsupported, the iframe falls back to keyboard autofill and manual entry without throwing (SMS OTP form verification).
WebOTP on desktop Chrome and browser support
Section titled “WebOTP on desktop Chrome and browser support”From Chrome 93, desktop Chrome can complete verification using an SMS received on a linked Android device via Chrome Sync—the same site code as on mobile, with the user signed into the same Google account on desktop Chrome and Android Chrome (Verify a phone number on desktop using WebOTP API, Use WebOTP on desktop).
This feature is powered by Chrome Sync so it works Chrome only at the moment. Receiving and transmitting SMS on iOS or iPad OS in Chrome is not supported.
— Chrome Developers, Verify a phone number on desktop using WebOTP API
Chromium implements the WebOTP JavaScript API; Safari does not, but Chromium and WebKit share the SMS text format. With autocomplete="one-time-code" and iMessage SMS relay, Safari on macOS can suggest codes when the message matches the origin (Is this API compatible between different browsers?).
Progressive enhancement without WebOTP
Section titled “Progressive enhancement without WebOTP”When OTPCredential is missing:
- Safari (and similar) may offer keyboard autofill from
@domain #codeSMS. - Other browsers rely on
type="text",inputmode="numeric", and manual submit.
inputmode and AbortController need no polyfills on modern browsers (SMS OTP form verification).
Security limits of SMS OTP and common test mistakes
Section titled “Security limits of SMS OTP and common test mistakes”SMS OTP shows possession of a number, not strong authentication.
Attackers can spoof SMS and hijack a person’s phone number. Carriers can also recycle phone numbers to new users after an account is closed.
— Chrome Developers, Verify phone numbers on the web with the WebOTP API
SMS transport and phone numbers can be subject to SIM swapping, number recycling, and interception.
— Chrome Developers, SMS OTP form verification
Prefer passkeys or Web Authentication for phishing-resistant primary sign-in; use SMS OTP where convenience fits, often with extra factors for re-auth (Is it safe to use SMS as a way to authenticate?).
Why the WebOTP dialog does not appear
Section titled “Why the WebOTP dialog does not appear”- Sender number in the receiver’s contacts—by design the SMS User Consent API will not trigger (The dialog doesn’t appear though I’m sending a properly formatted message).
- Work profile on Android: try personal-profile Chrome where SMS arrives.
- Re-check
@domain #codeformatting; use demos at chrome.dev/web-otp-demo. - Desktop/Android sync issues: on the Android device that receives SMS,
chrome://sync-internals→ Stop Sync → Request Start (Verify a phone number on desktop using WebOTP API).
Demo source: GoogleChromeLabs/web-identity-demos.
How to check this on your site
Section titled “How to check this on your site”-
Open your OTP page over HTTPS (or
localhost), confirm a single<input autocomplete="one-time-code" inputmode="numeric">inside a POST<form>, following SMS OTP form verification. -
Trigger an SMS from your backend and verify the last line is exactly
@your-host #codewith no scheme, port, path, or trailing signature (Format the SMS message). -
On Android Chrome, exercise WebOTP with a non-contact sender number using chrome.dev/web-otp-demo or your staging site; confirm prompt, fill, and
requestSubmit()behavior per Verify phone numbers on the web with the WebOTP API. -
On Safari/iOS, focus the field and confirm keyboard autofill when the same SMS format is used (Is this API compatible between different browsers?).
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the statement you are asking about, and we will correct or clarify it.