100MB FREEResidential proxiesClaim
NumberOTP

SMS OTP Autofill on the Web: one-time-code and WebOTP

Make SMS OTP autofill work on your site: the one-time-code input, the @domain #code SMS format, WebOTP in Chrome, browser support and a format checker.

NNanami
November 29, 202613 min read

SMS OTP autofill on the web takes three pieces: one input with autocomplete="one-time-code", an SMS whose last line reads @your-domain #123456, and, for Chrome, a short call to the WebOTP API. Get all three right and the code fills itself with one tap on iPhone and Android. This guide covers each piece, the format mistakes that quietly break it, and how to check the real SMS before you ship. It is the written companion to our video on OTP autofill, and if you're still deciding how to test the sign-up flow as a whole, start with our guide to testing SMS OTP without a real phone.

Facts here come from the WICG draft spec, web.dev, MDN, Chrome's and Apple's developer docs, all read on 30 November 2026. The browser and format results come from a local run on the same day, and its raw output is described below.

How SMS OTP autofill works on the web

The phone's operating system reads the incoming SMS, spots the code, and offers it to the browser for a field marked as a one-time code. You don't control that detection, but you control the two signals it looks for: how the field is marked and how the message is written.

There are two paths:

  • Keyboard suggestion (iOS Safari, Chrome on Android, others). The field has autocomplete="one-time-code". When the SMS arrives, the code appears above the keyboard and the user taps it. Apple's documentation says iOS detects one-time codes in SMS and offers them for AutoFill in one-time code fields in apps and websites.
  • WebOTP API (Chromium browsers). Your JavaScript asks the browser for the code. Chrome shows a consent sheet when a matching SMS arrives, and your script gets the code and can submit the form.

Both paths work best with an origin-bound message: the last line of the SMS names your domain and the code. That stops a code meant for your site from being offered on someone else's.

Piece one: the input field

Use one plain text input with three attributes. web.dev's SMS OTP form guidance recommends exactly this, and it is the part most sites get wrong.

<form action="/verify-otp" method="POST">
  <label for="otp">Enter the 6-digit code</label>
  <input id="otp" name="otp"
         type="text"
         inputmode="numeric"
         autocomplete="one-time-code"
         pattern="\d{6}"
         required>
  <button>Verify</button>
</form>
  • type="text", not type="number".
  • inputmode="numeric" brings up the digit keypad on phones.
  • autocomplete="one-time-code" is the hint the browser and OS look for. MDN lists it as supported in Safari 12, Firefox 109 and Chrome 93 (Chrome for Android 84).
  • pattern="\d{6}" and required are optional, but they catch a short code before it reaches your server.

Why not type="number"?

A number field treats the code as a quantity, and codes aren't quantities. In our local check (Chromium 151, 30 November 2026), a number input holding 012345 reported valueAsNumber as 12345, with the leading zero gone, and it also accepted 0123e4 as a value. It also shows spinner arrows nobody needs. The text input with pattern="\d{6}" kept 012345 intact and failed validation on a five-digit entry.

Why one input, not six boxes?

Six separate boxes look nice, but autofill fills one field. Chrome's current forms guidance says to always use a single input rather than splitting digits across boxes. If the design calls for boxes, style one input to look like them (letter-spacing, a background with six cells) instead of splitting it.

The typo that fails silently

The token must be exactly one-time-code, hyphenated. In the same run, an input with autocomplete="one-time code" (a space instead of the second hyphen) reported its autocomplete value as an empty string. The browser simply ignored it. No warning, no console error, just no autofill.

Piece two: the SMS format

Put the code on the last line in the form @host #code. The WICG origin-bound one-time codes draft defines it: @ before the top-level host, # before the code, exactly one space between the values, nothing before the host, and any trailing text on that line ignored. The human-readable text goes above it.

Your Example sign-in code is 482910. It expires in 10 minutes.

@www.example.com #482910

