Autofilling the address form

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.

If none of the above tokens is used, you can use the following tokens in the given order:

and combine them with

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:

The address form example

See the Pen Untitled by Ulf Schneider (@ulfschneider) on CodePen.

Comments