HTML & CSS Interview Question #41

What is the purpose of the autocomplete attribute?

Forms, Validation, Metadata, Media, Responsive Images & Accessibility Mid-Level Intermediate

Quick Interview Answer

autocomplete tells the browser what kind of information a form field represents and whether automatic completion is appropriate. Standard tokens include name, email, tel, current-password, new-password, street-address, and many others.

Detailed Explanation

autocomplete tells the browser what kind of information a form field represents and whether automatic completion is appropriate. Standard tokens include name, email, tel, current-password, new-password, street-address, and many others.

Using correct tokens can improve form completion, especially on mobile devices and for users who rely on password managers. Sensitive workflows should use the standardized tokens rather than inventing arbitrary values.

Code Example

<label for="email">Email</label>
<input id="email"
       name="email"
       type="email"
       autocomplete="email">

<label for="password">Password</label>
<input id="password"
       name="password"
       type="password"
       autocomplete="current-password">