👀 Live Preview
Login form with controlled autofill:

The autocomplete attribute is a handy feature in HTML that allows developers to control whether a browser should automatically complete user input in a form. This attribute is applied to form elements and can be particularly useful for enhancing user experience and streamlining data entry.
Enable or disable.
email, name, tel.
current / new.
input, form, textarea.
Set dynamically.
When to use off.
autocompleteThe primary purpose of the autocomplete attribute is to specify whether a browser should provide autocomplete suggestions for a particular input field. By default, most browsers have autocomplete enabled, which means they try to predict and fill in values based on the user’s previous inputs. However, there are situations where you might want to control or disable this behavior.
Instead of generic on, use tokens like email or name so browsers and password managers fill the correct data.
Add autocomplete to a form control with on, off, or a semantic token:
<input type="email" autocomplete="email">input, select, textarea, and form.off to disable autofill for a specific field.autocomplete on <form> applies to all fields unless overridden.The autocomplete attribute accepts various values to define different behaviors. The two main values are:
Common semantic tokens include:
name, email, tel, street-address — Contact and address fields.current-password — Login password field.new-password — Registration or password-change field.one-time-code — SMS or email verification codes.<input autocomplete="off">
<input autocomplete="email">
<input type="password" autocomplete="current-password">
<input type="password" autocomplete="new-password">| Field Type | Suggested Value | Notes |
|---|---|---|
| Login password | current-password | Password manager autofill |
| New password | new-password | Sign-up or reset forms |
email | Better than generic on | |
| OTP / captcha | off or one-time-code | Do not reuse saved values |
| Credit card (sensitive) | cc-number or off | Follow PCI guidelines |
| Applicable elements | input, form, textarea | Form controls |
| Element | Supported? | Notes |
|---|---|---|
<input> | Yes | Most common use |
<textarea> | Yes | Multi-line text |
<select> | Yes | Limited autofill effect |
<form> | Yes | Sets default for child fields |
on/off form example, dynamic new-password, and semantic token values.
Login form with controlled autofill:
Here’s a simple example of how to use the autocomplete attribute in an HTML form:
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" autocomplete="off">
<label for="password">Password:</label>
<input type="password" id="password" name="password" autocomplete="current-password">
<input type="submit" value="Submit">
</form>In this example, the autocomplete attribute is set to off for the username input field, disabling autofill suggestions for that field. The password field uses current-password so password managers can offer the saved login credential.
You can also dynamically set the autocomplete attribute using JavaScript. This can be useful when you want to customize autocomplete behavior based on certain conditions or user interactions. Here’s a brief example:
<input type="password" id="dynamicField">
<script>
document.getElementById("dynamicField").autocomplete = "new-password";
</script>In this script, the autocomplete attribute is set to new-password for an input field with the id dynamicField. This prompts password managers to suggest a strong new password during registration.
Use specific tokens so browsers know exactly what data to autofill:
<input type="text" autocomplete="name">
<input type="email" autocomplete="email">
<input type="tel" autocomplete="tel">Semantic tokens describe the field’s purpose. Browsers map them to saved autofill profiles for faster, more accurate form completion.
<label> elements.Choose on, off, or a semantic token per field.
Browser reads the autocomplete hint.
Autofill dropdown or password manager fills the field.
Users complete forms with less typing and fewer errors.
The autocomplete attribute is supported in all modern browsers. Behavior may vary slightly—some browsers ignore off on login fields for usability.
All major browsers honor autocomplete on form controls.
Bottom line: Use semantic tokens and test autofill in Chrome, Firefox, and Safari.
email, name, tel)current-password and new-password for passwordsautocomplete="off" on one-time codes and captchasoff alone for security (browsers may override)on when a specific token existsname attributes (autofill uses them too)off identicallyThe autocomplete attribute is a valuable tool for controlling the autocomplete behavior of form elements in HTML. By understanding and using this attribute appropriately, you can enhance the usability and security of your web forms.
Choose semantic tokens over generic values, use password-specific tokens for credential fields, and reserve off for fields that should never reuse saved data.
autocompleteBookmark these before building your next form.
Enable or disable.
Basicsemail, name, tel.
Semanticcurrent / new.
Security.autocomplete
DynamicFaster forms.
Usabilityinput, textarea, select, and form elements.current-password for login and new-password for sign-up so password managers work correctly.email, name, or street-address give browsers clearer autofill hints.element.autocomplete = "new-password" or use setAttribute at runtime.Practice the autocomplete attribute with login, password, and contact field examples in the Try It editor.
5 people found this page helpful