What Is the inputmode Attribute?
The inputmode attribute is an enumerated global HTML attribute that hints at the type of data that might be entered by the user while editing the element or its contents. This allows a browser to display an appropriate virtual keyboard tailored to the expected input type.
This single HTML attribute solves a common mobile frustration: when you're trying to enter a phone number but your keyboard shows the standard text layout, or when you need to type a decimal value and hunt for the period key. With inputmode, you get the right keyboard for the job--automatically.
Key characteristics:
- Works on any HTML element (primarily
<input>and contenteditable elements) - Purely a keyboard hint--no validation enforced
- Supported across all modern browsers (Baseline since December 2021)
- No JavaScript required
- Gracefully degrades in older browsers
Picture this scenario: a customer is on your mobile checkout page, ready to complete a purchase. They tap on the price field, and instead of seeing numbers and a decimal point, they see the standard QWERTY keyboard. They have to switch keyboard modes, hunt for the period key, and carefully tap in their order total. Frustrated, they abandon the cart. This happens millions of times daily across the web--all because a simple HTML attribute was overlooked. The inputmode attribute eliminates this friction with a single line of markup.
Implementing proper input attributes is a fundamental part of professional web development that significantly impacts user experience and conversion rates.
The Seven inputmode Values
The inputmode attribute accepts seven distinct values, each optimized for different input types. Understanding when to use each value is key to maximizing the benefit for your users.
Each value triggers a specific keyboard layout on mobile devices, from phone-style keypads to email-optimized layouts with the @ symbol front and center. The following table provides a quick reference, and the tabs below dive into each value with detailed explanations and code examples.
| Value | Keyboard Type | Best For | Example |
|---|---|---|---|
| `none` | No virtual keyboard | Custom input methods, drawing pads | Canvas-based input |
| `text` (default) | Standard locale keyboard | General text input | Names, addresses |
| `decimal` | Numeric with decimal separator | Prices, measurements, coordinates | 19.99, 42.5 |
| `numeric` | Numbers 0-9 only | PINs, quantities, codes | 1234, 5 items |
| `tel` | Phone keypad (0-9, *, #) | Phone numbers | (555) 123-4567 |
| `search` | Search-optimized with 'Search' key | Search fields | Product search |
| `email` | Email with @ symbol | Email addresses | [email protected] |
| `url` | URL with / key prominent | Web addresses | https://example.com |
Fractional numeric keyboard containing the digits and decimal separator for the user's locale (typically . or ,). Devices may or may not show a minus key.
Best for: Prices, percentages, lat/long coordinates, measurements with decimals, scientific notation values.
<input type="text" inputmode="decimal" placeholder="0.00">
The decimal separator adapts to the user's locale--European users see a comma, American users see a period.
Browser Support and Compatibility
The inputmode attribute has excellent browser support. According to MDN Web Docs, it achieved "Baseline" status in December 2021, meaning it's widely available across all modern browsers.
Current Support
- Chrome and Edge (Blink-based): Full support
- Firefox (Gecko): Full support
- Safari (WebKit): Full support
- All modern mobile browsers: Full support
More than 95% of global users access the web with browsers that support inputmode. For that remaining slice of users on older devices, the attribute is simply ignored--no broken experience, no JavaScript errors, no fallback complexity. This is progressive enhancement at its finest.
Graceful Degradation
One of the most compelling aspects of inputmode is its graceful degradation:
- Unsupported browsers simply ignore the attribute and show the default keyboard
- No JavaScript polyfills required
- No fallback code needed
- Safe to use in production today
This means you can start using inputmode immediately without worrying about breaking experiences for users on older browsers--they simply get the standard keyboard, which is exactly what they'd see without inputmode anyway.
inputmode at a Glance
7
inputmode values
100%
Modern browser support
0
JavaScript required
1
HTML attribute
inputmode vs input Types: What's the Difference?
A common point of confusion is the relationship between inputmode and the type attribute on <input> elements. They serve different purposes and can (and often should) be used together.
The Key Distinction
| Aspect | type Attribute | inputmode Attribute |
|---|---|---|
| Purpose | Semantic meaning + validation | Keyboard hint |
| Validation | Enforces data format | None |
| Keyboard | May affect keyboard (varies) | Directly controls keyboard |
| Required | Required for form inputs | Optional enhancement |
When to Use Each
Use type="email" when:
- You need email validation
- You want semantic meaning
- You want browser autofill support
Use inputmode="email" when:
- You're using a text input for email-like values
- You want keyboard control without validation
- You're using a custom input component
<!-- Use type for actual email fields -->
<input type="email" required>
<!-- Use inputmode for text inputs needing email keyboard -->
<input type="text" inputmode="email">
The Recommended Pattern
For the best results, use both--the type attribute for semantics and validation, and inputmode for keyboard control:
<!-- Complete solution: validation + keyboard -->
<input type="text" inputmode="decimal" pattern="[0-9]*[.,]?[0-9]*">
<!-- For tel, type="tel" already handles keyboard in most browsers -->
<input type="tel">
Understanding this distinction is crucial for building robust, accessible forms. The type attribute remains your foundation for semantic HTML and form validation. inputmode acts as a progressive enhancement--an optional layer that improves the experience for mobile users without affecting functionality for anyone else.
Proper form implementation is a core part of our web development services, ensuring your forms work flawlessly across all devices and browsers.
Best Practices for Using inputmode
When to Use inputmode
The inputmode attribute is most valuable in these scenarios:
- Generic text inputs needing type-specific keyboards
- Quantity fields that should show numeric keyboard
- Coupon codes needing text but better layout
- Custom form elements where
typedoesn't fit
- Contenteditable elements
- Rich text editors where you want to suggest input type
- Custom input areas that need keyboard control
- Dynamic forms
- Forms where input type changes based on user selection
- Multi-purpose input fields
- Accessibility improvements
- Reducing cognitive load for users
- Making forms more intuitive for all users
Performance Impact
While inputmode doesn't directly affect page load times, it significantly impacts user-perceived performance:
- Faster form completion on mobile devices
- Reduced input errors from wrong keyboard
- Lower form abandonment rates
- Improved Core Web Vitals for interaction metrics
Common Mistakes to Avoid
Mistake 1: Using inputmode instead of proper type
<!-- Wrong: Missing semantic meaning -->
<input inputmode="email">
<!-- Correct: Proper type with inputmode for keyboard -->
<input type="email" inputmode="email">
Mistake 2: Overusing inputmode on already-optimized types
<!-- Unnecessary: type="tel" already optimizes keyboard -->
<input type="tel" inputmode="tel">
<!-- Acceptable but redundant -->
<input type="text" inputmode="text">
Mistake 3: Expecting validation from inputmode
<!-- inputmode doesn't validate - use pattern -->
<input inputmode="numeric">
<!-- Better: Add pattern for validation -->
<input type="text" inputmode="numeric" pattern="[0-9]*">
Think of inputmode as a complement to proper form design, not a replacement for it. It enhances the keyboard experience while your semantic type attributes and validation patterns ensure data integrity. Together, they create forms that are both user-friendly and robust.
Practical Implementation Examples
E-commerce Forms
<!-- Product quantity - numeric keyboard for quick entry -->
<input type="number" min="1" max="99" inputmode="numeric"
placeholder="Qty" style="width: 80px;">
<!-- Price input - decimal keyboard shows period/comma -->
<input type="text" inputmode="decimal" placeholder="0.00" step="0.01">
<!-- Coupon code - standard text keyboard for alphanumeric -->
<input type="text" inputmode="text" placeholder="Enter coupon code">
<!-- Gift card number - numeric for card digits -->
<input type="text" inputmode="numeric" pattern="[0-9]*"
placeholder="1234 5678 9012 3456">
Registration and Contact Forms
<!-- Phone number (preferred: type="tel" for validation) -->
<input type="tel" inputmode="tel" placeholder="(555) 123-4567">
<!-- Email - @ symbol readily available -->
<input type="email" inputmode="email" placeholder="[email protected]">
<!-- ZIP code - numeric for digits only -->
<input type="text" inputmode="numeric" pattern="[0-9]{5}"
placeholder="12345" maxlength="5">
<!-- Credit card CVV - numeric for security codes -->
<input type="text" inputmode="numeric" pattern="[0-9]*"
placeholder="123" maxlength="4" style="width: 80px;">
Search and Navigation
<!-- Site search - Search key guides users to submit -->
<input type="search" inputmode="search" enterkeyhint="search"
placeholder="Search products...">
<!-- URL input - / key prominent for web addresses -->
<input type="url" inputmode="url" placeholder="https://...">
<!-- Internal search - finding content on page -->
<input type="text" inputmode="search" placeholder="Find in page...">
These examples are copy-paste ready for your projects. Each inputmode was chosen based on the expected data type: numeric for quantities and codes, decimal for prices, email and tel for their respective data types, and search for any text input primarily used for searching.
1// Change inputmode based on user selection2const amountType = document.getElementById('amount-type');3const amountInput = document.getElementById('amount');4 5amountType.addEventListener('change', (e) => {6 switch (e.target.value) {7 case 'percentage':8 amountInput.inputmode = 'decimal';9 break;10 case 'quantity':11 amountInput.inputmode = 'numeric';12 break;13 case 'currency':14 amountInput.inputmode = 'decimal';15 break;16 default:17 amountInput.inputmode = 'text';18 }19});20 21// Example: Credit card field detection22const cardNumber = document.getElementById('card-number');23cardNumber.addEventListener('input', (e) => {24 // Switch to numeric after detecting card pattern25 if (/^\d{4}$/.test(e.target.value.replace(/\s/g, ''))) {26 cardNumber.inputmode = 'numeric';27 }28});Related HTML Attributes for Input Optimization
enterkeyhint
The enterkeyhint global attribute works alongside inputmode to specify what label should appear on the Enter key. This completes the keyboard customization for your forms.
Values: enter, done, go, next, previous, search, send
<!-- Complete search optimization -->
<input type="search"
inputmode="search"
enterkeyhint="search"
placeholder="Search...">
<!-- Form with clear action hint -->
<input type="text"
enterkeyhint="next"
placeholder="First name">
pattern
The pattern attribute works with inputmode="text" or inputmode="numeric" to provide validation:
<!-- Numeric with validation -->
<input type="text"
inputmode="numeric"
pattern="[0-9]{5}"
title="Enter a 5-digit ZIP code">
<!-- Email pattern with inputmode -->
<input type="text"
inputmode="email"
pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"
title="Enter a valid email address">
autocomplete
The autocomplete attribute helps browsers provide better autofill suggestions:
<!-- Optimized for autofill and keyboard -->
<input type="tel"
inputmode="tel"
autocomplete="tel"
placeholder="Phone number">
These attributes work together to create a comprehensive form optimization strategy. The inputmode attribute handles the keyboard, enterkeyhint shapes the Enter key action, pattern enforces validation, and autocomplete guides autofill. Combined with proper type attributes, you have everything needed for optimal form UX.
Accessibility Benefits
The inputmode attribute provides significant accessibility benefits that extend beyond convenience:
Cognitive Load Reduction
When users see the appropriate keyboard, they don't need to hunt for special characters or switch keyboard modes. This reduces cognitive overhead, particularly beneficial for:
- Users with cognitive disabilities
- Users with memory impairments
- Older adults who may be less familiar with mobile conventions
Motor Skill Considerations
Users with motor impairments benefit from:
- Fewer keystrokes required
- Larger, easier-to-tap keys
- Reduced need for keyboard switching
Screen Reader Compatibility
The inputmode attribute:
- Works seamlessly with screen readers
- Helps users understand expected input format
- Doesn't interfere with announcement of field purpose
Universal Design
inputmode exemplifies universal design principles--improving experience for everyone while particularly benefiting users with disabilities. There's no downside to using it, making it an accessibility best practice. When you optimize for accessibility, you often end up creating better experiences for all users. The right keyboard doesn't just help screen reader users or those with motor impairments--it helps everyone complete forms faster and with less frustration.
Building accessible, user-friendly web experiences is at the core of our web development services. We ensure every form and interaction works beautifully for all users.
Frequently Asked Questions
Conclusion
The inputmode attribute represents a simple yet powerful approach to improving mobile form experiences. With a single HTML attribute, you can dramatically reduce friction for users entering data on their phones and tablets.
Key takeaways:
- Seven values cover all common input scenarios
- Universal support means safe production use
- Zero JavaScript required--pure HTML progressive enhancement
- Graceful degradation for older browsers
- Significant UX impact with minimal development effort
The next time you're building a form, consider: What keyboard would users expect for each field? Then add the corresponding inputmode attribute. Your users--especially those on mobile devices--will thank you.
Quick Reference
| Input Type | Use This inputmode |
|---|---|
| Phone number | tel |
| Email address | email |
| Price/decimal | decimal |
| Quantity/PIN | numeric |
| URL | url |
| Search query | search |
| Custom input | none |
Ready to implement inputmode in your projects? Start by auditing your existing forms and adding appropriate inputmode attributes to each field. The improvement in user experience--and potentially conversion rates--will be immediately noticeable. For more tips on building exceptional web forms, explore our web development services or browse our other web development guides.