What is BEM methodology?

What is BEM methodology?

What is BEM methodology?

BEM (Block, Element, Modifier) is a CSS methodology developed in 2009 by Yandex (think of them as Russia’s Google).

CSS is one of the easiest programming language but very hard to maintain. Using IDs and !important in your CSS will lead to chaos in the future, especially when your project gets bigger and starts having more people in your development team.

BEM CSS methodology simply fixes this problem and provides a better structure for your CSS code and scalable CSS!

Let’s build a card component;

  • .card is a block that contains all elements.
  • BEM naming connects blocks with elements with two underscores E.g: .card__description
  • Modifier is about changing how the element looks (changing font colors etc). We connect them with our element with two dashes E.g: .card__button--success




Why should you use BEM for your projects?


Pros:

  • Improves your CSS performance
  • Provide a modular structure to your projects
  • There will be no conflicts in your CSS because of its unique naming scheme
  • Better relationship between your CSS and HTML codes
  • Updating your CSS codes in the future will be easy

Cons:

  • Long class names
  • Long nestings in SASS

I suggest everyone uses BEM, it's my favourite CSS naming scheme. By using BEM, updating CSS codes and/or adding new codes with no conflict is so fast and easy.

Post your comment

Emre Rothzerg
Emre Rothzerg

Strategist.
Developer.
Consultant.

Follow me on:
Contact:
[email protected]
Newsletters

I am currently considering
new projects

Contact me