Rules that matter in practice:

  • Host only. No https://, no path, no port. Chrome's documentation says the same.
  • The exact host. @example.com and @www.example.com are different hosts. Use the host the user sees in the address bar on the verify page.
  • Keep it short. web.dev advises keeping the whole message to 140 characters or fewer; you can check yours with our SMS character counter. Chrome's docs describe the code itself as 4 to 10 alphanumeric characters with at least one digit.
  • Same code twice. The code in the body and the code on the last line must match. That sounds obvious until two templates drift apart.

Six format mistakes, checked

We wrote a small checker that applies the spec's last-line rules and ran ten sample messages through it on 30 November 2026, with www.example.com as the page host. These are the ones that failed and why:

Last line of the SMSResultWhy
@www.example.com #482910PassCorrect form
@www.example.com #482910 expires in 10 minPassTrailing text is ignored
#482910 @www.example.comFailCode before host
Do not share this code. (domain line above it)FailDomain line is not the last line
@https://www.example.com #482910FailScheme in host
@www.example.com:443 #482910FailPort in host
@www.example.com  #482910FailTwo spaces before the code
@example.com #482910FailHost doesn't match the page (www)

The checker is about twenty lines: split the message on newlines, take the last line, match ^@(\S+) #(\S+)( @(\S+))?, then reject a scheme, path or port, compare the host with your page's host, and confirm the code also appears in the body. Run it in your unit tests against the exact template your backend sends. A sneaky failure is a "Do not share this code" footer added below the domain line by a later template edit.

Codes inside an iframe

If the code field sits in an iframe from another origin, the message needs both hosts, and Chrome and Safari disagree on the syntax. The spec and Chrome (version 91 and later) use @top-host #code @iframe-host. Apple's domain-bound codes documentation uses a percent sign for the iframe host: @top-host #code %iframe-host. One message can't satisfy both, so if you can, move the code field into the top-level page. For WebOTP in an iframe, Chrome also needs a Permissions-Policy: otp-credentials header that lists the iframe origin and allow="otp-credentials" on the iframe element.

Piece three: the WebOTP API

WebOTP lets your script receive the code directly in Chromium browsers. Call it when the verify page loads, before the SMS is sent, and always keep the manual input working.

if ('OTPCredential' in window) {
  const input = document.querySelector('input[autocomplete="one-time-code"]');
  const form = input.closest('form');
  const ac = new AbortController();
  form.addEventListener('submit', () => ac.abort());   // user typed it themselves
  setTimeout(() => ac.abort(), 60_000);               // stop waiting after a minute

  navigator.credentials.get({ otp: { transport: ['sms'] }, signal: ac.signal })
    .then((otp) => {
      input.value = otp.code;
      form.requestSubmit();
    })
    .catch((err) => {
      if (err.name !== 'AbortError') console.warn('WebOTP:', err.name);
    });
}

Points the docs make that people miss:

  • HTTPS only (localhost counts as secure for development).
  • Call get() first, then send the SMS. Chrome looks for messages that arrive after the call.
  • The user still consents. Chrome shows a sheet when the SMS arrives; the code isn't handed over silently. Chrome's docs note that WebOTP doesn't work when the sender is in the user's contacts or on work profiles.
  • There's no built-in timeout in the docs, so add your own abort, as MDN's example does.

Feature detection doesn't mean a code is coming

This is the most useful result from the local run. In desktop Chromium 151, headless and headed, 'OTPCredential' in window was true, and navigator.credentials.get({otp}) neither resolved nor failed. It just waited until our 3-second abort fired (AbortError, about 3,007 ms). Desktop Chrome can only receive a code relayed from an Android phone signed in to the same Google account. Without one, the promise waits forever. So never hide the manual field behind feature detection, and never leave the call without an abort. The same fact explains why WebOTP can't be exercised in a headless CI browser; our Playwright OTP walkthrough reads the code over an API and types it instead.

Which browser does what (as of November 2026)

Safari relies on the autocomplete hint and domain-bound codes; Chromium browsers add WebOTP. Firefox supports the hint but not WebOTP. The table uses MDN's browser compatibility data (dataset dated 26 November 2026) and Apple's documentation.

