brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: autocomplete="one-time-code" lets browsers fill in SMS verification codes

Web
~/tips/tip-html-autocomplete-one-time-code

inputmode="numeric" autocomplete="one-time-code">

Marks an input as a one-time code field so browsers can offer the code from a text message.

Typing a six digit code from a text message into a web form is annoying, because you have to remember it. A single attribute lets the browser offer to fill it in.

<form action="/verify" method="post">
  <label for="otp">Verification code:</label>
  <input name="otp" id="otp" type="text"
         inputmode="numeric" autocomplete="one-time-code">
  <button type="submit">Verify</button>
</form>

MDN describes the one-time-code token as a one-time password used to verify identity as an additional factor when signing in, most often delivered by SMS, email or an authenticator app. The browser can offer the code it received as a suggestion for the field.

MDN adds that browsers may need the input to have a name or id, sit inside a form, and belong to a form that has a submit button. Meeting those conditions makes autofill more likely.

The inputmode="numeric" in the example is not required by the token. It is a common companion that shows a number keypad on phones.

The caveat is what not to do. Do not put autocomplete="off" on these fields out of habit, since that removes something many people rely on. And do not invent your own token values to block autofill, because MDN says that fails WCAG 2.2 success criterion 1.3.5. What the browser actually offers still depends on the browser and device, so test it on the phones your visitors use.

Further reading: MDN: autocomplete attribute

More Web tips async function sha256(text) { url = URL.createObjectURL(file); function setFilter(name, value) { and open <span translate="no">Home Assistant</span> in your browser. …the page behind the drawer… All Web tips (6) All topics

Link