For more tips like this, sign up to the weekly newsletter!
Use the autocomplete attribute to control how autofill works
Browsers can autofill not only password fields but also addresses, names, telephone numbers, and a whole lot of other things.
To help the browser figure out what data should go to which fields, you can use the autocomplete=""
property.
For example, this hints the browser to offer a telephone number to be autofilled to this input:
<input autocomplete="tel">
For a complete list of autofillable values, see the specification.
How to turn it off?
What if you don't want autofill, for example, for login forms?
Simply setting autocomplete="off"
does not prevent the browser from filling in login forms. You can use some workarounds yourself or use a jQuery plugin that does them for you.
Try it
References
- https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-field
- https://cloudfour.com/thinks/autofill-what-web-devs-should-know-but-dont/
- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-autocomplete
- https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion#The_autocomplete_attribute_and_login_fields