Browserautocomplete="one-time-code"WebOTP APIDomain-bound SMS
Safari (iOS, macOS)Yes, since Safari 12Unclear (see below)Yes, iOS 14 / macOS Big Sur and later
Chrome for AndroidYesYes, since 84Yes (with WebOTP)
Chrome / Edge desktopYesSince 93, needs a linked Android phoneYes (relayed from the phone)
Samsung InternetNot listed separatelyYes, since 14Yes (with WebOTP)
FirefoxYes, since 109NoNo
Android WebView / in-app browsersVariesNoVaries

On Safari and WebOTP, the sources disagree. MDN's entry for the otp option and the web-features list show Safari 27, while MDN's OTPCredential entry still shows no support, and Safari 27's release notes don't mention it. Until you've seen it work on a device, treat Safari as hint-only. The autocomplete attribute plus the domain line already gives iPhone users one-tap codes.

Why OTP autofill isn't working: a quick checklist

When the code arrives but isn't offered, the cause is nearly always the field or the last line, not the phone. Work down this list:

  1. Field: exactly autocomplete="one-time-code", one input, visible and focused, not inside a closed shadow root.
  2. Last line: @host #code, one space, host matches the address bar, nothing below it.
  3. Browser: in-app browsers and WebViews often skip autofill. Try the page in Safari or Chrome itself.
  4. Framework: some React or Vue forms don't notice an autofilled value. Read the value on submit, or listen for input and change, rather than relying on keystroke handlers alone.
  5. WebOTP: called before the SMS is sent, on HTTPS, with an abort, and the sender not saved in the test phone's contacts.
  6. The SMS never arrived at all: that's a delivery problem, not autofill. This troubleshooting guide covers why OTP codes don't arrive.

If you're on the user side and want codes filled on a computer without your phone, our roundup of OTP browser extensions covers that separately.

Check the real SMS before you ship

Unit tests prove your template is right; only a real message proves what the user's phone actually receives. Carriers, SMS gateways and template engines can change line breaks, add a footer or reformat text. Do one real-number check per release: send the code to a real mobile number, read the full message text, and run it through the same last-line checker.

With the notp command-line tool that's a few commands. These lines come from the CLI help and the API reference and weren't run in this article. Only the price lookup was run, on 30 November 2026:

notp prices ot --country usa                 # live price and stock
notp buy ot --country usa --no-wait --json   # buy a number, print its id
# ...trigger your app's "send code" with that number...
notp show <id> --json                     # the number, its code and every SMS

The API's activation object returns the whole message as full_sms next to the parsed otp, so a CI job can assert the last line automatically. If you'd rather receive it pushed to your server, the webhook receiver tutorial shows the same field arriving in a signed event. For the quick, free loop during development, keep using your auth platform's test numbers; Firebase's fictional test numbers are one example. They just never send a real SMS, so they can't catch a broken last line.

Why use NumberOTP for the real-number check

The pre-release check needs a real mobile number, the full SMS text and a way to script it. That's what NumberOTP is built for:

  • Developer tooling: SDKs for Node/TypeScript, Python, Go and PHP, the notp CLI, an MCP server, an OpenAPI spec, webhooks and idempotent retries, all listed on our developer hub.
  • Refund if no SMS arrives: per our refund policy (checked 30 November 2026), an activation that gets no SMS within its window, typically 20 minutes, is credited back to your wallet automatically, and you can cancel a waiting number yourself from two minutes after purchase.
  • Simple billing: top up by card or crypto and pay per number. The live price lookup on 30 November 2026 showed $1.05 for a USA number for the "any other" service.
  • Three independent number pools on our own infrastructure, with real SIM-backed mobile numbers.

Use it for your own accounts and follow each platform's terms; some platforms don't allow virtual numbers.

Frequently Asked Questions

What does autocomplete="one-time-code" do?

