HTML: input autocomplete
The autocomplete attribute tells the browser what kind of previously entered information can help fill a form field.
What you will learn
- How to use common autocomplete tokens
- How list and datalist provide suggestions
- Why autocomplete helps usability and accessibility
Common tokens
<label for="email">Email</label>
<input id="email" name="email" type="email" autocomplete="email">
<label for="given-name">First name</label>
<input id="given-name" name="given-name" autocomplete="given-name">Use a token that describes the data, such as email, name, street-address, or one-time-code. Correct tokens let browsers and password managers offer useful help.
Suggestions with datalist
<label for="browser">Browser</label>
<input id="browser" name="browser" list="browsers">
<datalist id="browsers">
<option value="Firefox">
<option value="Chrome">
</datalist>The list value must match the datalist id. Suggestions do not necessarily restrict the user to only those values.
Common mistakes
- Do not disable autocomplete just to make a form look more secure; use an appropriate token and protect data on the server.
- Keep a visible label and a meaningful
namealongside autocomplete. - Do not use a suggestion list as a replacement for server-side validation.