Skip to content
easeweb
Search topics

One-time code boxes that won't take a pasted code

A sign-in step asks for a six-digit code in six one-character boxes, so pasting the code from a text message puts in only its first digit.

WCAG 2.2
SC 3.3.8AA· new in 2.2
Required by
Not required by Section 508 or EN 301 549
Broken <input inputmode="numeric" maxlength="1">
The accessibility problem illustrated: Cognitive:Why did only the 4 go in?
01

The problem

People who can't easily hold six digits in mind, or type them one at a time, have to read the code from one screen and type it into another

02

Try it

Choose Copy code on the phone, then paste the code into the sign-in page with Ctrl+V or the context menu

If copying is blocked here, select the code in the message and copy it yourself.

Broken Can you fix this?

BrokenSix boxes that take one character each

Messages

Your Larkspur code is 481902

Check it’s you

Enter the 6-digit code we sent to your phone

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Let a pasted code go in whole

Before
BrokenSix boxes that take one character each
<p id="code-label">Enter the 6-digit code we sent to your phone</p><div class="code-boxes" role="group" aria-labelledby="code-label">  <input inputmode="numeric" maxlength="1" aria-label="Digit 1">  <input inputmode="numeric" maxlength="1" aria-label="Digit 2">  <input inputmode="numeric" maxlength="1" aria-label="Digit 3">  <input inputmode="numeric" maxlength="1" aria-label="Digit 4">  <input inputmode="numeric" maxlength="1" aria-label="Digit 5">  <input inputmode="numeric" maxlength="1" aria-label="Digit 6"></div>
What is wrong3 points
  • A pasted code puts in only its first digit. maxlength="1" makes the browser cut a pasted code, an autofilled one or a dictated one down to its first character before the script's input handler sees it.
  • The other five boxes stay empty: nothing spreads the rest of the code across them.
  • So the code can only be typed in, one digit at a time.
After

One field that takes the whole code

<label for="code">Security code</label><p id="code-hint">We sent a 6-digit code to your phone. It works for 15 minutes.</p><input id="code" name="code" type="text" inputmode="numeric"  autocomplete="one-time-code" spellcheck="false" aria-describedby="code-hint"><button type="submit">Continue</button>
How it is fixed4 steps
  1. Replace the six boxes with one labelled text field. The code goes in the way any text does: pasted with the keyboard or the context menu, dictated, or filled in by the browser.
  2. Add autocomplete="one-time-code", which tells the browser what the field is for, so a browser that supports it, such as Safari, can offer the code from a new message above the keyboard.
  3. Add inputmode="numeric", which brings up the number keypad on a phone.
  4. Leave out maxlength, so a code pasted as "481 902" still goes in; the server takes out spaces and hyphens before it checks the code; see convert what people type instead of rejecting it.

This fixes the Before and passes 3.3.8. No script is needed for any of this.

Why this fix: Use native HTML first

04

Design ideas

A code field can take any look, as long as a paste goes in

Three ways to ask for the same code. Copy 481902 from this line and paste it into each with Ctrl+V, the context menu or the Paste button, then try typing it: two take the whole code at once, and one refuses the paste.

In the design file

  • Draw a single field for the whole code, with its label, a hint such as “It works for 15 minutes”, and the button that sends it.
  • To space the digits apart, use letter spacing inside one field, not six separate boxes, and note that it is one field.
  • Add a “Send a new code” button, drawn as a button, for a code that expired or never arrived.
  • Draw the field with focus, and with all six digits typed in, 481902.

Passes

  • One field drawn as six cells Six soft 40 by 48 pixel cells with #767676 edges, 4.54:1 on white, are drawn behind one field, and the next cell to fill is ringed in #1a1a1a. It keeps the look of six boxes with no script to spread a code: a paste goes in whole, “481 902” included.
  • A field with its own Paste button A Paste pill at the end of the field, #1a1a1a on #f6f6f7 at 16.11:1, puts the copied code in with one press, for anyone who finds a long press and a Paste menu fiddly on a phone. The field still takes Ctrl+V and the code a phone offers; the browser may ask once before the page can read what was copied.

Fails

  • Pasting is turned off for your security.
    Sleek field that refuses a pasteWCAG 3.3.8 One underlined field with a shield, and under it “Pasting is turned off for your security”: a paste or a drop is cancelled, so the only way in is to read six digits off the message and type them back. One field is no help when the paste is the thing that is blocked.
05

Verify the fix

5 checks, no mouse.

Test with: Keyboard, Screen reader, Touch, Autofill, Speech input

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the sign-in flow or its code component changes.

How screen readers handle aria-describedby

Limits

This is a starting pattern, not a guarantee for every sign-in. The example is a code sent by text message; codes from an authenticator app or an email need the same paste test. The criterion doesn't ask a site to send codes by any particular route, and whether the code reaches the device people sign in on is outside it. The rest of signing in, such as a password field that refuses paste or a puzzle to solve, falls under the same criterion. Boxes that a keyboard can't go back through to correct a digit are covered in code boxes where a keyboard can't correct a wrong digit. Test the whole sign-in with disabled people and the assistive technology they use.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service