Attribute name pattern (attr-pattern)

Require attributes to match configured patterns. This rule is case-insensitive, for matching case use attr-case.

Rule details

Examples of incorrect code for this rule:

<p foo_bar="baz"></p>
error: Attribute "foo_bar" should match /[a-z0-9-:]+/ (attr-pattern) at inline:1:4:
> 1 | <p foo_bar="baz"></p>
    |    ^^^^^^^

1 error found.

Examples of correct code for this rule:

<p foo-bar="baz"></p>


This rule takes an optional object:

  "pattern": "[a-z0-9-:]+",
  "ignoreForeign": true


Pattern to match.

Multiple patterns can be set as an array of strings. With multiple patterns the attribute must match at least one pattern to be considered valid.

For instance, when configured with {"pattern": ["[a-z0-9-]+", "myprefix-.+"]} attributes can be either letters and digits or anything with the myprefix- prefix:

<p foo-bar-123></p>
<p myprefix-foo_123!></p>


By default attributes on foreign elements (such as <svg> and <math>) are ignored as they follow their own specifications.

Disable this option if you want to validate attributes on foreign elements as well.

Version history