Select an element with empty class attribute (class=””) using CSS?

Provided the class attribute is present as you say you can use the attribute selector like this:

jsFiddle

<a class="" href="https://stackoverflow.com/questions/16353893/...">asd</a>

a[class=""] {
    color: red;
}

If you want this to work when there is no class attribute present on the element you can use :not([class]).

jsFiddle

<a href="https://stackoverflow.com/questions/16353893/...">asd</a>

a:not([class]) {
    color: red;
}

These can then be combined together to handle both cases.

jsFiddle

<a href="https://stackoverflow.com/questions/16353893/...">asd</a>
<a class="" href="https://stackoverflow.com/questions/16353893/...">asd</a>

a[class=""],
a:not([class]) {
    color: red;
}

Leave a Comment