W
W
webpixel2015-07-05 17:01:35
css
webpixel, 2015-07-05 17:01:35

What is the correct way to name classes in BEM?

Greetings! I watched a bunch of videos, read a huge number of articles on BEM, but there is still no complete picture of the class naming issue. That's what I'm talking about, according to the logic, the naming of classes in BEM occurs according to this logic:
block__element--modifier
in this case, in my example it should be:

.menu {}
.menu__item {}
.menu__item--active {}
.menu__link

but for some reason I see this code everywhere:
.menu {}
.menu__item {}
.menu_item_acitve {}
.menu__link

In which case is the modifier like "menu__item--active" used?
On bem.info itself, the modifier is always written in the style "btn_big_red".
And to be honest, it's a little confusing. Please tell me how it is correct, so that I would already put an end to this issue for myself. Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dm, 2015-07-05
@webpixel

Below in the comments is an explanation that in English. The network got accustomed to the spelling not the cat. was originally. frontender.info/learning-to-love-bem
That's why there are differences. But the essence is the same

O
Oleg Cherr, 2015-07-21
@OlegCherr

I recommend naming the classes in a way that is convenient for you personally (or your team).
Personally, I really dislike entries with double dashes or underscores, and even more so key-value modifiers. It looks very cumbersome, especially when one element has several similar classes.

.menu__item--active {}
.menu__item_state_active {}

Therefore, I strongly recommend adjusting the bam for yourself. Think about the challenges you face now and in the future, and solve them in the most concise way possible. Here, for example, is my modification of bam . I've been using it for several years now. Development has become very enjoyable.

K
Kater-auf-Dach, 2015-07-19
@Kater-auf-Dach

Although there is a solution for a long time, I will clarify a little and correct the question itself - if anyone else asks such a question.
Strictly speaking, in the original BEM notation, the class .menu_item_active {}will look like .menu__item_state_active {}.
This is a case of a key/value type modifier whose fully qualified name is constructed as follows:
block-name__elem-name_mod-name_mod-val.
Therefore, not btn_big_red, but btn_color_redand btn_size_big, that is, there are already 2 modifiers.
More details - in the naming convention , at the very bottom there is also a section "Alternative names"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question