autocomplete HTML attribute
The HTML autocomplete attribute lets web developers specify what if any permission the user agent has to provide automated assistance in filling out form field values, as well as guidance to the browser as to the type of information expected in the field.
It is available on <input> elements that take a text or numeric value as input, <textarea> elements, <select> elements, and <form> elements.
Try it
<label for="firstName">First Name:</label>
<input name="firstName" id="firstName" type="text" autocomplete="given-name" />
<label for="lastName">Last Name:</label>
<input name="lastName" id="lastName" type="text" autocomplete="family-name" />
<label for="email">Email:</label>
<input name="email" id="email" type="email" autocomplete="off" />
label {
display: block;
margin-top: 1rem;
}
Description
The autocomplete attribute provides a hint to the user agent specifying how to, or indeed whether to, prefill a form control. The attribute value is either the keyword off or on, or an ordered list of space-separated tokens.
<input autocomplete="off" />
<input autocomplete="on" />
<textarea autocomplete="shipping street-address"></textarea>
<input autocomplete="section-user1 billing postal-code" />
If an <input>, <select> or <textarea> element has no autocomplete attribute, the browser will use the autocomplete attribute of the element's owning form. The owning form is either the <form> matching the id specified by the form attribute of the element (if present) or, more commonly, the <form> the element is nested in.
Note:
In order to provide autocompletion, user-agents might require <input>/<select>/<textarea> elements to:
- Have a
nameand/oridattribute - Be descendants of a
<form>element - Be owned by a form with a submit button
If the same list of tokens is used in more than one form control, the user-agent will autocomplete all occurrences of the same autocomplete value with the same data value.
Some tokens may be used more than once with potentially different expected values, such as the zip-code token in a form that contains both shipping and billing addresses. Including multiple different tokens in a space-separated list causes the associated form controls to be given unique autocomplete values: in this case, autocomplete="shipping zip-code" and autocomplete="billing zip-code".
Some autocomplete values may need to be re-used multiple times. For example, a form may contain multiple shipping addresses and therefore multiple occurrences of "shipping zip-code" while still expecting different values. To make the autocomplete value unique in these cases, the first token in the space-separated list of tokens can be a section-* token, where the token's first eight characters are always the string "section-", followed by an alphanumeric string. All form fields given the section-* token with the same alphanumeric string belong to the same named group.
If including the autocomplete attribute on hidden input elements (<input type="hidden">), its value must be an ordered list of space-separated tokens; the on and off keywords are not allowed.
The source of the suggested values is generally up to the browser; typically values come from past values entered by the user, but they may also come from pre-configured values. For instance, a browser might let the user save their name, address, phone number, and email addresses for autocomplete purposes. The browser may also offer the ability to save encrypted credit card information, for autocompletion following an authentication procedure.
Note:
The autocomplete attribute also controls whether Firefox will — unlike other browsers — persist the dynamic disabled state and (if applicable) dynamic checkedness of an <input> element, <textarea> element, or entire <form> across page loads. The persistence feature is enabled by default. Setting the value of the autocomplete attribute to off disables this feature. This works even when the autocomplete attribute would normally not apply by virtue of its type. See Firefox bug 654072.
Value
The attribute value is either the keyword off or on, or a space-separated <token-list> that describes the meaning of the autocompletion value.
off-
The browser is not permitted to automatically enter or select a value for this field. It is possible that the document or application provides its own autocomplete feature, or that security concerns require that the field's value not be automatically entered.
Note: In most modern browsers, setting
autocompleteto"off"will not prevent a password manager from asking the user if they would like to save username and password information, or from automatically filling in those values in a site's login form. See Managing autofill for login fields. on-
The browser is allowed to automatically complete the input. No guidance is provided as to the type of data expected in the field, so the browser may use its own judgement.
<token-list>-
An ordered set of