I'm pretty sure I remember that adding the autocomplete
attribute to an <input>
element used to work as expected, ie adding autocomplete="email"
would mean the autocomplete would just show previously entered email addresses.
However, both Firefox and Chrome seem to only be using name
and id
to decide what to autocomplete with, and ignoring autocomplete unless it is saying to not autocomplete at all.
In my tests, the following doesn't do anything:
<input type="email" autocomplete="email">
<input type="email" title="email" autocomplete="email">
<input type="text" autocomplete="email">
<input type="email" autocomplete="on">
<input type="email" autocomplete="on email">
<label for="emai">Email</label>
<input type="email" id="emai" autocomplete="email">
The following autocomplete with the autocomplete value (though seem to be getting that value from elsewhere)
<input type="email" name="email" autocomplete="email">
<input type="email" id="email" autocomplete="email">
<input type="email" id="email" autocomplete="family-name">
<input type="email" name="email">
<input type="text" name="email" autocomplete="email">
<input type="email" id="username" autocomplete="family-name">
And these autocomplete with something other than the autocomplete value
<input type="email" id="email" autocomplete="family-name">
<input type="email" id="username" autocomplete="family-name">
<input type="email" id="username" autocomplete="email">
<input type="email" id="username" autocomplete="honorific-prefix">
None of the above tests suggest that the autocomplete attribute is doing anything at all. As I say, I'm sure it used to work as expected.
Things I would appreciate your thoughts on:
autocomplete
still a valid attribute - caniuse only seem to mention the on/off values, even though Mozilla suggest the other values exist.autocomplete is not ignored, but...
Modern browsers don’t any more rely solely on the autocomplete
attribute but instead prioritize name
and id
(to a point where even "off"
is ignored). However, autocomplete is still useful for specific cases. Also:
disabled
or ARIA attributes like role="none"
or role="presentation"
make the element non-interactive, disabling autocomplete
entirely
autocomplete="off"
is sometimes overridden (use something more random)
some browsers require the interactive elements to be inside a <form>
to work properly
In short: in a form, match id
with name
and label.for
, use the proper autocomplete values and avoid role="none"
or disabled
<form>
<label for="email">Email</label>
<input type="email" id="email" name="email" autocomplete="email">
<input type="password" name="password" autocomplete="current-password">
</form>