Full Byte Developer.
PHONEKEYS

Right phone keyboard for every form field

Use type and inputmode to show the right virtual keyboard: numeric for codes, tel for phones, email for addresses.

Published here · 3 sources

The wrong keyboard makes mobile forms frustrating. Here is which combination of type and inputmode to use for each field.

Email address

Use type="email". The keyboard shows @ and common domain suffixes [3]:

html
<input type="email" name="email" autocomplete="email">

Phone number

Use type="tel". The keyboard shows a phone dialpad [3]:

html
<input type="tel" name="phone" autocomplete="tel">

Credit card number

Use type="text" with inputmode="numeric". This shows a number pad without the spinner buttons that type="number" adds [1] [2]:

html
<input type="text" inputmode="numeric" pattern="[0-9 ]{13,19}" autocomplete="cc-number">

ZIP or postal code

Same pattern: type="text" with inputmode="numeric" [2]:

html
<input type="text" inputmode="numeric" pattern="[0-9]{5}" autocomplete="postal-code">

One-time code (OTP)

Use inputmode="numeric" and autocomplete="one-time-code" so the device offers to autofill from SMS:

html
<input type="text" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9]{6}">

Decimal amount (price, weight)

Use inputmode="decimal". The keyboard includes a decimal separator [1]:

html
<input type="text" inputmode="decimal" pattern="[0-9]*\.?[0-9]*">

URL

Use type="url". The keyboard shows / and .com shortcuts [3]:

html
<input type="url" name="website" autocomplete="url">

When to use type=number

Only for values that make sense to increment: quantity selectors, age inputs, or numeric settings. The spinner buttons are part of the UI [2].

html
<input type="number" name="quantity" min="1" max="99">

For codes, IDs, and formatted numbers, use inputmode="numeric" instead.

Send this to the friend whose signup form shows a letter keyboard for a phone number.

Keep this guide

By Full Byte Developer

Filed under Dev tools

Questions about this guide

What is the difference between type and inputmode?

type changes both the keyboard and the validation. inputmode only changes the keyboard, leaving validation to you.

Should I use type=number for ZIP codes?

No. type=number adds spinner buttons and allows scientific notation. Use type=text with inputmode=numeric instead.

Sources

  1. MDN: inputmode attributedeveloper.mozilla.org
  2. MDN: HTML5 input typesdeveloper.mozilla.org

Next in this stack