HTML5 Intermediate Accessible Forms · 6 min read

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

Syntax
<input type="text" inputmode="numeric" pattern="[0-9]*">

Example

Interactive preview available
seats.html
<!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

  1. Seats stays type=text so you control parsing.
  2. inputmode=numeric asks for a digit keyboard.
  3. pattern is only a hint and a light client check.
  4. Phone uses type=tel.
  5. autocomplete=tel helps saved numbers.
  6. Desktop keyboards are unchanged.
  7. The server parses the integer.
  8. 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.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…