Require autocomplete attribute to be valid

Rule ID:
valid-autocomplete
Category:
HTML Syntax and concepts
Standards:
  • HTML5

The HTML5 autocomplete attribute can be used in different ways:

Further the space-separated tokens must appear in the following order:

Typical field names would be:

For a full list of valid field names refer to the HTML5 standard Autofill section.

Some field names can only be used on specific input controls, for instance:

Again, refer to the Autofill section in the standard for a full table of allowed controls.

Rule details

Examples of incorrect code for this rule:

<input type="text" autocomplete="foo">
<input type="text" autocomplete="name billing">
<input type="text" autocomplete="street-address">
error: "foo" is not a valid autocomplete token or field name (valid-autocomplete) at inline:1:34:
> 1 | <input type="text" autocomplete="foo">
    |                                  ^^^
  2 | <input type="text" autocomplete="name billing">
  3 | <input type="text" autocomplete="street-address">


error: "billing" must appear before "name" (valid-autocomplete) at inline:2:39:
  1 | <input type="text" autocomplete="foo">
> 2 | <input type="text" autocomplete="name billing">
    |                                       ^^^^^^^
  3 | <input type="text" autocomplete="street-address">


error: "street-address" cannot be used on <input type="text"> (valid-autocomplete) at inline:3:34:
  1 | <input type="text" autocomplete="foo">
  2 | <input type="text" autocomplete="name billing">
> 3 | <input type="text" autocomplete="street-address">
    |                                  ^^^^^^^^^^^^^^


3 errors found.

Examples of correct code for this rule:

<input type="text" autocomplete="name">
<input type="text" autocomplete="billing name">
<textarea autocomplete="street-address"></textarea>

References

Version history