Disable Browser Password Memory in HTML Forms
In this article
To stop browsers from offering to save passwords in your HTML forms, you need to add specific attributes to the <form> and <input> elements. This guide explains the exact code changes and the limitations you should know.
What You'll Need
- Access to the HTML source of your web page or form.
- A basic text editor (like Notepad, VS Code, or Sublime Text).
- Familiarity with HTML form elements (
<form>,<input>).
Step-by-Step
- Locate the form element. Find the
<form>tag in your HTML. It wraps all the input fields. - Add the
autocomplete="off"attribute to the form. Inside the opening<form>tag, addautocomplete="off". For example:<form action="/login" method="post" autocomplete="off">. This is the primary method to disable password saving for the entire form. - Add
autocomplete="off"to password inputs. For each password field, addautocomplete="off"directly to the<input>tag. Example:<input type="password" name="pass" autocomplete="off">. This reinforces the form-level setting. - Use
autocomplete="new-password"for password fields. In many modern browsers,autocomplete="off"is ignored for password fields. Instead, useautocomplete="new-password"on password inputs to signal that this is a new password field, which prevents the browser from offering to save it. Example:<input type="password" name="pass" autocomplete="new-password">. - For username/email fields, use a non-standard value. To prevent the browser from suggesting saved usernames, set
autocomplete="off"or a random value likeautocomplete="nope"on the username/email input. However, be aware that some browsers ignore this for login forms. - Test in multiple browsers. After making changes, test the form in Chrome, Firefox, Safari, and Edge. Each browser may behave differently.
Common Mistakes
- Only using
autocomplete="off"on the form. Many browsers ignore this for password fields, so you must also apply it to the input elements. - Using
autocomplete="off"on password fields. As mentioned, this is often ignored. Useautocomplete="new-password"instead. - Forgetting to test. Each browser has its own rules. What works in Chrome may not work in Firefox.
- Assuming it works for all browser versions. Older browsers may not support these attributes, so always test.
Tips
- Combine form-level and input-level attributes. Use both
autocomplete="off"on the form andautocomplete="new-password"on password fields for best results. - Use a random autocomplete value for username fields. Some developers use
autocomplete="nope"orautocomplete="false"to confuse the browser. - Consider the user experience. Disabling password saving can frustrate users who rely on password managers. Only do this when necessary (e.g., for sensitive forms like banking).
- For login forms, consider using a password manager policy. Instead of disabling saving, you can encourage users to use a password manager.
Troubleshooting
- Browser still offers to save password. This is common. Try using
autocomplete="new-password"on the password field and ensure the form hasautocomplete="off". Also, clear the browser's saved passwords for your site in its settings to test fresh. - Username field still shows suggestions. Set
autocomplete="off"on the username input, but note that some browsers ignore this for login forms. You can try a random value likeautocomplete="off"orautocomplete="random". - Works in one browser but not another. This is expected. Each browser has its own heuristics. Use the
autocomplete="new-password"trick, which is widely supported. - Password field is pre-filled with a saved password. This happens when the browser ignores your attributes. Clear saved passwords for your site in browser settings and try again.
Frequently Asked Questions
Does autocomplete="off" work in all browsers?
No. Chrome and Firefox often ignore it for password fields. Safari respects it more, but it's not guaranteed. Using autocomplete="new-password" is more reliable.
What is the difference between autocomplete="off" and autocomplete="new-password"?
autocomplete="off" tells the browser not to suggest or save values. autocomplete="new-password" tells the browser this is a new password field, so it should not offer to save it (and may even suggest a strong password).
Can I disable password saving for just one field?
Yes, you can set the attribute on individual inputs. However, for password fields, use autocomplete="new-password" instead of off.
Will disabling password saving affect my site's security?
Not directly, but it may encourage users to use weaker passwords or write them down. It's often better to let users save passwords in a password manager.
Is there a JavaScript solution?
You can dynamically set the autocomplete attribute via JavaScript, but it's not more effective than HTML. Some developers use a fake hidden password field to trick the browser, but that's not recommended.
Does this work for iframes?
It can, but browser behavior may vary. The same attributes apply, but test thoroughly.