autocomplete tells the browser and password manager exactly what a field holds, so they can fill it in one tap. inputmode picks the virtual keyboard without changing validation. enterkeyhint labels the Enter key. autocapitalize and spellcheck stop the keyboard from “helping” with names, codes and usernames. Together they turn a two-minute checkout into a twenty-second one.
Watch someone fill in an address form on a phone. The name field capitalizes correctly, but the email field capitalizes the first letter, and the login later fails because the username was saved as “Ravi.k”. The PIN code field opens a full keyboard. The OTP field does not offer the code that just arrived by SMS. The browser has their address saved but autofills the city into the state field because the field names are addr2 and region_x. Every one of these is fixable with an attribute.
These attributes are hints to the browser, the operating system’s keyboard and password managers. autocomplete describes the meaning of a field’s value using a fixed vocabulary of tokens. inputmode describes the kind of virtual keyboard to show. enterkeyhint describes the action of the Enter key. autocapitalize and spellcheck control text correction. None of them changes how the value is validated, which is the job of the type attribute covered in HTML5 input types in practice.
What does the autocomplete attribute do?
Browsers guess what a field contains from its name, id and label, and the guesses are often wrong. An explicit autocomplete token removes the guessing. It is also an accessibility requirement: WCAG 2.1 success criterion 1.3.5, Identify Input Purpose, asks that fields collecting information about the user identify their purpose, and these tokens are how you do it.
| Field | Token |
|---|---|
| Full name | name (or given-name and family-name) |
email |
|
| Phone | tel (or tel-national without country code) |
| Username on a login form | username |
| Password on a login form | current-password |
| Password on sign-up or change-password | new-password |
| SMS or email verification code | one-time-code |
| Street address | street-address, or address-line1 and address-line2 |
| City | address-level2 |
| State or province | address-level1 |
| PIN code, ZIP or postal code | postal-code |
| Country | country (code) or country-name |
| Card number, name, expiry, CVC | cc-number, cc-name, cc-exp, cc-csc |
| Company | organization |
| Date of birth | bday, or bday-day, bday-month, bday-year |
The address tokens use generic “levels” because address formats differ worldwide: address-level1 is the largest administrative area (a state in India or the US), address-level2 is usually the city.
Shipping, billing and sections
When a form has two addresses, prefix the tokens so the browser fills each from the right saved entry:
<input name="ship_pin" autocomplete="shipping postal-code">
<input name="bill_pin" autocomplete="billing postal-code">
<!-- For other repeated groups, use section-* -->
<input name="guest1_name" autocomplete="section-guest1 name">
<input name="guest2_name" autocomplete="section-guest2 name">
Passwords and the autocomplete=”off” myth
Login and sign-up forms benefit most from correct tokens. current-password tells password managers to fill the saved password. new-password tells them to offer a generated strong password and to save it afterwards. Pair each with username on the identifier field, even if it is an email address, so the manager stores the right pair.
Setting autocomplete="off" on login fields does not work the way many teams expect. Chrome, Firefox and Safari ignore it for username and password fields, deliberately, because blocking password managers pushes people toward weak, reused passwords. Security reviews that demand autocomplete="off" on login forms are asking for something browsers will not do. Use off only where autofill is genuinely wrong, such as a field where an admin types someone else’s details.
One-time codes
<label for="otp">Enter the 6-digit code we sent you</label>
<input id="otp" name="otp" type="text" inputmode="numeric"
autocomplete="one-time-code" pattern="[0-9]{6}" maxlength="6">
On iOS and macOS Safari, one-time-code makes the keyboard offer a code that just arrived by SMS or email as a one-tap suggestion. On Android, Chrome’s similar suggestion and the WebOTP API, which can read a specially formatted SMS with the user’s permission, cover the same need. Either way, the user stops switching apps to copy six digits.
What does inputmode do?
inputmode changes only the virtual keyboard. That makes it the right tool when you want a numeric keypad but need text behavior, such as keeping leading zeros.
| Value | Keyboard | Use for |
|---|---|---|
numeric |
Digits 0 to 9 | OTPs, PIN codes, card numbers, account numbers |
decimal |
Digits plus the locale’s decimal separator | Prices, weights, measurements |
tel |
Phone pad with * and # | Phone numbers when you cannot use type="tel" |
email |
Text with @ and . | Email-like identifiers in a text field |
url |
Text with / and .com | Domains and URLs typed without a scheme |
search |
Text with a search key | Search fields |
text |
Standard keyboard | The default |
none |
No keyboard | Fields with their own on-screen input, such as a custom keypad |
A useful rule: choose type for meaning and validation, then add inputmode only when the type’s default keyboard is wrong. A field with type="email" already gets the email keyboard; type="text" inputmode="numeric" is the standard pattern for digit strings that are not numbers. Note that numeric on iOS shows a large digits-only pad, while decimal adds a decimal point, so pick decimal for any value with fractions.
What does enterkeyhint do?
<input type="search" name="q" enterkeyhint="search">
<input type="text" name="first" enterkeyhint="next">
<textarea name="message" enterkeyhint="send"></textarea>
The values enter, done, go, next, previous, search and send change the label or icon on the virtual keyboard’s Enter key. They do not change behavior; if you label it “next”, your code should move focus to the next field. Used consistently, it tells users what will happen before they tap.
How do autocapitalize and spellcheck work?
Phone keyboards capitalize the first letter of a text field and autocorrect words by default. That is right for sentences and wrong for usernames, codes, coupon fields and many names.
| Attribute and value | Effect | Use for |
|---|---|---|
autocapitalize="none" |
No automatic capitals | Usernames, coupon codes, handles |
autocapitalize="words" |
Capitalize each word | Names, city names |
autocapitalize="characters" |
All capitals | Vehicle registration numbers, PAN, IFSC codes |
autocapitalize="sentences" |
First letter of each sentence | Messages, reviews (the default for text) |
spellcheck="false" |
No spelling underlines | Names, codes, technical identifiers |
autocorrect="off" |
No word replacement, Safari only | Usernames, product codes |
A few details: autocapitalize only affects virtual keyboards and has no effect when typing on a physical keyboard. Fields with type of email, url and password are never auto-capitalized, so they do not need it. And autocorrect is a non-standard Safari attribute; other browsers ignore it, which is harmless.
Putting it together: an address form
<label for="name">Full name</label>
<input id="name" name="name" autocomplete="shipping name"
autocapitalize="words" spellcheck="false" enterkeyhint="next">
<label for="phone">Mobile number</label>
<input id="phone" name="phone" type="tel" autocomplete="shipping tel" enterkeyhint="next">
<label for="line1">Flat, house no., building</label>
<input id="line1" name="line1" autocomplete="shipping address-line1" enterkeyhint="next">
<label for="line2">Area, street, locality</label>
<input id="line2" name="line2" autocomplete="shipping address-line2" enterkeyhint="next">
<label for="pin">PIN code</label>
<input id="pin" name="pin" inputmode="numeric" pattern="[1-9][0-9]{5}" maxlength="6"
autocomplete="shipping postal-code" enterkeyhint="next">
<label for="city">City</label>
<input id="city" name="city" autocomplete="shipping address-level2"
autocapitalize="words" enterkeyhint="next">
<label for="state">State</label>
<input id="state" name="state" autocomplete="shipping address-level1"
autocapitalize="words" enterkeyhint="done">
With saved browser data, this form fills in a single tap. Without it, every field shows the right keyboard and never fights the user’s typing. The labels and grouping follow the accessible forms guide.
Frequently Asked Questions
What is the difference between inputmode and input type?
type defines what kind of data the field holds and how the browser validates it. inputmode only chooses which virtual keyboard to show. Use type for meaning, and add inputmode when you need a different keyboard without changing validation, such as type=text with inputmode=numeric for OTP codes.
Does autocomplete=”off” work on password fields?
No. Major browsers deliberately ignore autocomplete=”off” on login fields so that password managers keep working. Use current-password on login forms and new-password on sign-up and password change forms instead.
How do I make the OTP from an SMS appear above the keyboard?
Add autocomplete=”one-time-code” to the code field, along with inputmode=”numeric”. Safari on iOS and macOS then offers the code from a recent SMS or email as a one-tap suggestion, and Chrome on Android offers similar suggestions.
Is the autocomplete attribute required for accessibility?
WCAG 2.1 success criterion 1.3.5 at level AA requires that inputs collecting the user’s own information identify their purpose, and correct autocomplete tokens are the standard way to meet it. It also lets assistive tools fill or label fields with familiar icons.
A minute of attributes, hours of user time
These attributes cost nothing to add and have no visual effect on desktop, which is why they are so often missing. Add an autocomplete token to every field that collects the user’s own data, an inputmode where the keyboard is wrong, and turn off capitalization and correction where they get in the way. Then fill your own form on a phone and count the taps. For the full reference, see the MDN autocomplete reference and the WCAG guidance on identifying input purpose. Related reading on this site: native form validation.
Originally posted on 13 June 2023 and post last modified on 13 June 2023