I noticed some code in our projects using CSS class names such as red
, black
or float
.
I want to provide some information for people so they know to avoid it.
Is there a common name for that code smell so I can reference it?
They are "non-semantic class names". That is, a class name should represent an idea, not how it should look or be laid out. That allows you to change the look and feel with a change in one place instead of everywhere that referenced class names red, black, float
There is one exception that exists for hacking purposes, for example if you need something that is implemented in different ways across browsers (the prefixed ones like gradients and others) and you don't want to repeat it every where. However, the better solution is to use SASS mixins.
.
item
is not on the same league (of badness) as classes named red, blue, float
. Pick your battles. If it's div.item
inside a div.tasks
, it's not too bad, although I would prefer to use ul.tasks
and li
and not need an div.item
Commented
Apr 23, 2013 at 22:53
item
is pretty meaningless, but it is hard to formalize. Anyway, it seems there are no common names for CSS smells anyway, so I'll accept your answer -- non-semantic is as specific as it gets.
Commented
Apr 23, 2013 at 23:00