Skip to main content Accessibility Feedback

How to autocomplete two-factor authentication codes with a single HTML attribute

Today’s tip comes courtesy of Tomek Sułkowski on Twitter.

If you manage an app that supports two-factor authentication, either through an app or SMS, you can make it easy for users to autocomplete their unique code. The trick is a single HTML attribute: [autocomplete="one-time-code"].

<label for="two-factor-auth">Authentication Code</label>
<input id="two-factor-auth" autocomplete="one-time-code">

Tomek setup a demo here. (I made a fork on CodePen in case his goes down or you want to fork and test yourself).

To use it, text yourself a short “auth code” (maybe 4 or 6 digits). You can also read more about the [autocomplete] attribute on MDN.