Input masks and formatting as you type
Fields that reformat or block what people type can prevent mistakes, and can also fight them as they type.
The answer
Accept the separators people type and clean them up yourself, and show the expected shape outside the field. As strong as the weakest rule behind it: moderate.
-
Accept the separators people type, such as spaces in a card number, and remove them yourself.
Baymard reports card-number errors and abandonment where spaces are rejected, without participant numbers; GOV.UK and Apple say the same for phone numbers. Rated 3.
- Applies when
- Always.
- Based on
- Practitioner research
- Principle
- Prevent errors
- Common mistake
- A mask that rejects a pasted value because it contains spaces or punctuation.
- User researchUser research: The credit card number field must allow and auto-format spacesLars Soderlund, 2025
- GuidanceGuidance: GOV.UK Design System, Ask users for phone numbersGOV.UK Design System
- Guidance: Improving AutoFill experiences for your forms (Safari developer documentation)Apple, 2026
- Guidance: Input masking for restricted form fields (phone, date, card)Edward Scott, 2017
-
Show the expected format in text outside the field.
A large survey experiment found a visible template raised well-formed currency answers from about 82% to 96%, and a controlled study found stated formats cut errors. Neither tested a mask. Rated 3.
- Applies when
- The system accepts only one format.
- Based on
- Research
- Depends on
- How strict the format is
- Principle
- Prevent errors
- ExperimentsExperiment: Designing input fields for non-narrative open-ended responses in web surveysCouper, 2011
- Experiment: Enhancing online forms: use format specifications for fields with format restrictions to help respondentsBargas-Avila, 2011
The other rules
-
Choosing an on-screen keyboard must not block characters people type.
The HTML standard defines the keyboard hint as a hint only; GOV.UK moved away from number-type fields after they silently dropped characters. Rated 3.
- Applies when
- Always.
- Based on
- Convention
- Principle
- Let practiced people go faster
- StandardStandard: HTML Living Standard, 6.8.9 The inputmode attributeWHATWG
- GuidanceGuidance: Why the GOV.UK Design System team changed the input type for numbersGOV.UK Design System team, 2020
- Guidance: NumberField (React Aria component docs)Adobe
-
If you format as people type, never block or drop characters, keep paste and editing working, and prefer formatting when they leave the field.
USWDS allows masks on these conditions; CMS and React Aria format on leaving the field; the one experiment used a mask that misfired in about 8% of entries. No comparison of the options. Rated 2.
- Applies when
- Formatting is applied to what is typed.
- Based on
- Convention
- Principle
- Keep people in control
- Common mistake
- A mask that moves the cursor or rewrites the value while the person is editing the middle of it.
- GuidanceGuidance: USWDS input mask componentU.S. Web Design System
- Guidance: Masked field (CMS Design System text field)CMS Design System
- Guidance: NumberField (React Aria component docs)Adobe
- Guidance: Census Bureau experiment: phone format (benefit messages study)Nichols et al., 2017
- Guidance: Politespace, an unobtrusive alternative to input masksTodd Parker or Zach, 2014
-
Don’t format as people type. Accept any reasonable format and clean it up afterwards.
Baymard recommends it for fixed formats; GOV.UK advises against it; USWDS ships a mask that fails some of its own accessibility tests; the only controlled test found no benefit. Rated 1.
- Applies when
- Always.
- Based on
- Practitioner research
- Principle
- Prevent errors
- User researchUser research: The credit card number field must allow and auto-format spacesLars Soderlund, 2025
- GuidanceGuidance: Input masking for restricted form fields (phone, date, card)Edward Scott, 2017
- Guidance: GOV.UK Design System, Ask users for phone numbersGOV.UK Design System
- Guidance: USWDS input mask componentU.S. Web Design System
- Guidance: Census Bureau experiment: phone format (benefit messages study)Nichols et al., 2017
- Guidance: Why masking is not accessibleDan Greene, 2023
Accessibility
- WCAG 2.2 · 3.3.1WCAG 2.2, 3.3.1 (A) and 4.1.3 (AA) apply to any message a mask produces.
- USWDS reports that its mask does not pass all of its WCAG 2.1 AA tests; CMS says its screen reader checks are incomplete. Two essays report screen readers announcing masked values wrongly, each from a single case.
- No study of masked inputs with screen reader users was found.
Open questions
- OpenNo controlled study, review or published online experiment of masks against free entry was found for card numbers, ZIP codes or currency.
- OpenThe single phone experiment was inconclusive because the mask itself was faulty.
- OpenWhether formatting on leaving the field avoids the problems of formatting on each keystroke: untested.
Sources
- ExperimentsExperiment: Designing input fields for non-narrative open-ended responses in web surveysCouper, 2011
- Experiment: Enhancing online forms: use format specifications for fields with format restrictions to help respondentsBargas-Avila, 2011
- User researchUser research: The credit card number field must allow and auto-format spacesLars Soderlund, 2025
- StandardStandard: HTML Living Standard, 6.8.9 The inputmode attributeWHATWG
- GuidanceGuidance: GOV.UK Design System, Ask users for phone numbersGOV.UK Design System
- Guidance: Improving AutoFill experiences for your forms (Safari developer documentation)Apple, 2026
- Guidance: Input masking for restricted form fields (phone, date, card)Edward Scott, 2017
- Guidance: Why the GOV.UK Design System team changed the input type for numbersGOV.UK Design System team, 2020
- Guidance: NumberField (React Aria component docs)Adobe
- Guidance: USWDS input mask componentU.S. Web Design System
- Guidance: Masked field (CMS Design System text field)CMS Design System
- Guidance: Census Bureau experiment: phone format (benefit messages study)Nichols et al., 2017
- Guidance: Politespace, an unobtrusive alternative to input masksTodd Parker or Zach, 2014
- Guidance: Why masking is not accessibleDan Greene, 2023
Related
- Phone number inputAsk only if you will use it, take it in one field, and accept the number however it is written.Answer: moderate.
- Entering a dateLet people type a date they know. Show a calendar only when they are choosing one, and still let them type.Answer: moderate.
- Payment cardTake the card number in one field, with or without spaces, and work out the card type yourself.Answer: moderate.
- Stating format requirementsRemove format rules where you can. Where you cannot, state them before people type.Answer: moderate.
- Input modes and on-screen keyboardsShow the keyboard that matches each field, but accept the same input whatever keyboard appears.Answer: moderate.