4

I am structuring the CSS in my web application according to the BEM convention.

I have a block called item and 3 elements: item__section, item__title and item__description.

I am using these BEM classes as follows:

<div class="item">
  <div class="item__section item__title"> ... </div>
  <div class="item__section item__description"> ... </div>
</div>

The item__section element class contains style that we reuse between elements.

Is this valid BEM or should I create a modifier for item__section for each kind of section(title and description)?

Chedy2149
  • 2,821
  • 4
  • 33
  • 56

2 Answers2

7

That's absolutely valid and is called mix:

tadatuta
  • 2,007
  • 11
  • 12
  • the above code is not a mix , you shouldn't use two elements of the same block in the same tag – Boogie Sep 24 '21 at 08:23
-1

I don't think you should. You could add mixin like:

<div class="item">
  <div class="item__section u-title"> ... </div>
  <div class="item__section u-description"> ... </div>
</div>

but don't use two elements of the same block in the same tag because you can end up with specificity problems

Boogie
  • 750
  • 7
  • 17