šŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
šŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

inputmode: Requesting The Right Mobile Keyboard

Understand that inputmode is purely a keyboard-layout hint with no validation effect, the common values matching typical data shapes, and the genuine use case for combining it with type="text" to avoid type="number"'s leading-zero limitation.

⚔ Total XP: 0|šŸ’» html XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Input Modes

Mobile keyboard requests.


šŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
šŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

On mobile devices, the on-screen keyboard shown for a field meaningfully affects typing speed and error rate. inputmode is the dedicated, validation-independent mechanism for requesting the appropriate layout.

1A Keyboard Hint, Not A Validation Constraint

It's a common and understandable assumption that inputmode="numeric" somehow restricts a field to numeric input, similar to how type="number" or pattern constrain acceptable values — but this is incorrect. inputmode exclusively requests which on-screen virtual keyboard layout a mobile browser should display; it has zero effect on what characters can actually be typed, pasted, or ultimately submitted.

Actual value restriction still requires the mechanisms covered earlier in this module — type, pattern, min/max. A field can (and often should, for the leading-zero use case covered later) use inputmode alongside these separate validation mechanisms, understanding they solve entirely different problems.

<!-- Numeric keyboard shown, but validation still needs pattern -->
<input type="text" inputmode="numeric" pattern="\d*">
localhost:3000
āœ“ Keyboard And Validation, Separatelyinputmode requests the keyboard; pattern still handles actual value validation.

2Matching inputmode Values To Common Data Shapes

numeric requests a digit-focused keypad, ideal for whole-number values like quantities or PIN codes. tel requests a phone-dial-style layout appropriate for phone numbers. email requests a keyboard with an easily accessible @ key and often no autocapitalize interference. url optimizes for URL entry with quick access to / and common domain shortcuts. decimal is similar to numeric but crucially includes a decimal point key, appropriate for values like prices that may include fractional components.

Choosing the value that actually matches the expected data shape — rather than defaulting to the generic system keyboard for everything — measurably improves mobile form completion speed and reduces typing errors.

<input type="tel" inputmode="tel">
<input type="text" inputmode="decimal" name="price">
localhost:3000
decimal keyboard includes:
Digit keys + a decimal point key

3Solving type="number"'s Leading-Zero Problem

<input type="number"> treats its value as an actual numeric value internally, which means leading zeros are silently stripped — a value entered or set as "007" becomes simply 7. For genuinely numeric-shaped data where leading zeros are semantically meaningful — certain ID formats, some postal codes, product codes — this behavior is actively wrong.

The correct pattern is type="text" (preserving the exact string as entered) combined with inputmode="numeric" (still showing the appropriate numeric mobile keyboard) and pattern="\d*" (still validating that only digits were entered) — getting the correct mobile UX without type="number"'s data-mangling side effect.

<!-- type="number" would silently become 7, losing the leading zeros -->
<input type="text" inputmode="numeric" pattern="\d*" value="007">
localhost:3000
āœ“ "007" Preserved ExactlyText-based storage with numeric keyboard and pattern validation, avoiding type="number"'s data mangling.

4Step-by-Step Breakdown

Requesting The Right Keyboard, Not Just The Right Input Type. On mobile, the visible on-screen keyboard matters enormously for typing speed and accuracy. inputmode requests a specific keyboard layout — numeric keys, an @ symbol, phone-dial layout — independent of the input's actual type or validation behavior.

inputmode Is About The Keyboard, Not Validation. A common misconception: inputmode doesn't validate or constrain the actual entered value at all — that's still type, pattern, min/max from earlier lessons. inputmode purely requests which on-screen keyboard layout mobile browsers should display.

inputmode's Actual Effect. Does adding inputmode="numeric" to an <input type="text"> restrict what characters can actually be typed or submitted?

  • →Yes, it prevents any non-numeric character from being entered
  • →No, it only requests a numeric on-screen keyboard; actual value restriction requires separate constraints like pattern
  • →It automatically converts the field's type to number

Common inputmode Values Match Common Data Types. numeric shows a digit-focused keypad, tel shows a phone-dial-style layout, email shows a keyboard with an easily accessible @ symbol, url shows one optimized for URLs with / and .com shortcuts, and decimal allows a decimal point unlike numeric.

