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"

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

ValueUse
Quantity, age, counttype="number"
ZIP code (5 digits), OTP, card number, CVCtype="text" inputmode="numeric"
Price, weight, percentagetype="text" inputmode="decimal"
Can be negativetype="text" (standard keyboard)
Phone numbertype="tel"
ZIP+4, UK or Canadian postcodetype="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:

MarkupiPhoneGalaxy (Samsung Keyboard)Pixel / Motorola (Gboard)
type="number"Full keyboard on the 123 page (has minus)0–9 . , — no minus0–9 - , . and space
inputmode="numeric"Number pad: 0–9 only0–9 plus a ".-" key and ,0–9 - , . and space
inputmode="decimal"0–9 and a point0–9 . , — no minus0–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

  1. Change type="number" to type="text" and add inputmode="numeric" (or decimal).
  2. Replace min, max and step, which only work on number fields, with a pattern or your own check.
  3. In your code, read input.value as a string and remove spaces, commas and dashes before checking it.
  4. 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.