HTML global attributeGlobal attributes

inputmode

Hints which on-screen keyboard to show: digits, digits with a decimal separator, a phone pad, an email keyboard, or none.

Applies to
Text fields <input>, <textarea> and elements with contenteditable
On this page

Example

#
HTML
<style>
  .field { display: grid; gap: 4px; max-width: 300px; margin-bottom: 12px; }
  .field small { color: #a3a3a3; }
</style>

<form>
  <label class="field">Login or email
    <input type="text" name="login" inputmode="email" autocomplete="username">
    <small>A keyboard with the @ sign, with no address format check.</small>
  </label>
  <label class="field">Code from a text message
    <input type="text" name="code" inputmode="numeric" autocomplete="one-time-code">
    <small>Digits only.</small>
  </label>
  <label class="field">Payment amount in $
    <input type="text" name="amount" inputmode="decimal">
    <small>Digits and a decimal separator, for example a period.</small>
  </label>
</form>
Preview

You will only see the keyboard type on a phone or tablet. On a computer all three fields look and work the same way.

Definition and usage

#

The inputmode attribute tells a phone or tablet what kind of on-screen keyboard to bring up when the user taps the field. A code from a text message needs only digits, an amount needs digits with a decimal separator, and an email address needs a keyboard with the @ sign. A well-chosen keyboard saves switching and typos.

Unlike the type attribute of an <input> field, inputmode changes nothing except the keyboard: it does not validate, does not add arrows or a calendar, and does not affect what gets sent to the server. That is why it suits values that consist of digits but are not numbers to calculate with, like PINs, codes from text messages, or card numbers. For these, choose type="text" with inputmode="numeric", not type="number".

Fields with type="email", type="tel" and type="url" pick the right keyboard themselves, so inputmode is mostly useful in ordinary text fields and in elements with contenteditable. On a computer with a physical keyboard the attribute changes nothing.

Syntax

#
Syntax
<element inputmode="none | text | decimal | numeric | tel | search | email | url">…</element>

Values

#
  • none

    No on-screen keyboard. Only when the page has its own keyboard, for example a PIN pad in a kiosk.
  • text

    A regular text keyboard. The default setting.
  • decimal

    Digits and a decimal separator, a comma or a period depending on the language settings. For amounts and measurements.
  • numeric

    Digits only. For PINs, codes from text messages and card numbers.
  • tel

    A phone keypad with digits and the +, * and # characters.
  • search

    A keyboard for searching. The Enter key often turns into “Search”.
  • email

    A keyboard with the @ sign and a period. It does not validate the address.
  • url

    A keyboard for web addresses, usually with the / and . keys.

Browser support

#

Widely available · since 2021

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Combine inputmode with autocomplete. The pair inputmode="numeric" and autocomplete="one-time-code" lets you enter a code from a text message with one tap on the suggestion above the keyboard.
  • The keyboard is only a convenience. If a field accepts digits only, enforce that with the pattern attribute or in a script, because the user can paste any text.

Related entries

#

Spotted a mistake or missing an example? Write to us.