References

Beginner-friendly references for web development, with live, editable examples.

The HTML inputmode attribute

Global attribute Works on every element All modern browsers
In short

The HTML inputmode attribute hints what kind of data a user will enter so mobile browsers show the most useful on-screen keyboard, such as numeric, tel, email, url, decimal or search. It is a global attribute, most valuable on form fields.

Overview

The inputmode attribute lets you optimize the on-screen keyboard without changing an input's type. For example, a one-time-code field can stay type="text" for validation but use inputmode="numeric" to summon a number pad.

It only affects the virtual keyboard layout; it does not perform validation or change the submitted value. Choose the mode that matches the expected characters, and combine it with enterkeyhint for the smoothest mobile experience.

Values

Value
none | text | decimal | numeric | tel | search | email | url

Example

Live example
<input inputmode="numeric" placeholder="Enter a numeric code" style="padding:8px; width:100%;">

Best practices

  • There is no number keyword for inputmode. Write numeric for digits or decimal for fractions, because inputmode="number" is invalid and leaves the browser to choose its default keyboard.
  • Avoid numeric and decimal for values that can be negative, such as a temperature offset, because devices may or may not show a minus key on those keyboards.
  • Pick tel for phone numbers and numeric for PINs. The tel keypad should include * and # as well as digits, while numeric is only required to offer the digits 0 to 9.
  • An editor that draws its own on-screen keypad, such as a calculator, is the place for inputmode="none", because the browser should then show no virtual keyboard at all.
  • On a custom editor built with contenteditable, set the mode on the editing host itself, since there is no type attribute there to choose a keyboard.

Frequently asked questions

What does the inputmode attribute do?
Hints the type of virtual keyboard to display for an editable field.
Is inputmode guaranteed to work?
No. It is a hint to on-screen keyboards; a browser may show a different layout or ignore it, and physical keyboards are unaffected.
What is the difference between inputmode and the input type?
The type attribute sets what the value means and how it is validated; inputmode only suggests which on-screen keyboard layout to show.
Does inputmode decimal show a period or a comma?
It depends on the locale, since inputmode decimal should offer the user's own decimal separator. That is typically a period or a comma, so accept both when your code parses the number.