HTML Attributes
HTML <form> autocomplete Attribute
The autocomplete attribute on a <form> sets the default autofill behaviour for all fields inside it. Individual fields can still override that default.
The <form> autocomplete Attribute
When placed on the <form> element, autocomplete defines the default for every input, textarea and select in the form. Individual fields can still override this by setting their own autocomplete attribute, giving you form-wide control with per-field exceptions.
Syntax
Syntax: <form autocomplete="on"> or <form autocomplete="off">. The default is on when the attribute is not specified.
<form autocomplete="off"> ... </form>Example
Run the example. Autofill is turned off for the whole form, but the email field re-enables it for itself.
<!DOCTYPE html>
<html>
<body>
<form autocomplete="off">
<label for="code">One-time code</label><br>
<input type="text" id="code" name="code" placeholder="Do not autofill"><br><br>
<label for="mail">Email</label><br>
<input type="email" id="mail" name="email" autocomplete="email"
placeholder="Autofill allowed here"><br><br>
<button type="submit">Continue</button>
</form>
</body>
</html>Attribute Values
| Value | Description |
|---|---|
| on | Fields may be autofilled by the browser (the default) |
| off | The browser should not autofill fields in this form by default |
Setting autocomplete="off" is only a hint. Browsers may ignore it for login and password fields to keep password managers working, so never rely on it for security.
Key Takeaways
- autocomplete on a <form> sets the default for all its fields.
- Individual inputs can override the form-level value.
- The default is on when the attribute is absent.
- off is only a hint and may be ignored for logins.
- Never rely on off for security or privacy.
