/css-naming-methodologies

This repo shows an overview of commonly used CSS naming methodologies

MIT LicenseMIT

CSS Naming Methodologies

This repo gives an overview of multiple CSS naming methodologies and their pros and cons.

BEM (Block Element Modifier)

Information

Pros

  • Component based
  • Very flexible, suitable for small and big projects
  • Big community so most problems/questions you will face are already 'solved' by others
  • No more specificity issues
  • Every element has it's own class so you won't have to use descendant selectors anymore. This will improve CSS efficiency
  • Can be easily checked by a linter

Cons

  • Syntax doesn’t look very sexy
  • Classnames might get long but this can be solved easily by using the tips out of the following article

OOCSS (Object Oriented CSS)

Information

Pros

  • Less repeating styles so smaller file size
  • Can be used really well in combination with SASS
  • CSS styles are modular blocks of code so they can be reused really easy

Cons

  • Cluttered HTML markup
  • Not suitable for small projects
  • You probably need to update HTML when updating styles so this makes it really tough to maintain projects.

SMACSS (Scalable and Modular Architecture for CSS)

Information

Pros

  • When writing new CSS you probably know where to put it
  • Can be used in combination with other methodologies like BEM

Cons

  • Not really suitable for smaller projects
  • Theme might not be needed for all projects
  • When using SMACSS without another naming methodology you’re probably still gonna use descendant selectors (which is bad practice and generally should be avoided)

ACSS (Atomic CSS)

Information

Pros

  • Change styles without changing CSS
  • Works well with frameworks like React or Angular. Personally I would rather go for something like Styled Components but to each his own
  • Ultra reusable, never have to duplicate a single line of styling again

Cons

  • Your HTML elements will have a lot of classes so they will be cluttered
  • You need JavaScript to set ACSS up
  • CSS doesn’t describe context of components

Also interesting to check out

ITCSS (Inverted Triangle CSS)

CSS namespacing