Is there a CSS selector for elements lacking an attribute?

I understand that css rules can target elements specified by attribute values, e.g.:

input[type="text"] {}

Can I make a rule that targets elements which omit a certain attribute? For example, can I target elements that lack an href or elements that don't specify a type?


You can follow this pattern:

a:not([href])
input:not([type])

The attribute selector is used to select elements with the specified attribute.

:not is supported in all modern browsers and IE9+, if you need IE8 or lower support you're out of luck.


For links you can simply use:

a { color: red; }
a:link { color: green; }

fiddle: http://jsfiddle.net/ZHTXS/ no need for javascript.

For form attributes, use the not attribute pattern noted above input:not([type]) and if you need to support older versions of IE, I'd probably add a class and use an IE specific style sheet linked with conditional comments.