Im just reviewing our CSS naming standards. I’m going to be proposing some changes. I would like some feedback here.
Currently our CSS naming standards are non-standard with industry conventions.
I’ll keep this to the point:
-
Adopting standard BEM
-
Removing atomic class modifiers (but keeping atomic classes). IMO these are largely useless.
for eg.has-font-size-5__sm
is confusing. Font size should not be this granular in a design. Most defined font size names will have 2 different sizes (at the most 3) based on screen width. These sizes should just be set using media queries on the base atomic class for example:.is-font-size-sm { font-size: 1rem; @media screen and (min-width: 70rem) { font-size: 1.3rem } ... }
-
merging class modifiers and atomic classes. The M in BEM means modifier so that’s confusing. We can just merge all the is-* and has-* into is-*. They should basically be used when blocks or elements use a global style (ie font-size, color, background-color) so on.
.is-color-black
makes sense .is-hidden
also does but .is-disabled
does not as a disabled element requires different style rules depending on the element. (form.is-disabled requires totally different styles to input.is-disabled). We should use BEM modifier in this instance .form--disabled
.
This will give us the best flexibility in terms of clear BEM standards and also reducing the amount of duplicated styles that BEM can sometimes create if its used without global element modifiers.
Thoughts?