The key point of BEM is a distinction between element (prefixed by __
in the classname) and modifier (prefixed by --
):
Element
A part of a block that has no standalone meaning and is
semantically tied to its block.Modifier
A flag on a block or element. Use them to change appearance
or behavior.
In your example, both --heading
, --subheading
and --author
are not modifiers of elements – they ARE elements. If, for some reason, you decide to apply actual modifiers to those elements (like highlighted
or clickable
), you end up either rewriting the classnames completely – or having some weirdness like article__textbox--heading--clickable
.
Now, the real question I see here is ‘ok, it’s not modifiers, but what should I do with elements sitting inside other elements?’ In other words, which classnames should be applied to elements nested into other elements? This question is actually answered in BEM FAQ:
Q: What should I do if my block has a complex structure and its elements
are nested? CSS classes likeblock__elem1__elem2__elem3
look scary.A: According to BEM method, block structure should be flattened; you do
not need to reflect nested DOM structure of the block. So, the class
names for this case would be:
.block {}
.block__elem1 {}
.block__elem2 {}
.block__elem3 {}
… whereas the DOM representation of the block may be nested:
<div class='block'>
<div class='block__elem1'>
<div class='block__elem2'>
<div class='block__elem3'></div>
</div>
</div>
</div>
Besides the fact that the classes look much nicer, it makes the elements be dependent on the block only. So, you can easily move them across the block when providing changes to the interface. The changes of the block DOM structure would not need corresponding changes to the CSS code.
So in your case it might be better to have them styled like this:
<div className="article">
<div className="article__textbox">
<h1 className="article__heading"></h1>
<p className="article__subheading"></p>
<span className="article__author"></span>
</div>
</div>
Another approach, covered in this article, is treating textbox as a separate block, and all its innards as its own elements:
<div className="article">
<div className="textbox">
<h1 className="textbox__heading"></h1>
<p className="textbox__subheading"></p>
<span className="textbox__author"></span>
</div>
</div>
Remember, it’s all about DRY: if that textbox is intended to be reused in other blocks, treat it as block. Quoting the same article:
When you’re unsure if something even is a block, ask yourself: “Could
this BEM element I’m about to add to a block be used as a component in
other areas of the website?”