Evil Closet Monkey Evil Closet Monkey - 1 year ago 70
CSS Question

Determining if an attribute is absent via CSS Attribute Selector?

Can the CSS Attribute Selector, and/or combination of selectors, be used to determine if an attribute is absent?

An attribute selector can be used to test if the attribute is blank:


... but the attribute still must be present in order for that to pass. If the HTML tag does not have the attribute at all, the above selector does not pass.

Can a selector be written in a way that it would pass if the attribute is not there?

Answer Source

Something like this?

div:not([aria-label]) {
  color: red;  
<div aria-label="test">


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download