DEV Community

Discussion on: Why you should use semantic naming in CSS

Collapse
 
alohci profile image
Nicholas Stimpson

I'm not convinced about the semantic-ness of "sidebar". Still seems presentational to me, since on some devices you might not want it at the side. The problem is of course that the sidebar often contains a bag of bits, and while each bit may have a semantic name, the bag doesn't. It's impossible to suggest a better name without knowing what bits a given bag contains, but in many cases, referring to the element as an <aside> within the context of a given document element ancestry might work out better.

Collapse
 
sargalias profile image
Spyros Argalias • Edited

Yeah perfectly good suggestion, thank you. You've got some good reasoning behind that.

At the end of the day you and your team will decide what makes the most sense to use.

There are two main motivations behind semantic class names:

  • The principle of least astonishment (the name is a useful, non-surprising label to the programmer).
  • Minimising future changes, because changing things is error-prone. A semantic name just happens to be the thing that is the least likely to change, compared to say color-red which could change all the time.

You've got the right idea to challenge the name. If you can find one that you think is most appropriate then by all means go for it :).

EDIT: Clarified about label being non-surprising.