Boolean attribute style

Rule ID:
attribute-boolean-style
Category:
Style
Standards:
  • HTML5
Fixable:
No

Boolean attributes are attributes without a value and the presence of the attribute is considered a boolean true and absence a boolean false. The HTML5 standard allows three styles to write boolean attributes:

This rule requires a specific style when writing boolean attributes. Default is to omit the value.

This rule does not have an effect on regular attributes with empty values, see attribute-empty-style instead.

Rule details

Examples of incorrect code for this rule:

<input required="" />

<input required="required" />
error: Attribute "required" should omit value (attribute-boolean-style)
> 1 | <input required="" />
    |        ^^^^^^^^
  2 |
  3 | <input required="required" />


error: Attribute "required" should omit value (attribute-boolean-style)
  1 | <input required="" />
  2 |
> 3 | <input required="required" />
    |        ^^^^^^^^


2 errors found.

Examples of correct code for this rule:

<input required />

Options

This rule takes an optional object:

{
  "style": "omit"
}

Style