Disallow whitespace between attribute key and value

Rule ID:
attr-delimiter
Category:
HTML Syntax and concepts
Standards:
  • HTML5

While technically allowed by the HTML5 specification this rule disallows the usage of whitespace separating the attribute key and value, i.e. before or after the = character.

Usage of whitespace in this context is typically a sign of typo or unintended behaviour. For instance, consider the following markup:

<input name= disabled>

As the HTML5 specification allows whitespace after = this is to be interpreted as <input name="disabled"> which is has a completely different meaning than the developer probably intended. This could have been generated from a templating langage where the value supposted to be bound to name was not set:

<input name=<%= fieldName %> disabled>

Rule details

Examples of incorrect code for this rule:

<input name= "my-field">
<input name ="my-field">
error: Attribute value must not be delimited by whitespace (attr-delimiter) at inline:1:12:
> 1 | <input name= "my-field">
    |            ^^
  2 | <input name ="my-field">


error: Attribute value must not be delimited by whitespace (attr-delimiter) at inline:2:12:
  1 | <input name= "my-field">
> 2 | <input name ="my-field">
    |            ^^


2 errors found.

Examples of correct code for this rule:

<input name="my-field">