# 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.

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

## The answer

Accept the separators people type and clean them up yourself, and show the expected shape outside the field.

- **Moderate.** Accept the separators people type, such as spaces in a card number, and remove them yourself. (https://uxreference.com/forms/input-masks#rule-1)
- **Moderate.** Show the expected format in text outside the field. (https://uxreference.com/forms/input-masks#rule-3)

## The problem

Reformatting or restricting what someone types can prevent format errors, and can also fight the person typing.

## 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. Moderate

Accept the separators people naturally type, such as spaces in a card number, and remove them yourself.

- Applies when: Always.
- Based on: Practitioner research
- Principle: Prevent errors

Why: 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.

Sources: [The credit card number field must allow and auto-format spaces](https://baymard.com/blog/credit-card-field-auto-format-spaces); [GOV.UK Design System, Ask users for phone numbers](https://design-system.service.gov.uk/patterns/telephone-numbers/); [Improving AutoFill experiences for your forms (Safari developer documentation)](https://developer.apple.com/documentation/safari-developer-tools/autofill.md); [Input masking for restricted form fields (phone, date, card)](https://baymard.com/blog/input-masking-form-field)

Link: https://uxreference.com/forms/input-masks#rule-1

#### Rule 2. Moderate

Ask for a suitable on-screen keyboard separately from any restriction on what can be typed. A keyboard hint must not block other characters.

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

Why: 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.

Sources: [HTML Living Standard, 6.8.9 The inputmode attribute](https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute); [Why the GOV.UK Design System team changed the input type for numbers](https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/); [NumberField (React Aria component docs)](https://react-aria.adobe.com/NumberField)

Link: https://uxreference.com/forms/input-masks#rule-2

#### Rule 3. Moderate

Show the expected shape of the value in text outside the field.

- Applies when: The system accepts only one format.
- Based on: Research
- Depends on: How strict the format is
- Principle: Prevent errors

Why: 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.

Sources: [Designing input fields for non-narrative open-ended responses in web surveys](https://pmc.ncbi.nlm.nih.gov/articles/PMC3570266); [Enhancing online forms: use format specifications for fields with format restrictions to help respondents](https://doc.rero.ch/record/301906/files/iwc23-0033.pdf)

Link: https://uxreference.com/forms/input-masks#rule-3

#### Rule 4. Weak

If you format as the person types, never block or drop characters, keep paste, deletion and editing in the middle working, and prefer formatting when they leave the field.

- Applies when: Formatting is applied to what is typed.
- Based on: Convention
- Principle: Keep people in control

Why: 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.

Sources: [USWDS input mask component](https://designsystem.digital.gov/components/input-mask/); [Masked field (CMS Design System text field)](https://design.cms.gov/components/text-field/masked-field); [NumberField (React Aria component docs)](https://react-aria.adobe.com/NumberField); [Census Bureau experiment: phone format (benefit messages study)](https://census.gov/content/dam/Census/library/working-papers/2017/adrm/rsm2017-02.pdf); [Politespace, an unobtrusive alternative to input masks](https://www.filamentgroup.com/lab/politespace)

Link: https://uxreference.com/forms/input-masks#rule-4

#### Rule 5. Unsettled

Whether formatting input as it is typed helps people is unsettled.

Until the evidence settles, use this default: Do not format as the person types. Accept any reasonable format and clean it up after entry.

- Applies when: Always.
- Based on: Practitioner research
- Principle: Prevent errors

Why: 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.

Sources: [Input masking for restricted form fields (phone, date, card)](https://baymard.com/blog/input-masking-form-field); [The credit card number field must allow and auto-format spaces](https://baymard.com/blog/credit-card-field-auto-format-spaces); [GOV.UK Design System, Ask users for phone numbers](https://design-system.service.gov.uk/patterns/telephone-numbers/); [USWDS input mask component](https://designsystem.digital.gov/components/input-mask/); [Census Bureau experiment: phone format (benefit messages study)](https://census.gov/content/dam/Census/library/working-papers/2017/adrm/rsm2017-02.pdf); [Why masking is not accessible](https://dev.to/dgreene1/why-masking-is-not-accessible-i3c)

Link: https://uxreference.com/forms/input-masks#rule-5

## Accessibility requirements

- WCAG 2.2, 3.3.1 (A) and 4.1.3 (AA) apply to any message a mask produces. (https://www.w3.org/WAI/WCAG22/Understanding/error-identification.html)
- 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.

## Common mistakes

- A mask that rejects a pasted value because it contains spaces or punctuation.
- A mask that moves the cursor or rewrites the value while the person is editing the middle of it.

## Still open

- No controlled study, review or published online experiment of masks against free entry was found for card numbers, ZIP codes or currency.
- The single phone experiment was inconclusive because the mask itself was faulty.
- Whether formatting on leaving the field avoids the problems of formatting on each keystroke: untested.

## Related problems

- [Phone number input](https://uxreference.com/forms/phone): Ask only if you will use it, take it in one field, and accept the number however it is written.
- [Entering a date](https://uxreference.com/forms/date-input): Let people type a date they know. Show a calendar only when they are choosing one, and still let them type.
- [Payment card](https://uxreference.com/forms/payment-card): Take the card number in one field, with or without spaces, and work out the card type yourself.
- [Stating format requirements](https://uxreference.com/forms/format-requirements): Remove format rules where you can. Where you cannot, state them before people type.
- [Input modes and on-screen keyboards](https://uxreference.com/mobile/input-modes): Show the keyboard that matches each field, but accept the same input whatever keyboard appears.

## Sources

- [The credit card number field must allow and auto-format spaces](https://baymard.com/blog/credit-card-field-auto-format-spaces). Lars Soderlund, Baymard Institute, 2025, large-scale qualitative checkout testing plus benchmark (existing record in sources.yaml).
- [GOV.UK Design System, Ask users for phone numbers](https://design-system.service.gov.uk/patterns/telephone-numbers/). GOV.UK Design System, n.d..
- [Improving AutoFill experiences for your forms (Safari developer documentation)](https://developer.apple.com/documentation/safari-developer-tools/autofill.md). Apple, 2026, component documentation (reused from the form.autofill gaps record).
- [Input masking for restricted form fields (phone, date, card)](https://baymard.com/blog/input-masking-form-field). Edward Scott, Baymard Institute, 2017.
- [HTML Living Standard, 6.8.9 The inputmode attribute](https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute). WHATWG, n.d., normative standard.
- [Why the GOV.UK Design System team changed the input type for numbers](https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/). GOV.UK Design System team (Technology in government blog), 2020, team write-up of browser and assistive technology testing.
- [NumberField (React Aria component docs)](https://react-aria.adobe.com/NumberField). Adobe, React Aria, n.d., component documentation.
- [Designing input fields for non-narrative open-ended responses in web surveys](https://pmc.ncbi.nlm.nih.gov/articles/PMC3570266). Couper, Kennedy, Conrad, Tourangeau, 2011, four experiments embedded in two opt-in panel web surveys (2007, 2008).
- [Enhancing online forms: use format specifications for fields with format restrictions to help respondents](https://doc.rero.ch/record/301906/files/iwc23-0033.pdf). Bargas-Avila, Orsini, Piosczyk, Urwyler, Opwis, 2011, between-subjects online experiment, four format-hint conditions, 15-field form.
- [USWDS input mask component](https://designsystem.digital.gov/components/input-mask/). U.S. Web Design System, GSA, n.d..
- [Masked field (CMS Design System text field)](https://design.cms.gov/components/text-field/masked-field). CMS Design System, U.S. Centers for Medicare and Medicaid Services, n.d., component documentation with accessibility test checklist.
- [Census Bureau experiment: phone format (benefit messages study)](https://census.gov/content/dam/Census/library/working-papers/2017/adrm/rsm2017-02.pdf). Nichols et al., US Census Bureau, 2017.
- [Politespace, an unobtrusive alternative to input masks](https://www.filamentgroup.com/lab/politespace). Todd Parker or Zach (Filament Group; byline as shown on page), Filament Group, 2014, expert opinion with a code library.
- [Why masking is not accessible](https://dev.to/dgreene1/why-masking-is-not-accessible-i3c). Dan Greene (dev.to), 2023, expert opinion with informal library testing.

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