BEM CSS

CSS is easy to learn? Most would say that yes, mainly because of the facility and the possibility of quickly seeing what we are doing. However, of course, that exists negative points and, when we talk about them, one of the principal is related to maintenance/organization of CSS.

Open a file and writing CSS is very easy and quick; however, give maintenance, organize it, and scale it are not trivial things. As your project grows, you start to lose patience with CSS or break windows get bigger and bigger. A good reading tip is an article (in pt-BR) Scalable CSS do Shankar Cabus.

BEM CSS

Several alternatives/thoughts/methodologies attempt to correct and assist in organizing and structuring a CSS project. One is the BEM (Block Element Modifier), created by the Yandex guys, a Russian search site.

As can be noted, the basic idea is to have three things:

Huh?! Imagine a list of items with an active item, something more like this:

<ul class="list">
<li class="list-item active"></li>
<li class="list-item"></li>
<li class="list-item"></li>
</ul>
view raw css-bem-01.html hosted with ❤ by GitHub
.list {}
.list-item {}
.list-item.active {}
view raw css-bem-02.css hosted with ❤ by GitHub

Applying the BEM, we have something like this:

<ul class="list">
<li class="list__item"></li>
<li class="list__item"></li>
<li class="list__item list__item--active"></li>
</ul>
view raw css-bem-03.html hosted with ❤ by GitHub
.list {}
.list__item {}
.list__item--active {}
view raw css-bem-04.css hosted with ❤ by GitHub

I need to admit that some time ago when I discovered the BEM methodology, I thought: “This is so weird!”. All those __ and -- were so strange. But now that I know more about the idea, I can say that it convinced me. Of course, like any other thoughts/methodologies, there are positive and negative points, and it is up to you, give the final word.

Only some topics that I realized using the BEM (but are my opinions):

More posts