Inputmode Explained: The Key to User-friendly Mobile Forms

[object Object]
Sara MitevskaJune 18th, 2024
June 18th, 2024 3 minutes read
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8IqXm6pSuYwgEpt_ghjHWWvPNIlqmWJ1bRy6MExvIz2K2EKXCwP04CTmaGDcaPod0PEK6_ZlYicCkAYRgYVXjR3FCeH1MVjBeBht10fpTyU5IuLbaVjDHa92Fubs9c_YyKbKUnGGj1TjPlATvFm0kJuZdghXV7KW-c-xP_dFJjXjKs6Oy8p5t65pd9a1i/w640-h640/mobile-chat-illustration-Photoroom%20(1).webp
input mode explained

If you’ve ever struggled with typing the right information into a web form on your phone, you’ll appreciate how much a simple change like inputmode can improve the experience. But what exactly is inputmode, and how can you use it to make your forms more user-friendly?

What is Inputmode?

inputmode is an HTML attribute that tells the browser which type of virtual keyboard to display when a user focuses on an input field. By showing the appropriate keyboard, it makes typing faster and reduces errors. It’s especially useful on mobile devices where keyboard layouts can change based on the type of data you need to enter. inputmode is primarily used on <input /> elements but it can also be applied on any other HTML element in contenteditable mode.

How Does inputmode Work?

When you add the inputmode attribute to an input field, you specify the type of data you expect users to enter. The browser then displays the most relevant keyboard. Here are all the values that inputmode can have:

  • text: Default keyboard for text input.
  • numeric: Number pad for numerical input.
  • decimal: Number pad with a decimal point.
  • tel: Telephone keypad for entering phone numbers. It includes the digits 0–9, the asterisk (*), and the pound (#) key
  • email: Keyboard optimised for email addresses. Includes @ and .com buttons.
  • url: Keyboard optimised for URLs (includes / and . buttons).
  • search: Keyboard optimised for search input. For example, the return/submit key may be labeled "Search", along with possible other optimisations.
  • none: No virtual keyboard. For when the page implements its own keyboard input control.

Examples

Let’s look at some examples of how to use inputmode in your forms:

Numeric

  <label for="amount">Amount:</label>
  <input type="text" id="amount" inputmode="numeric" placeholder="Enter amount"/>

The keypad on mobile will look something like this. (This can vary depending on the mobile OS, this example shows how it looks on iOS)

numeric input mode

Tel


  <label for="phone">Phone:</label>
  <input type="text" id="phone" inputmode="tel" placeholder="Enter your phone number"/>

The keypad on mobile will look something like this:

phone input mode

Email


  <label for="email">Email:</label>
  <input type="text" id="email" inputmode="email" placeholder="Enter your email"/>

The keypad on mobile will look something like this:

email input mode

Url

Here is an example of using a <div> element in editable mode as a field:

  <label for="url">Url:</label>
  <div contenteditable="true" id="url" inputmode="url" placeholder="Enter a url"/>

The keypad on mobile will look something like this:

url input mode

When to Use inputmode

If you're using the HTML <input> element with a specific type attribute (other then 'text'), the keypad will be automatically shown depending on the type. However, if you need a more custom input or other editable element then you might need to use the proper inputmode. Using the correct inputmode will allow you to optimise the input experience for users, especially on mobile devices. Here are some situations where it can be helpful:

  • Numeric:
    • Credit Card Numbers
    • Security Codes (e.g., CVV for credit cards)
    • Bank Account Numbers
    • Social Security Numbers
    • Employee or Student ID Numbers
    • Membership Numbers
    • Serial Numbers for Products
  • Decimal:
    • Prices
    • Weights
    • Product Dimensions
    • Coordinates (e.g., latitude and longitude)
    • Financial Data (e.g., interest rates)
    • Measurement Units (e.g., height, length)
  • Tel:
    • Phone Numbers
    • Fax Numbers
  • Email:
    • Email Addresses
    • Contact Forms
  • URL:
    • Website URLs
    • API Endpoints
  • Search:
    • Search Fields on Websites
    • Search Boxes in Applications
  • Text:
    • Names
    • Addresses
    • General Text Inputs

By making these small adjustments, you can significantly improve the user experience on your web forms, making them quicker and easier to fill out.

Browser support

inputmode attribute is supported by most major browsers as shown on the table below.

https://caniuse.com/input-inputmode




Read next