type="number" vs inputmode="numeric"
A number field is for amounts you count up and down. Everything else made of digits is text.
Last updated November 30, 2026 · Keyboards checked on real phones: iPhone (iOS 17 and 18), Galaxy S24 and S25, Pixel 9, Motorola Edge 50 Fusion
The difference in one line: type="number" changes how the browser stores and checks the value, while inputmode="numeric" only changes the keyboard.
What goes wrong with type="number"
- Leading zeros vanish. ZIP code 02134 and account number 0042 lose their zeros when the value is read as a number.
- Scrolling changes the value. On a computer, scrolling the page with the pointer over a focused number field can step its value up or down.
- "e" is allowed. 1e5 is a valid number, so the letter e passes while other letters are thrown away.
- Long values round. A 16-digit card number is too long to be stored exactly as a JavaScript number.
- Invalid input turns into nothing. If someone types something that is not a number, the field's value is an empty string, so your code cannot even show them what went wrong.
The GOV.UK Design System team moved away from <input type="number"> to <input type="text" inputmode="numeric" pattern="[0-9]*"> for these reasons. Their notes also say iOS shows the full keyboard for type="number", and that pattern="[0-9]*" was what triggered the number pad there.
The pattern to copy
<label for="zip">ZIP code</label>
<input id="zip" name="zip" type="text"
inputmode="numeric" pattern="[0-9]*"
autocomplete="postal-code" maxlength="5">
inputmode opens the number pad on iOS 13 and later and on Android. pattern covers older iPhones and gives you free validation. autocomplete lets the phone fill the value in.
When type="number" is right
Use it for real quantities: how many tickets, a person's age, the number of rooms. These are values where a step of one makes sense and a spinner or arrow keys help. Even then, think about the iPhone keyboard. type="number" opens the full keyboard on its 123 page, which has a minus key. If you add inputmode="numeric" to it you get the bigger number pad, but you lose the minus key and the decimal point.
Decimals
For prices or weights use inputmode="decimal". It adds a point to the pad, or a comma in regions that write decimals with one. Accept both when you read the value. If the value can be negative, do not use either pad on iPhone: neither has a minus key.
Quick decision table
| Value | Use |
|---|---|
| Quantity, age, count | type="number" |
| ZIP code (5 digits), OTP, card number, CVC | type="text" inputmode="numeric" |
| Price, weight, percentage | type="text" inputmode="decimal" |
| Can be negative | type="text" (standard keyboard) |
| Phone number | type="tel" |
| ZIP+4, UK or Canadian postcode | type="text" |
What each phone actually shows
We tapped the same three fields on real phones in Chrome and Safari. The keyboards differ more than most people expect:
| Markup | iPhone | Galaxy (Samsung Keyboard) | Pixel / Motorola (Gboard) |
|---|---|---|---|
type="number" | Full keyboard on the 123 page (has minus) | 0–9 . , — no minus | 0–9 - , . and space |
inputmode="numeric" | Number pad: 0–9 only | 0–9 plus a ".-" key and , | 0–9 - , . and space |
inputmode="decimal" | 0–9 and a point | 0–9 . , — no minus | 0–9 - , . and space |
Two lessons follow. First, a field that only needs digits still has to cope with a stray point, comma, dash or space on Android, so strip them in your code rather than rejecting the value. Second, a minus sign is only reliable on the standard keyboard: the iPhone number pad and the Galaxy decimal pad have none.
A worked example: the vanishing zero
A shop in Boston asks for a ZIP code with <input type="number">. A customer types 02134. The browser stores the number 2134, the shipping-rate lookup finds no such ZIP code, and checkout fails with a vague error. The same thing happens to card numbers in a different way: JavaScript numbers are exact only up to 9,007,199,254,740,991, so the 16-digit value 9999999999999999 becomes 10000000000000000 when read as a number. Keeping these fields as text avoids both bugs.
Changing an existing field safely
- Change
type="number"totype="text"and addinputmode="numeric"(ordecimal). - Replace
min,maxandstep, which only work on number fields, with apatternor your own check. - In your code, read
input.valueas a string and remove spaces, commas and dashes before checking it. - Test on a real iPhone and a real Android phone, or paste the field into the checker and switch between iPhone, Galaxy and Pixel / Motorola.
Frequently asked questions
Does inputmode="numeric" validate the value?
No. It only chooses the keyboard. Add pattern="[0-9]*" or check the value in your code.
Why not just use type="tel" for every digit field?
The phone pad works, but screen readers announce the field as a phone number, and the + * # key is confusing on a ZIP or card field.
Why does my number field accept "e"?
Because 1e5 is a valid number in HTML. If the value is a code or an ID, use type="text" inputmode="numeric" instead.
Found a mistake or want a check added? Write to contact (at) mobileformcheck.com.