liveBook · Manning

Autocomplete attribute

As explained in Architecting Accessibility

An HTML attribute that indicates whether and how a browser may automatically complete a form field using stored information.

A form can ask for information a person has already entered elsewhere, such as a name or email address. The autocomplete attribute tells the browser what a field is for so it can offer stored information when available. This can reduce typing effort and input errors. section 6.1.8 section 6.1

Choose a value for the field’s purpose, not just its data type. An input type can identify a date, for example, but does not distinguish a birthday from a credit-card expiry date. For a person’s name, use autocomplete="name" alongside an appropriate input type and a visible label. section 6.1.8 section 6.1.10

A name field

<label for="owner-name">Owner’s name</label> <input id="owner-name" name="owner_name" type="text" autocomplete="name"> section 6.1.10

When a form asks for similar information in different contexts, identify the context too. Shipping and billing postal-code fields, for instance, can use autocomplete="shipping postal-code" and autocomplete="billing postal-code". Separate sections can distinguish repeated fields for different people. section 6.1.8

<input autocomplete="shipping postal-code">
<input autocomplete="billing postal-code"> 

Compare the shipping and billing values when two postal-code fields serve different purposes. section 6.1.8

Authentication fields need the same care. Use autocomplete="username" and autocomplete="current-password" for a login, and autocomplete="new-password" for a new password. These values help the browser fill stored credentials or, depending on the browser, offer help generating a new password rather than filling an existing one. section 7.3.1

How Architecting Accessibility covers it

How deep it goes
Explains field purpose versus input type and demonstrates contextual and authentication values, without detailing browser implementation.
Examples
Uses shipping and billing postal codes, repeated guest names, an owner-name field, and login and registration fields.
What it assumes
Assumes familiarity with HTML input fields while explaining how data type differs from field purpose.
What you can do after
Operate/configure it in HTML forms to request appropriate browser prefill and distinguish existing passwords from new ones.
How it connects
Connects autocomplete to input type, inputmode, form accessibility, and password managers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting Accessibility. The section links point to the parts of the book it draws on.