It tells the browser and operating system that the field expects a one-time code. When an SMS with a code arrives, iOS Safari, Chrome on Android and other browsers can offer that code above the keyboard, so the user fills it in with one tap. It doesn't read messages itself and needs no JavaScript, so it is safe to add to every OTP field.

What SMS format is needed for OTP autofill?

Write the readable message first, then end with a last line in the form @host #code, for example @www.example.com #482910. Use exactly one space, put nothing before the host, and leave out the scheme, port and path. The host must match the page where the code is entered. Text after the code on that line is ignored, but nothing should come after that line.

Does Safari support the WebOTP API?

The sources disagree as of November 2026. Some MDN data and the web-features list mark it as arriving in Safari 27, while MDN's main OTPCredential entry and Safari's release notes don't confirm it. Safari has supported the one-time-code hint since version 12 and domain-bound SMS codes since iOS 14, which already gives iPhone users one-tap autofill without WebOTP.

Why doesn't OTP autofill work with six separate boxes?

Autofill puts the whole code into one field, so six single-digit inputs either receive nothing or only the first digit. Chrome's forms guidance recommends a single input for the full code. If your design needs the look of separate boxes, style one input with letter-spacing and a background pattern instead of splitting it into six elements.

Can I test WebOTP in a headless browser?

Not end to end. In a local run in November 2026, desktop Chromium reported WebOTP as available, but the request simply waited until it was aborted, because desktop Chrome only receives codes relayed from a linked Android phone. In CI, test the SMS template with a format checker and read real codes over an API, then check the consent sheet by hand on an Android phone.

Make the code fill itself, then prove it with a real SMS

Add the one-time-code input, end your SMS with the domain line, wire up WebOTP with an abort, and run one real message through the checker before each release. Create a free NumberOTP account to get a real number and the full SMS text for that check, and get your money back automatically if no SMS arrives.

Frequently Asked Questions

What does autocomplete="one-time-code" do?+

It tells the browser and operating system that the field expects a one-time code. When an SMS with a code arrives, iOS Safari, Chrome on Android and other browsers can offer that code above the keyboard, so the user fills it in with one tap. It doesn't read messages itself and needs no JavaScript, so it is safe to add to every OTP field.

What SMS format is needed for OTP autofill?+

Write the readable message first, then end with a last line in the form @host #code, for example @www.example.com #482910. Use exactly one space, put nothing before the host, and leave out the scheme, port and path. The host must match the page where the code is entered. Text after the code on that line is ignored, but nothing should come after that line.

Does Safari support the WebOTP API?+

The sources disagree as of November 2026. Some MDN data and the web-features list mark it as arriving in Safari 27, while MDN's main OTPCredential entry and Safari's release notes don't confirm it. Safari has supported the one-time-code hint since version 12 and domain-bound SMS codes since iOS 14, which already gives iPhone users one-tap autofill without WebOTP.

Why doesn't OTP autofill work with six separate boxes?+

Autofill puts the whole code into one field, so six single-digit inputs either receive nothing or only the first digit. Chrome's forms guidance recommends a single input for the full code. If your design needs the look of separate boxes, style one input with letter-spacing and a background pattern instead of splitting it into six elements.

Can I test WebOTP in a headless browser?+

Not end to end. In a local run in November 2026, desktop Chromium reported WebOTP as available, but the request simply waited until it was aborted, because desktop Chrome only receives codes relayed from a linked Android phone. In CI, test the SMS template with a format checker and read real codes over an API, then check the consent sheet by hand on an Android phone.

Need a number right now? Get $0.10 in free credits — no card required.

Sign up free →

Written by

N

Nanami

Nanami is a telecom and digital privacy specialist at NumberOTP with over 8 years of experience in SMS verification systems, virtual phone infrastructure, and online identity protection. He covers OTP security, number masking, developer APIs, and privacy-first verification workflows for businesses and developers worldwide.

Get your first OTP number free

$0.10 in credits on signup. No card required. Works for 800+ platforms.

Get started free →