When all you've got is an ID selector...

widget {

...

} Now we have an ID in our CSS, and that is not a good precedent to set. Instead, we should do something like this:

[id="widget"] { ... }

This is an attribute selector. This is not selecting on an ID per se, but on an element with an attribute of id which also has a certain value. This particular selector is basically saying Hey, find me an element with an attribute called id which has a value of widget.

The beauty of this selector is that it has the exact same specificity as a class, so we’re selecting a chunk of the DOM based on an ID, but never actually increasing our specificity beyond that of our classes that we’re making liberal use of elsewhere.

But this is a hack.

This article is my 20th oldest. It is 134 words long