# One-time codes

> A code arrives in another app and expires quickly, and copying it across by hand invites mistakes.

Area: Forms. Evidence behind the answer: Moderate. Last checked November 12, 2026.
Page: https://uxreference.com/forms/one-time-code

## The answer

Use one field that can be pasted into and filled automatically, and do not submit by itself.

- **Settled, WCAG AA.** Allow the code to be pasted and filled in automatically. (https://uxreference.com/forms/one-time-code#rule-1)
- **Settled, WCAG AA.** Don’t submit when the last digit is typed, unless you said you would. (https://uxreference.com/forms/one-time-code#rule-2)
- **Moderate.** Use one field for the code, marked with the one-time-code token, with a number pad for numeric codes. (https://uxreference.com/forms/one-time-code#rule-3)

## The problem

A code arrives in another app or device and has to reach the field quickly, before it expires, without being retyped wrongly.

## How to decide

None. The sources do not describe more than one correct practice that depends on context.

## Every rule

Each rule has a grade: Settled (required by WCAG AA or law, or replicated research), Strong, Moderate, Weak, or Unsettled (use the stated default until the evidence settles).

#### Rule 1. Settled, WCAG AA

Allow the code to be pasted and filled in automatically.

- Applies when: Always.
- Based on: Standard or law
- Principle: Work for everyone

Why: WCAG 2.2 level AA (3.3.8). Reopened and checked.

Sources: [Understanding SC 3.3.8: Accessible Authentication (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/accessible-authentication-minimum.html)

Link: https://uxreference.com/forms/one-time-code#rule-1

#### Rule 2. Settled, WCAG AA

Do not submit the form automatically when the last digit is entered, unless the person was told beforehand.

- Applies when: Always.
- Based on: Standard or law
- Principle: Keep people in control

Why: WCAG 2.2 level A (3.2.2): submitting on input without prior notice is a listed failure. Reopened and checked in the pilot. One component library offers automatic submit as an option.

Sources: [Understanding SC 3.2.2 On Input (Level A)](https://www.w3.org/WAI/WCAG22/Understanding/on-input.html); [One-Time Password Field (Radix Primitives)](https://www.radix-ui.com/primitives/docs/components/one-time-password-field)

Link: https://uxreference.com/forms/one-time-code#rule-2

#### Rule 3. Moderate

Use one field for the whole code, marked with the one-time code token, with a numeric keyboard for numeric codes.

- Applies when: Always.
- Based on: Convention
- Principle: Let practiced people go faster

Why: GOV.UK, Google, Twilio and MDN agree. No test of one field against one box per digit was found. Rated 3.

Sources: [Confirm a phone number (GOV.UK Design System pattern)](https://design-system.service.gov.uk/patterns/confirm-a-phone-number/); [SMS OTP form best practices](https://web.dev/articles/sms-otp-form); [Best Practices for OTP Input Forms in HTML](https://www.twilio.com/en-us/blog/developers/best-practices/otp-input-forms-html); [Simple One-Time Passcode Inputs](https://cloudfour.com/thinks/simple-one-time-passcode-inputs/); [HTML attribute: autocomplete](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete)

Link: https://uxreference.com/forms/one-time-code#rule-3

#### Rule 4. Weak

Do not split the code into one box per digit.

- Applies when: Always.
- Based on: Convention
- Principle: Prevent errors

Why: WCAG's guidance flags split boxes where a paste fills only the first; a major component library ships a per-digit field. Convention with dissent, so 2.

Sources: [Understanding SC 3.3.8: Accessible Authentication (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/accessible-authentication-minimum.html); [Simple One-Time Passcode Inputs](https://cloudfour.com/thinks/simple-one-time-passcode-inputs/); [Best Practices for OTP Input Forms in HTML](https://www.twilio.com/en-us/blog/developers/best-practices/otp-input-forms-html); [One-Time Password Field (Radix Primitives)](https://www.radix-ui.com/primitives/docs/components/one-time-password-field)

Link: https://uxreference.com/forms/one-time-code#rule-4

#### Rule 5. Weak

Accept the code with spaces or hyphens in it.

- Applies when: Always.
- Based on: Convention
- Principle: Prevent errors

Why: GOV.UK only; reopened and checked. Rated 2.

Sources: [Confirm a phone number (GOV.UK Design System pattern)](https://design-system.service.gov.uk/patterns/confirm-a-phone-number/)

Link: https://uxreference.com/forms/one-time-code#rule-5

#### Rule 6. Weak

Say how long the code is valid, say so when it has expired, and offer to send a new one.

- Applies when: Always.
- Based on: Practitioner research
- Principle: Keep people informed

Why: GOV.UK guidance, and a 72-person study in which typed codes took 15 to 17 seconds and 30-second codes caused trouble. Rated 2.

Sources: [Confirm a phone number (GOV.UK Design System pattern)](https://design-system.service.gov.uk/patterns/confirm-a-phone-number/); [A Usability Study of Five Two-Factor Authentication Methods](https://par.nsf.gov/servlets/purl/10110669)

Link: https://uxreference.com/forms/one-time-code#rule-6

#### Rule 7. Weak

Format the text message so the device can offer the code to the right site.

- Applies when: The code is sent by text message.
- Based on: Convention
- Principle: Let practiced people go faster

Why: Vendor guidance; one security paper argues one-tap filling can help phishing. Rated 2.

Sources: [SMS OTP form best practices](https://web.dev/articles/sms-otp-form); [Verify phone numbers on the web with the WebOTP API](https://developer.chrome.com/docs/identity/web-apis/web-otp); [Taken Out of Context: Security Risks with Security Code AutoFill in iOS & macOS](https://discovery-pp.ucl.ac.uk/10076464/1/Gutmann_WAY_2019.pdf)

Link: https://uxreference.com/forms/one-time-code#rule-7

## Accessibility requirements

- WCAG 2.2, 3.3.8 Accessible Authentication (AA) and 3.2.2 On Input (A). (https://www.w3.org/WAI/WCAG22/Understanding/accessible-authentication-minimum.html)
- WCAG 2.2, 2.2.1 Timing Adjustable (A) bears on code expiry; expiry needed for security may fall under its exceptions. Not analyzed here. (https://www.w3.org/WAI/WCAG22/Understanding/timing-adjustable.html)

## Common mistakes

- One box per digit that breaks paste ([rule 4](https://uxreference.com/forms/one-time-code#rule-4)).
- A code that expires with no message and no way to get another ([rule 6](https://uxreference.com/forms/one-time-code#rule-6)).

## Still open

- No controlled test of one field against split boxes, of automatic submit, or of resend and expiry wording was found.
- How long a code should stay valid: GOV.UK uses 15 minutes; no evidence.

## Related problems

- [Autofill and identifying input purpose](https://uxreference.com/forms/autofill): Mark each field with what it is for, and never block autofill, pasting or password managers.
- [Log in](https://uxreference.com/accounts/log-in): Never block paste or password managers, and slow repeated attempts instead of locking people out.
- [Time limits](https://uxreference.com/accessibility/time-limits): Avoid time limits. Where one is needed, warn before it ends and let people extend it.

## Sources

- [Understanding SC 3.3.8: Accessible Authentication (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/accessible-authentication-minimum.html). W3C WAI, 2023, normative standard, informative Understanding document.
- [Understanding SC 3.2.2 On Input (Level A)](https://www.w3.org/WAI/WCAG22/Understanding/on-input.html). W3C WAI, n.d., normative standard.
- [One-Time Password Field (Radix Primitives)](https://www.radix-ui.com/primitives/docs/components/one-time-password-field). Radix UI (WorkOS), n.d., component documentation.
- [Confirm a phone number (GOV.UK Design System pattern)](https://design-system.service.gov.uk/patterns/confirm-a-phone-number/). GOV.UK Design System, n.d., design system pattern guidance.
- [SMS OTP form best practices](https://web.dev/articles/sms-otp-form). web.dev (Google), 2020, expert opinion (platform vendor guidance).
- [Best Practices for OTP Input Forms in HTML](https://www.twilio.com/en-us/blog/developers/best-practices/otp-input-forms-html). Alvin Lee, Twilio Blog, 2025, expert opinion (vendor guidance).
- [Simple One-Time Passcode Inputs](https://cloudfour.com/thinks/simple-one-time-passcode-inputs/). Tyler Sticka, Cloud Four, 2025, expert opinion.
- [HTML attribute: autocomplete](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete). MDN Web Docs (Mozilla contributors), n.d., component documentation.
- [A Usability Study of Five Two-Factor Authentication Methods](https://par.nsf.gov/servlets/purl/10110669). Reese, Smith, Dutson, Armknecht, Cameron, Seamons (BYU), SOUPS 2019, 2019, two-week between-subjects study with simulated bank login; separate within-subjects setup lab study.
- [Verify phone numbers on the web with the WebOTP API](https://developer.chrome.com/docs/identity/web-apis/web-otp). Google Chrome developers, 2019, component documentation.
- [Taken Out of Context: Security Risks with Security Code AutoFill in iOS & macOS](https://discovery-pp.ucl.ac.uk/10076464/1/Gutmann_WAY_2019.pdf). Gutmann and Murdoch (WAY 2019 workshop), 2019, expert cognitive walkthrough of iOS 12 and macOS 10.14 betas.

---
From Solved Problems in UX by Athen Pellicci, an evidence-graded reference of web interface problems. CC BY 4.0. https://uxreference.com/
