type="number" vs inputmode="numeric"

A number field is for amounts you count up and down. Everything else made of digits is text.

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"

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.

Found a mistake or want a check added? Write to contact (at) mobileformcheck.com.