Forms
Input auto-formatting
Automatically format inputs like phone numbers and credit cards as users type
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
Published on Dec 8, 2025
Explore more examples
Forms
Dropdown usability
Replace long dropdowns with searchable select components for better usability
formselectinputaccessibility
View example
FormsAvoid disabled submit buttons
Keep submit buttons enabled and show clear error messages on submit instead of silently disabling
formbuttonaccessibilitydisabled
View example
FormsVerification code input
Use separate digit inputs for verification codes to improve clarity and mobile experience
inputverificationpasteOTP
View example