HTML Beginner

Better mobile keyboards without JavaScript

Mobile users got stuck with the default text keyboard on every input, or developers shipped JS workarounds to detect device type. inputmode and enterkeyhint let HTML request the right keyboard directly.

Modern
2 attributes
1<!-- Numeric pad, no type=tel hack -->
2<input type="text" inputmode="numeric" />
3
4<!-- Search keyboard with Search return key -->
5<input type="search" inputmode="search" enterkeyhint="search" />
Old JS hack
1/* Hack: use type=tel to get numeric keyboard */
2<input type="tel" pattern="[0-9]*" />
3
4/* No way to control the return key label */
5if (/Mobi/.test(navigator.userAgent)) {
6  submitBtn.textContent = 'Search';
7}
Widely available Since 2024 96% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2024.

66+
95+
12.1+
79+
each input triggers a different keyboard on mobile
Tap each field on a mobile device to see the keyboard change
Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more
⚑

Right keyboard, right type

inputmode controls the virtual keyboard independently from input type. Get a numeric pad while keeping type=text validation β€” no type=tel hack needed.

✦

Custom return key

enterkeyhint labels the return key: go, done, next, search, send. Users know what happens when they tap it.

∞

Works on contenteditable too

Both attributes work on contenteditable elements, not just inputs. Useful for rich text editors and custom input components.

Key Attributes
inputmode
+ enterkeyhint
Old Approach
type=tel hack
Wrong semantics for numbers
Modern Approach
inputmode
Keyboard hint, any input type

How it works

inputmode hints which virtual keyboard to show. Values: none (no keyboard), text (default), decimal (number with decimal point), numeric (digits only), tel, search, email, url. It does not affect the input type or validation.

enterkeyhint controls the label on the return/enter key of the virtual keyboard. Values: enter, done, go, next, previous, search, send. Browsers may ignore it if the key is not customizable.

The key distinction between inputmode and type: type affects browser validation and the submitted value format. inputmode only affects the keyboard β€” no validation, no format change. Use inputmode="numeric" when you want digits but need to accept leading zeros or dashes that type="number" would reject.

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC