LEARNING OBJECTIVES โต
- Understand how modern browser autofill engines and password managers utilize the
autocompleteattribute. - Implement WCAG 2.1 Success Criterion 1.3.5 (Identify Input Purpose) using standard autofill tokens.
- Master the WHATWG token vocabulary across identity, security (
new-password,one-time-code), addresses, and payments. - Apply sectioning prefixes (
shipping,billing) for multi-address checkout pipelines. - Understand why browsers intentionally ignore
autocomplete="off"on login/credential fields.
๐ The Mental Model & Story (Intuitive Foundation)
Imagine checking into an international hotel or visiting a medical clinic. The receptionist hands you a clipboard with a 4-page paper form: Full Legal Name, Passport Number, Home Address, Mobile Phone, Emergency Contact, Credit Card.
If you have to handwrite your name and home address 15 times a month on paper, your wrist gets tired, you make typos, and you dread the process.
Now imagine carrying an official Digital Passport Smartcard. When you tap the clipboard, a robotic arm instantly copies your verified identity, home address, and payment token into every corresponding box in 0.1 seconds with 100% typographic accuracy.
+-----------------------------------------------------------------------------------+
| USER SMART VAULT (Keychain / 1Password / Browser Autofill) |
| Name: "Alex Vance" | Email: "[email protected]" | CC: "**** **** **** 4242" |
+-----------------------------------------------------------------------------------+
โ
Taps form (Scans autocomplete token clues)
โผ
+-----------------------------------------------------------------------------------+
| WEB FORM INPUTS |
| <input autocomplete="name"> <==== Populated: "Alex Vance" |
| <input autocomplete="email"> <==== Populated: "[email protected]" |
| <input autocomplete="cc-number"> <==== Populated: "4532 0123 4567 4242" |
+-----------------------------------------------------------------------------------+
The autocomplete attribute is that standardized smartcard protocol. It provides machine-readable metadata that tells password managers and browser autofill engines: "This specific input is for the user's family name, this one is for the one-time SMS 2FA code, and this is the billing zip code."
Technical Deep Dive & Specifications
WCAG 2.1 Success Criterion 1.3.5 (Level AA)
Web Content Accessibility Guidelines (WCAG) 2.1 introduced SC 1.3.5: Identify Input Purpose.
Websites must use standardized HTML autocomplete tokens on inputs collecting user-specific personal data. This assists users with motor disabilities, cognitive impairments, and screen reader users by allowing assistive technologies to automatically fill forms or render personalized visual icons (e.g., placing a phone icon next to tel inputs).
The Complete WHATWG Autocomplete Token Vocabulary
The autocomplete attribute accepts space-separated tokens structured according to the WHATWG specification:
[section-name] [shipping | billing] [contact-type] <token>
1. Identity & Contact Tokens
| Token | Meaning / Purpose |
|---|---|
name |
Full name (single field) |
given-name |
First name / given name |
additional-name |
Middle name / middle initial |
family-name |
Last name / surname |
nickname |
Casual display handle |
email |
Email address |
username |
Account login username |
organization |
Company or employer name |
organization-title |
Job title / professional designation |
2. Authentication & Security Tokens
| Token | Meaning / Purpose |
|---|---|
current-password |
Existing password for authentication or re-auth |
new-password |
Registration or password change (triggers strong password generation) |
one-time-code |
2FA / OTP SMS code (triggers mobile keyboard SMS autofill on iOS/Android) |
webauthn |
Conditional UI for Passkeys / FIDO2 biometric authentication |
3. Postal Address Tokens
| Token | Meaning / Purpose |
|---|---|
street-address |
Full multiline street address |
address-line1 |
Street address line 1 |
address-line2 |
Suite, unit, apartment number |
address-level2 |
City, town, or municipality |
address-level1 |
State, province, or prefecture |
postal-code |
Zip code or postal code |
country |
Two-letter ISO country code (US, GB) |
country-name |
Full localized country name (United States) |
4. Payment Tokens
| Token | Meaning / Purpose |
|---|---|
cc-name |
Cardholder name as printed on card |
cc-number |
16โ19 digit payment card number |
cc-exp |
Expiration date (MM/YY or MM/YYYY) |
cc-exp-month |
Expiration month (01โ12) |
cc-exp-year |
Expiration year (2026) |
cc-csc |
Card security code (CVV/CVC on back of card) |
cc-type |
Payment brand (visa, mastercard, amex) |
5. Sectioning Prefixes (shipping vs billing)
When a checkout form collects both a shipping address and a billing address, prefixing tokens with shipping or billing prevents autofill collisions:
<!-- Shipping Address Group -->
<input autocomplete="shipping address-line1">
<input autocomplete="shipping postal-code">
<!-- Billing Address Group -->
<input autocomplete="billing address-line1">
<input autocomplete="billing postal-code">
The autocomplete="off" Reality in Modern Browsers
Historically, banks and websites placed autocomplete="off" on forms to prevent password saving.
Modern Spec & Browser Reality: Modern browsers (Chrome, Safari, Firefox, Edge) and password managers (1Password, Bitwarden, Apple Keychain) intentionally ignore autocomplete="off" on login, username, and password fields.
Security research proved that forcing users to memorize complex passwords without password managers leads to weak, reused passwords (Password123!). Browsers prioritize user security by enabling password managers everywhere.
Use autocomplete="off" only for:
- Unique captcha inputs
- One-time verification tokens not intended for storage
- Sensitive search histories in shared kiosk environments
๐ป Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Line 33 (
autocomplete="given-name"): Tells autofill engines to supply only the user's first name without combining it with the surname. - Line 37 (
autocomplete="family-name"): Populates the user's surname. - Line 41 (
autocomplete="email"): Binds to the user's registered email address. - Line 48 (
autocomplete="shipping street-address"): Uses theshippingsection prefix to populate the physical delivery address rather than the payment billing address. - Line 66 (
autocomplete="one-time-code" inputmode="numeric"): The gold standard for 2FA. On iOS (Safari) and Android (Chrome), incoming SMS text messages with verification codes appear automatically as a single-tap suggestion directly above the keyboard.
Expected Browser Render Output
Express Checkout Portal
1. Contact Information
First Name [given-name] Last Name [family-name]
[ ] [ ]
Email Address [email]
[ ]
2. Shipping Address
Street Address [shipping street-address]
[ ]
City [shipping address-level2] Postal Code [shipping postal-code]
[ ] [ ]
3. Verification
SMS Verification Code [one-time-code]
[ 123456 ]
[ Complete Instant Checkout ]๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Build a Password Reset & 2FA Suite
Instructions:
- Build an account security update form posting to
/api/account/security. - Add a field for the user's current password with
autocomplete="current-password". - Add a field for the user's new password with
autocomplete="new-password"andminlength="12". - Add a field for the SMS 2FA code with
autocomplete="one-time-code"and numeric inputmode. - Verify that each input uses matching semantic
<label>elements withforassociations.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Using Custom Non-Standard Names as Autocomplete: Writing
autocomplete="my-custom-phone"has zero effect. Browsers only recognize standardized tokens specified in the WHATWG specification. - Using
autocomplete="off"on Password Fields: Thinkingautocomplete="off"stops password theft. In reality, it hinders security by discouraging users from using password managers with generated 30-character random passwords. - Confusing
namewithgiven-name: Usingautocomplete="name"on a field labeled "First Name" will cause the browser to insert the user's complete full name (first + last) into the first name box. Usegiven-nameinstead.
๐ก Pro Tips
- Pair
one-time-codewith WebOTP API: Combiningautocomplete="one-time-code"with the JavaScript WebOTP API (navigator.credentials.get({ otp: { transport: ['sms'] } })) provides seamless programmatic verification without user typing. - Double Checkout Conversion Rates: E-commerce case studies consistently show that implementing full WHATWG
autocompletetokens on checkout fields cuts checkout completion times by 65% and reduces cart abandonment significantly.
๐ Key Takeaways
- The
autocompleteattribute provides machine-readable hints to browser autofill engines and password managers. - Implementing standard
autocompletetokens satisfies WCAG 2.1 Success Criterion 1.3.5 (Identify Input Purpose). - Use
current-passwordfor logins andnew-passwordfor registration/reset screens. - Use
one-time-codeon 2FA/OTP inputs to enable mobile SMS keyboard suggestions. - Prefix tokens with
shippingorbillingto disambiguate multi-address checkout pipelines. - --