Choosing The Right inputmode. A field collects a price value that may include cents, like '19.99'. Why might inputmode="decimal" be more appropriate than inputmode="numeric"?

  • →They're functionally identical; either works equally well
  • →decimal's keyboard includes a decimal point key, which numeric's typically omits
  • →numeric is deprecated in favor of decimal

inputmode Complements type, It Doesn't Replace It. For genuinely numeric data, <input type="number"> already implies an appropriate mobile keyboard in most browsers — inputmode becomes most valuable specifically for type="text" fields that represent numeric-shaped data but need text-level validation flexibility (like a numeric ID that might have a required leading zero, which type="number" would strip).

inputmode With type="text". Why might a developer use type="text" with inputmode="numeric" instead of simply using type="number" for a numeric-looking ID field?

  • →There's no real reason; type="number" is always strictly better
  • →type="number" strips leading zeros and doesn't support values like "007" as text
  • →inputmode literally cannot be combined with type="number"

Input Modes Mastered. You now understand that inputmode is purely a keyboard-layout hint independent of validation, know the common values matching typical data shapes, and understand the genuine use case for pairing type="text" with inputmode when type="number" would incorrectly strip meaningful leading zeros.

Show The Right Mobile Keyboard. inputmode="numeric" tells mobile browsers to show a numeric keypad, without changing validation.

Level Up šŸš€

Advanced cheat sheets, SEO tricks, and interview prep for this topic.

Browser Support

ChromeSupported

Fully supported.

FirefoxSupported

Fully supported.

SafariSupported

Fully supported.

EdgeSupported

Fully supported.

Accessibility (A11y)

1The Correct Mobile Keyboard Reduces Cognitive And Motor Load For All Mobile Users

A numeric keypad for a numeric field reduces the visual scanning and precise targeting required compared to a full QWERTY keyboard, benefiting users with motor control differences or cognitive load concerns particularly.

SEO Implications

  • 1

    Faster, Lower-Friction Mobile Form Completion Indirectly Supports Conversion And Engagement Metrics

    Given mobile-first indexing (covered in the Mobile-First HTML lesson) evaluates the mobile experience primarily, small UX improvements like correct keyboard matching compound across a mobile-majority user base.

Best Practices

Choose inputmode Based On The Field's Actual Expected Data Shape, Not Just Its type Value

Since inputmode and type solve different problems, deliberately matching the keyboard to expected content (even for type="text" fields) meaningfully improves mobile typing speed and accuracy.

Use type="text" Plus inputmode="numeric" Plus pattern For Numeric-Looking Data Where Leading Zeros Matter

This combination gets the correct mobile keyboard and validation behavior while avoiding type="number"'s silent leading-zero stripping, a common, easy-to-miss data-integrity bug.

Frequent Bugs

THE BUG

A postal/product code field silently loses its leading zeros after being saved.

THE FIX

Switch from type="number" to type="text" with inputmode="numeric" and a pattern constraint, preserving the exact entered string.

THE BUG

Users on mobile complain that entering a phone number is slow and error-prone, requiring switching keyboard modes manually.

THE FIX

Add inputmode="tel" (and type="tel") to request the phone-optimized on-screen keyboard directly.

Real-World Examples

A Correctly-Configured Numeric ID Field

An order ID field preserving leading zeros while still getting the correct mobile numeric keyboard.

<label for="orderId">Order ID</label>
<input id="orderId" type="text" inputmode="numeric" pattern="\d{6}" value="007821">

Interview Prep

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Assuming inputmode restricts what can actually be entered

<input inputmode="numeric" pattern="\d*">

The Solution //

Pair inputmode with real validation (type, pattern) since it only affects the displayed keyboard.

The Error //

Using type="number" for IDs/codes with meaningful leading zeros

<input type="text" inputmode="numeric" pattern="\d*" value="007">

The Solution //

Use type="text" with inputmode="numeric" and pattern instead to preserve the exact string.

Lesson Glossary

[01]inputmode

Requests a specific on-screen mobile keyboard layout.

Code Preview
inputmode="numeric"

[02]Keyboard Hint

A UX-only signal with no validation effect.

Code Preview
Doesn't restrict input

[03]Leading Zero Stripping

type="number"'s side effect of losing leading zeros.

Code Preview
"007" → 7

[04]decimal (inputmode)

A numeric keyboard variant including a decimal point key.

Code Preview
For price-like values

Continue Learning