Forms
Auto-format inputs with mobile keyboard
Automatically format structured inputs (credit card, IBAN, phone) with proper spacing and show the appropriate mobile keyboard.
forminputformatmobilekeyboardibancredit-cardaccessibility
Bad example
Good example
Auto-format inputs with mobile keyboard
The Problem
When users enter structured data like credit card numbers, IBANs, or phone numbers, they often struggle with:
- Reading back long strings of numbers without visual breaks
- Accidentally making typos they can't easily spot
- Having to switch keyboards on mobile to enter numbers
The Solution
- Auto-format as they type: Add visual separators (spaces) to make numbers easier to read and verify
- Use
inputmode="numeric": Show the numeric keyboard on mobile devices without the drawbacks oftype="number"
Why not type="number"?
- Adds unwanted spinner arrows
- Doesn't allow spaces or formatting characters
- Inconsistent behavior across browsers
- Scientific notation issues with large numbers
Implementation Tips
- Use
inputmode="numeric"for pure numbers (credit cards, IBAN) - Use
type="tel"for phone numbers (includes +, *, #) - Store the raw value (without spaces) but display formatted
- Handle paste events to clean and format pasted content
- Consider max length based on the format (16 digits for most credit cards, up to 34 for IBAN)
- Use example placeholders: Show the expected format in the placeholder (e.g.,
4242 4242 4242 4242) instead of repeating the label (e.g.,Enter card number). This helps users understand the expected format at a glance.
Accessibility
- The formatted display helps users with cognitive disabilities verify their input
aria-describedbycan link to format hints- Screen readers will read the actual input value
Explore more examples
Forms
Autofocus on Modal input
When a modal opens with a single input, it should be automatically focused
View example
FormsDisable submit button during loading
Prevent double submissions by disabling the button and showing a spinner
View example
FormsVerification code paste support
Allow users to paste verification codes instead of typing digit by digit
View example