Reputation: 1043
I have the following HTML code, I tend to have a 3 code project identifier at the start
<span class="abc-user-overview__header__title">
<span class="abc-user-overview__header__title__name">
{{ name }}
<span class="abc-user-overview__header__active">true</span>
</span>
Although the 'name' element is a child of title, how strict does the naming convention have to be? As I think abc-user-overview__header__title__name is too long and would prefer to drop the __title, giving me:
<span class="abc-user-overview__header__title">
<span class="abc-user-overview__header__name">
{{ name }}
<span class="abc-user-overview__header__active"true</span>
</span>
Is this valid and acceptable BEM?
Upvotes: 1
Views: 3367
Reputation: 989
Instead of this:
block-name__elem-name_mod-name_mod-val
I use this, that's a bit shorter and easier to read:
blockName-elemName--modName--modVal
In alternative, you can separate the modificator. Be careful, this may create conflicts if you use mixins:
<ul class="blockName">
<li class="blockName-elemName --first">...</li>
<li class="blockName-elemName">...</li>
<li class="blockName-elemName">...</li>
<li class="blockName-elemName --last">...</li>
</ul>
Upvotes: 0
Reputation: 439
Those names aren't too long. Sometimes when names get too long it's because you've got too much going on in that page. When I see that in angular (for example) I consider extracting components, then you can chop off the block and half the element name from the existing css classes and replace with a shorter block name. it makes the parent component so much easier to read when you move a lot of unrelated complexity to a different component. Good candidates for this could include
Some of these components might be useful for the whole application, or maybe just for that page. Etc.
Upvotes: 0
Reputation: 3884
Sadly your code is not valid according to BEM convention. This is the official name structure block-name__elem-name_mod-name_mod-val
.
Here is your code with valid BEM naming:
<span class="abc-user-overview__title">
<span class="abc-user-overview__name">{{ name }}</span>
<span class="abc-user-overview__status abc-user-overview__status_active">true</span>
</span>
Few tips:
.news-list
, but on other we may display Products, so reusing block with name .news-list
with Products inside isnt very nice. In this case a simple class like .list
will be enough.block
, not an element
.Full documentation and great examples can be found in the official website: https://en.bem.info/methodology/naming-convention/#naming-rules
Upvotes: 1