Full answer
The autocomplete attribute tells the browser, a password manager or an assistive tool what each field is for. With the right token, the browser can fill a name, address or code in one step. This saves time, reduces mistakes and helps people with motor or memory difficulties. It is also part of accessibility rules, which ask that fields about the user can be filled automatically.
Common tokens:
- Names:
name,given-name,family-name. - Contact:
email,tel. - Address:
street-address,address-line1,postal-code,country. - Payment:
cc-name,cc-number,cc-exp,cc-csc. - Accounts:
username,current-passwordfor sign-in andnew-passwordfor sign-up or a password change. These help password managers choose to fill or to suggest a strong password. one-time-codelets a phone offer the code from a text message.
Tokens can have a section or purpose in front, such as shipping postal-code and billing postal-code, to separate two groups of address fields on one page. off asks the browser not to fill, but browsers may ignore it for login fields, and it can harm users, so use it only for fields such as a search box for a one-time value.
Tokens work together with a good name and a connected label. A visible label is still needed.
Each field has a token that matches its meaning, and each has a label connected with for. The check reads the attributes, because browser autofill needs saved data and a real profile.
Test with a real browser profile and a password manager, since the fill behaviour belongs to the browser.
<form id="f">
<label for="gn">First name</label>
<input id="gn" name="first" autocomplete="given-name">
<label for="em">Email</label>
<input id="em" name="email" type="email" autocomplete="email">
<label for="pw">New password</label>
<input id="pw" name="password" type="password" autocomplete="new-password">
<label for="otp">Code from SMS</label>
<input id="otp" name="otp" inputmode="numeric" autocomplete="one-time-code">
<label for="zip">Shipping postal code</label>
<input id="zip" name="zip" autocomplete="shipping postal-code">
</form>The check read the attributes and the label links. Browser autofill needs a saved profile and was not tested. Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- Tokens describe the meaning of a field.
- Use current-password and new-password for accounts.
- one-time-code helps with SMS codes.
- Prefix shipping or billing to separate groups.
- Keep real labels. Test with a real profile.
Common mistakes
- Setting autocomplete="off" on login and checkout fields, which breaks password managers.
- Using the same token for shipping and billing fields on one page with no section prefix.
- Using a placeholder or a made-up name instead of a visible label and a correct token.
Follow-ups
- How do you separate shipping and billing fields on one page?
- When is autocomplete="off" reasonable?
Tips
- Link tokens to accessibility and to fewer typing errors.
- Name new-password and one-time-code. They are the ones people forget.