inputmode for the Right Mobile Keyboard
Lesson 32 of 36 in the HTML5 learning path.
How do I open a numeric keyboard without type=number?
inputmode chooses a virtual keyboard. It does not validate. A text field with inputmode=numeric avoids the quirks of type=number.
The keyboard is a convenience. The server still checks that seats is an integer in range.
Syntax & Parameters
<input type="text" inputmode="numeric" pattern="[0-9]*">
Example
Interactive preview available<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Seats</title>
<style>
body{font:1rem/1.5 sans-serif;margin:2rem} label{display:block;margin:.5rem 0 .2rem}
</style>
</head>
<body>
<form method="post" action="/lessons"><label for="seats">Seats</label><input id="seats" name="seats" type="text" inputmode="numeric" pattern="[0-9]*"><label for="phone">Phone</label><input id="phone" name="phone" type="tel" inputmode="tel" autocomplete="tel"><button>Save</button></form>
</body>
</html>
Expected Output
A phone shows a numeric keypad for seats and a telephone keypad for phone.
Line-by-Line Walkthrough
- Seats stays type=text so you control parsing.
- inputmode=numeric asks for a digit keyboard.
- pattern is only a hint and a light client check.
- Phone uses type=tel.
- autocomplete=tel helps saved numbers.
- Desktop keyboards are unchanged.
- The server parses the integer.
- inputmode is not a security boundary.
Common Pitfalls & Security
inputmode does not filter a hardware keyboard.
- Letters can still be pasted into seats.
- type=number adds spinners and mishandles leading zeros.
- pattern is not the server rule.
- inputmode=none can block a keyboard you still need.
Best Practices & Modern Standards
Pick type for the data and inputmode for the keyboard when they differ.
Validate the integer range on the server even if the keypad only shows digits.
Real-World Use
The new-lesson form asks for a seat count. Phones show digits. The controller rejects anything outside 1 to 40.
Frequently Asked Questions
Does inputmode validate?
No. It only influences the virtual keyboard.
Why avoid type=number?
Spinners and parsing surprises get in the way when you only wanted digits.
What about decimals?
inputmode=decimal offers a separator. Still validate the format you store.
Do desktops change?
Little. A physical keyboard ignores the hint.