inputmode

Controls which virtual keyboard appears on mobile devices. Critical for fields where the input type doesn't match the keyboard you need.

Overview

The inputmode attribute controls which virtual keyboard appears on mobile devices. It is essential for fields where the type attribute doesn't match the keyboard you want.

The key distinction: type controls validation and behavior (spinners, step arrows, format enforcement), while inputmode controls only the keyboard. You can combine them independently.

Applies to: <input>, <textarea>, and any element with contenteditable

Values

ValueKeyboardUse When
textStandard text keyboardDefault. General text input.
numericNumber keys only (0-9)PINs, ZIP codes, OTPs, credit card numbers — numeric data that isn't a "number" you'd increment.
decimalNumbers with a decimal point keyPrices, measurements, percentages — numbers that may contain a decimal.
telTelephone keypad (0-9, *, #, +)Phone numbers. Similar to numeric but includes phone-specific characters.
emailText keyboard with @ and . easily accessibleEmail addresses. Usually paired with type="email".
urlText keyboard with / and . easily accessibleURLs. Usually paired with type="url".
searchText keyboard with a search/submit keySearch fields. Pairs well with type="search".
noneNo virtual keyboardCustom input UIs (datepickers, color pickers) where you provide your own input mechanism.

inputmode vs type

This is the most important concept to understand. Consider a PIN field:

  • type="number" gives you a numeric keyboard but also adds spinner arrows, allows scientific notation (1e5), and strips leading zeros.
  • type="text" inputmode="numeric" gives you the same numeric keyboard with none of those side effects.

Use type="number" when the value is a quantity that can be incremented (age, item count). Use type="text" inputmode="numeric" when the value is a code or identifier that happens to be digits (PIN, ZIP, credit card number).

Practical Examples

PIN Entry

A 4-digit PIN needs a numeric keyboard but should preserve leading zeros and avoid spinner arrows.

Price Input

Prices need a decimal point but shouldn't have spinner arrows or allow scientific notation.

ZIP Code

US ZIP codes are five digits. Leading zeros matter (01234), so type="number" would break them.

Search Field

The search value ensures the virtual keyboard shows a search action key.

Contenteditable Element

The inputmode attribute also works on contenteditable elements, giving you keyboard control outside of form fields.

Suppressing the Keyboard

Use inputmode="none" when your UI provides its own input mechanism. The field can still receive focus and programmatic input, but the virtual keyboard will not appear.

Common use cases include custom datepickers, emoji pickers, or calculator UIs where tapping buttons fills the field.

Browser Support

The inputmode attribute is supported in all modern browsers. On desktop, it has no visible effect since there is no virtual keyboard — it is purely a mobile optimization. This means you can add it to any field without affecting the desktop experience.

See Also