References

Beginner-friendly references for web development, with live, editable examples.

The HTML autocomplete attribute

Attribute All modern browsers
In short

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

Live 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 name token when you can. Narrower fields such as given-name tend to expose Western biases.
  • Don't invent values such as nope to 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 in username webauthn, when your sign-in page asks for passkeys through a conditional navigator.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.

Frequently asked questions

What does autocomplete=off do?
Setting autocomplete to off asks the browser not to save the field's value or suggest past entries. It also stops the browser from caching the form's values in session history, which is what refills the fields after someone presses Back.
Why do browsers ignore autocomplete=off on login forms?
Many browsers still offer to save and fill a login when autocomplete is off. Built-in password management is generally seen as a net gain for security, and browsers may let users override off.
How can autocomplete stop a browser from filling in a password?
Use autocomplete=new-password on pages where someone sets another person's password. It is only a hint, and some browsers may not follow it.
What is autocomplete one-time-code?
The autocomplete token one-time-code marks a field for a sign-in code sent by SMS, email or an app. It is valid on text, search and password inputs, but not on number or tel inputs.
Why doesn't the autocomplete attribute fill my field?
Browsers may need more than the autocomplete attribute. Autofill might require a name or id, a form element around the field, and a submit button in that form.
How do I turn off autocomplete for one field only?
Put autocomplete=off on that field and leave the form's own setting alone. If suggestions keep appearing, change the field's name attribute.