Preventing a browser from storing passwords is generally a user preference, and as such, it’s controlled by browser settings rather than by HTML or JavaScript. However, you can use the autocomplete attribute to suggest to the browser not to save passwords for a specific input field.
To do this we write
<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="new-password">
<input type="submit" value="Submit">
</form>
to create a form.
The autocomplete="off"
attribute on the username field suggests to the browser that it should not remember previously entered values for this field.
The autocomplete="new-password"
attribute on the password field suggests to the browser that it should not suggest previously entered passwords for this field, and it should prompt the user to enter a new password if available.
However, it’s important to note that browsers may choose to ignore these suggestions for security reasons, especially in the case of password fields. Users also have control over their browser’s settings, and they may choose to ignore these suggestions or enable password saving globally.
Therefore, while you can use these attributes to suggest to the browser not to save passwords, it’s ultimately up to the browser and user whether passwords are saved or not. Additionally, JavaScript cannot directly control browser settings related to password saving.