The HTML specification
The HTML autocomplete attribute can be used to hint the browser how to prefill an address form based on earlier user input. This can be achieved by assigning space separated, case-insensitive autofill detail tokens to the autocomplete attribute. Like so:
<label>Street address
<input type="text" name="address" autocomplete="address-line1">
</label>The HTML specification lists the following tokens to indicate the browser the purpose of a form field, hinting the browser to prefill with suitable content. The tokens require its associated form control group being Text, if not stated otherwise in the //comment.
namehonorific-prefixgiven-nameadditional-namefamily-namehonorific-suffixnicknameusername//Username
new-password//Passwordcurrent-password//Passwordone-time-code//Passwordorganization-titleorganizationstreet-address//Multiline textaddress-line1address-line2address-line3
address-level4address-level3address-level2address-level1countrycountry-namepostal-codecc-name//cc-…indicates payment instrument data, like for credit cards.cc-given-namecc-additional-namecc-family-name
cc-numbercc-exp//monthcc-exp-month//Numericcc-exp-year//Numeric
cc-csccc-typetransaction-currencytransaction-amount//Numericlanguagebday//Datebday-day//Numericbday-month//Numericbday-year//Numeric
sexurl//Urlphoto//Url
If none of the above tokens is used, you can use the following tokens in the given order:
home, meaning the field is for contacting someone at their residencework, meaning the field is for contacting someone at their workplacemobile, meaning the field is for contacting someone regardless of locationfax, meaning the field describes a fax machine's contact detailspager, meaning the field describes a pager's or beeper's contact details
and combine them with
tel//Teltel-country-codetel-nationaltel-area-codetel-localtel-local-prefixtel-local-suffixtel-extensionemail//Usernameimpp//Url
For example:
<label>Email address
<input type="email" name="email" autocomplete="home email">
</label>All the above tokens can optionally be used together with either shipping or billing to denote if the form field is part of a shipping address or if it belongs to the billing address. And there are section- tokens, that can be used to group, for example, two shipping addresses in the form section-address1 and section-address2.
According to MDN
In order to provide autocompletion, user-agents might require
<input>/<select>/<textarea>elements to:
- Have a name and/or id attribute
- Be descendants of a
<form>element- Be owned by a form with a submit button