Skip to content
easeweb
Search topics

Code boxes where a keyboard can't correct a wrong digit

One-time code boxes move on to the next box when a key comes up, so Shift+Tab is sent straight back and the keyboard can't return to a mistyped digit.

WCAG 2.2
SC 2.1.1A
Required by
Section 508 · EN 301 549 (EU)
Broken box.addEventListener('keyup', …)
The accessibility problem illustrated: Motor:How do I fix the 7?
01

The problem

Keyboard, switch and screen reader users who mistype one digit can't go back to it, so they can't send the right code.

02

Try it

Type 4, 8 and 7, then change the 7 to a 1 using only the keyboard.

Try Backspace, the left arrow and Shift+Tab. The panel shows where each key sent focus, including any box it passed through on the way.

Broken Can you fix this?

BrokenBoxes that move on when a key comes up

Check it’s you

Enter the 6-digit code we sent to your phone

Last key: none yet

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Move on only when a digit goes in, or take the code in one field.

  1. 1Move on to the next box only when a digit goes in, never on every key.
  2. 2Let the keyboard reach any digit already typed, and type over it.
  3. 3Where the design allows, ask for the code in one field.
Before Boxes that move on when a key comes up
<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 name="code-1" inputmode="numeric" maxlength="1" aria-label="Digit 1 of 6">  <input name="code-2" inputmode="numeric" maxlength="1" aria-label="Digit 2 of 6">  <input name="code-3" inputmode="numeric" maxlength="1" aria-label="Digit 3 of 6">  <input name="code-4" inputmode="numeric" maxlength="1" aria-label="Digit 4 of 6">  <input name="code-5" inputmode="numeric" maxlength="1" aria-label="Digit 5 of 6">  <input name="code-6" inputmode="numeric" maxlength="1" aria-label="Digit 6 of 6"></div><button type="submit">Continue</button>
After

One field for the whole code

<label for="code">Security code</label><p id="code-hint">Enter the 6-digit code we sent to your phone.</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>

Why this fix: Use native HTML first

04

Verify the fix

4 checks.

Test with: Keyboard, Screen reader, Mouse

0 of 4 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.

Limits

This is a starting pattern, not a guarantee for every code entry. The example is a sign-in code; a PIN, a gift card number or a booking reference asked for in boxes needs the same test. Pasting the whole code is covered in one-time code boxes that won't take a pasted code. Boxes built from elements that aren't inputs need every key added by script, and a screen reader may not treat them as fields at all; this guide doesn't cover them in code. Test the whole sign-in with the keyboards, switches and screen readers your users rely on.

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