Skip to main content

selector-max-attribute

Limit the number of attribute selectors in a selector.

    [rel="external"] {}
/** ↑
* This type of selector */

Each selector in a selector list is evaluated separately.

note

In versions prior to 17.0.0, this rule would evaluate functional pseudo-classes separately, such as :not() and :is(), and resolve nested selectors (in a nonstandard way) before counting.

Options

number

Specify a maximum attribute selectors allowed.

Given:

{
"selector-max-attribute": 2
}

The following patterns are considered problems:

[type="number"][name="quality"][data-attribute="value"] {}
[type="number"][name="quality"][disabled] {}

The following patterns are not considered problems:

[type="text"] {}
[type="text"][name="message"] {}
[type="text"][disabled] {}
[type="text"][name="message"] {
& [disabled] {}
}

Optional secondary options

ignoreAttributes

{ "ignoreAttributes": ["array", "of", "attributes", "/regex/"] }

Given:

{
"selector-max-attribute": [0, { "ignoreAttributes": ["/^data-my-/", "dir"] }]
}

The following patterns are not considered problems:

[dir] [data-my-attr] {}
[dir] [data-my-other-attr] {}