The HTML autocomplete attribute
The HTML autocomplete attribute tells browsers what a field is for, such as email or new-password. The value off asks for no suggestions, but many browsers still fill login fields. Set on a <form>, it becomes the default for that form's fields.
Overview
The HTML autocomplete attribute tells the browser whether to autofill a field and what data it expects. <input> fields that take a text or numeric value can carry it, and so can <select>, <textarea> and whole <form> elements. Its value is on, off or a list of tokens.
Password fields have tokens of their own. Use current-password on a sign-in form and new-password where someone creates or changes a password. Browsers may use new-password to avoid filling in the existing password and to offer help creating a secure one.
Several tokens can describe one field, in a fixed order. An optional section- name comes first, then an optional shipping or billing, and then the field name, as in shipping postal-code. A phone or email field name can directly follow a contact type such as work, as in work email.
A list in any other order is invalid, and the field falls back to the on or off setting of its form. A <form autocomplete="off"> sets that default for every field without a value of its own, and a field with no form defaults to on.
Syntax
<label for="email">Email</label>
<input type="email" id="email" name="email" autocomplete="email">
<label for="pw">New password</label>
<input type="password" id="pw" name="pw" autocomplete="new-password">
Values
| Value |
|---|
on, off, or a specific token such as email, name, current-password, one-time-code. |
Example
<label for="list">autocomplete value to test</label><br>
<select id="list">
<option>shipping postal-code</option>
<option>postal-code shipping</option>
<option>section-gift shipping street-address</option>
<option>work email</option>
<option>email work</option>
<option>home postal-code</option>
</select>
<p id="out" role="status"></p>
<p>Pick each value to see whether the browser accepts its token list.</p>
<script>
const list = document.getElementById('list');
const field = document.createElement('input');
function check() {
field.setAttribute('autocomplete', list.value);
document.getElementById('out').textContent = field.autocomplete
? 'Valid. The autocomplete property reads "' + field.autocomplete + '".'
: 'Invalid. The autocomplete property reads an empty string.';
}
list.addEventListener('change', check);
check();
</script>
More Examples
Best practices
- Match each autocomplete token to a fitting input type. Each token is allowed only on suitable controls, so validators reject email on a password field and postal-code on an email field.
- Ask for a whole name with the single
nametoken when you can. Narrower fields such as given-name tend to expose Western biases. - Don't invent values such as
nopeto block suggestions. The browser then can't tell what the field is for, so it can't offer relevant suggestions either. - End the list with
webauthn, as inusername webauthn, when your sign-in page asks for passkeys through a conditionalnavigator.credentials.get()call. Chrome 108, Firefox 122 and Safari 16.4 added support for it.
Accessibility
Valid autocomplete tokens help people with motor or cognitive disabilities fill in forms with less typing. They satisfy WCAG 2.2 Success Criterion 1.3.5, Identify Input Purpose, at Level AA, and the criterion can still be met when a form turns autocompletion off, if fields carry their own tokens.























