HTML - HTML Inputmode and Enterkeyhint Attributes for Mobile Devices
1. Introduction
HTML provides several attributes that help developers improve the user experience of websites, especially on mobile devices. Two useful attributes are inputmode and enterkeyhint. These attributes allow developers to control how the virtual keyboard appears and how its Enter key is displayed when users interact with form fields.
When users access a website through a mobile phone or tablet, they usually enter information using an on-screen keyboard. Depending on the information being entered, such as a phone number, email address, decimal value, or website URL, the keyboard layout can make a significant difference in usability.
The inputmode attribute suggests the appropriate keyboard layout for a particular input field, while the enterkeyhint attribute suggests the label or action displayed on the keyboard's Enter key. Together, these attributes make forms easier and faster to use on mobile devices.
2. Understanding the Inputmode Attribute
The inputmode attribute is an HTML global attribute that provides a hint to the browser about the type of virtual keyboard that should be displayed when a user focuses on an input field or an editable element.
It does not validate the entered information or change the actual data type of the input field. Instead, it helps the browser display a keyboard layout that is suitable for the expected input.
For example, when a user needs to enter a phone number, displaying a numeric keyboard is more convenient than displaying a complete alphabetic keyboard.
Syntax:
<input type="text" inputmode="numeric">
In this example, the inputmode="numeric" attribute suggests that the browser should display a numeric keyboard when the user selects the input field.
3. Different Values of the Inputmode Attribute
The inputmode attribute supports several values that help developers select suitable keyboard layouts.
1. None
The none value indicates that the browser should not display a virtual keyboard automatically when the input field receives focus. It is useful when a website provides its own custom keyboard or another input mechanism.
Example:
<input type="text" inputmode="none">
This value can be useful for applications that use custom on-screen number pads or specialized input interfaces.
2. Text
The text value suggests a standard text keyboard that allows users to enter letters and other characters.
Example:
<input type="text" inputmode="text">
It is suitable for entering names, comments, descriptions, and other general text information.
3. Decimal
The decimal value suggests a numeric keyboard that includes a decimal separator. It is useful when users need to enter decimal numbers, such as prices, measurements, or weights.
Example:
<input type="text" inputmode="decimal">
For example, a user entering a product price of 125.50 may find this keyboard layout more convenient.
4. Numeric
The numeric value suggests a keyboard containing numerical digits. It is particularly useful for entering phone numbers, PIN codes, verification numbers, and other numeric information.
Example:
<input type="text" inputmode="numeric">
This helps users enter numerical information without switching between different keyboard layouts.
5. Tel
The tel value suggests a telephone-oriented keyboard that makes entering phone numbers easier. Depending on the device, it may include digits and commonly used telephone characters.
Example:
<input type="text" inputmode="tel">
It is useful for contact forms, registration pages, and customer information forms.
6. Search
The search value suggests a keyboard layout designed for search-related input. Some mobile keyboards may display a search-oriented Enter key or other search-related controls.
Example:
<input type="text" inputmode="search">
It is commonly used in website search boxes and product search fields.
7. Email
The email value suggests a keyboard layout optimized for entering email addresses. Depending on the device, it may provide convenient access to characters such as the at symbol and period.
Example:
<input type="text" inputmode="email">
This is useful for login pages, registration forms, and contact forms.
8. URL
The url value suggests a keyboard layout designed for entering website addresses. Depending on the device, it may provide convenient access to characters such as the slash, period, and other URL-related symbols.
Example:
<input type="text" inputmode="url">
It is useful for website address fields, profile links, and URL submission forms.
4. Understanding the Enterkeyhint Attribute
The enterkeyhint attribute is another HTML global attribute that helps improve the mobile typing experience. It suggests what type of action should be represented by the Enter key on a virtual keyboard.
By default, mobile keyboards may display an Enter key without clearly indicating what action will happen next. The enterkeyhint attribute allows developers to suggest a more meaningful label, helping users understand the purpose of the key.
For example, in a search field, the Enter key can display the word "Search" instead of a general Enter label.
Syntax:
<input type="text" enterkeyhint="search">
In this example, the browser is encouraged to display a search-related label on the virtual keyboard's Enter key.
5. Different Values of the Enterkeyhint Attribute
The enterkeyhint attribute supports several values depending on the action users are expected to perform.
1. Enter
The enter value indicates a general Enter action. It is useful when users need to insert a new line or perform a general input action.
Example:
<textarea enterkeyhint="enter"></textarea>
2. Done
The done value suggests that the user has completed the current input task.
Example:
<input type="text" enterkeyhint="done">
It is useful for forms where users enter information into a field and then finish the task.
3. Go
The go value suggests that the user should proceed to another page or destination after entering information.
Example:
<input type="text" enterkeyhint="go">
It can be used in navigation interfaces and website address fields.
4. Next
The next value indicates that the user should move to the next input field.
Example:
<input type="text" enterkeyhint="next">
It is especially useful in registration forms where users need to enter information such as their name, email address, and phone number.
5. Previous
The previous value suggests that the user should move to the previous input field.
Example:
<input type="text" enterkeyhint="previous">
It can be useful in forms that allow users to navigate between multiple fields.
6. Search
The search value suggests that the user should perform a search operation.
Example:
<input type="search" enterkeyhint="search">
It is commonly used in search bars, product search pages, and website navigation interfaces.
7. Send
The send value suggests that the user should send the entered information.
Example:
<textarea enterkeyhint="send"></textarea>
It is useful in messaging applications, feedback forms, and communication interfaces.
6. Combining Inputmode and Enterkeyhint Attributes
Developers can use both attributes together in a single input field to improve the mobile typing experience.
For example, consider a website registration form where users need to enter their phone number. The inputmode="numeric" attribute suggests a numeric keyboard, while enterkeyhint="next" suggests that the user should move to the next field.
Example:
<form>
<label for="phone">Phone Number:</label>
<input
type="text"
id="phone"
inputmode="numeric"
enterkeyhint="next"
placeholder="Enter phone number">
<label for="email">Email Address:</label>
<input
type="email"
id="email"
inputmode="email"
enterkeyhint="done"
placeholder="Enter email address">
<button type="submit">Submit</button>
</form>
In this example, the phone number field suggests a numeric keyboard and a Next action. The email field suggests an email-friendly keyboard and a Done action. This makes the form more convenient to complete on mobile devices.
However, the attributes only provide hints to the browser. They do not automatically move the focus to another field, submit a form, or execute a search. Developers must implement those actions separately using JavaScript or normal HTML form behaviour.
7. Difference Between Inputmode and Enterkeyhint
Although both attributes improve mobile form usability, they serve different purposes.
|
Feature |
Inputmode |
Enterkeyhint |
|---|---|---|
|
Main purpose |
Suggests the keyboard layout |
Suggests the Enter key label |
|
Controls |
Type of virtual keyboard |
Appearance of Enter key |
|
Common values |
numeric, decimal, email, tel |
next, done, search, send |
|
Main benefit |
Makes data entry easier |
Makes the next action clearer |
|
Validation |
Does not validate input |
Does not validate input |
The inputmode attribute focuses on how users enter information, whereas enterkeyhint focuses on what action users are expected to perform after typing.
8. Advantages of Using These Attributes
Improved Mobile User Experience: These attributes make mobile forms easier to use by displaying more appropriate keyboard layouts and meaningful Enter key labels.
Faster Data Entry: Users can enter phone numbers, email addresses, decimal values, and website addresses more efficiently without repeatedly switching keyboard layouts.
Better Form Navigation: The enterkeyhint attribute helps communicate whether users should move to the next field, finish entering information, or send their message.
Reduced User Confusion: Clear keyboard labels help users understand what is expected when they press the Enter key.
Improved Accessibility and Usability: Appropriate input hints can make forms more convenient for users who interact with websites through mobile devices. However, these attributes do not replace proper labels, instructions, or accessible form controls.
Better Compatibility with Mobile Interfaces: Both attributes are supported by modern browsers, although the exact keyboard appearance and behaviour may vary depending on the browser, operating system, and device.
9. Best Practices for Using Inputmode and Enterkeyhint
Developers should choose the inputmode value according to the information expected in each input field. For example, numeric keyboards should be suggested for numeric information, while email keyboards should be used for email addresses.
The enterkeyhint value should clearly represent the next action that users are expected to perform. Developers should not use next if the Enter key does not actually move users to another field.
It is also important to remember that inputmode does not provide input validation. Developers should use suitable HTML input types, validation attributes such as required and pattern, and server-side validation to ensure that the entered information is correct.
Finally, developers should test these attributes on different mobile devices and browsers because virtual keyboard layouts may vary. They should also ensure that forms remain usable when physical keyboards or assistive technologies are used.
10. Conclusion
The inputmode and enterkeyhint attributes are useful HTML features for creating mobile-friendly websites and forms. The inputmode attribute helps browsers suggest an appropriate virtual keyboard, while the enterkeyhint attribute suggests a meaningful action label for the Enter key. By combining these attributes, developers can make registration forms, search boxes, contact forms, and messaging interfaces more convenient and user-friendly. Although these attributes do not perform validation or automatically execute actions, they improve the overall interaction between users and web applications, especially on smartphones and tablets.