Answer the question
In order to leave comments, you need to log in
Which naming option is more correct (BEM)?
There are a few moments that after a while can not settle down in my head.
Which option is more correct from the options below? Or is there no more correct one at all, and everyone writes as he pleases?
1st option - the most flat structure without utility classes
2nd option - less flat structure with utility classes
3rd option - the class structure accurately reflects the nesting of elements
<div class="main">
<nav class="main__nav">
<ul class="main__nav-list">
<li class="main__nav-item">
<a href="#" class="main__nav-link">Home</a>
</li>
<li class="main__nav-item">
<a href="#" class="main__nav-link">Work</a>
</li>
<li class="main__nav-item">
<a href="#" class="main__nav-link">About us</a>
</li>
</ul>
</nav>
</div>
/ / / / /
<div class="main">
<nav class="main-nav">
<ul class="main-nav__list">
<li class="main-nav__item">
<a href="#" class="main-nav__link">Home</a>
</li>
<li class="main-nav__item">
<a href="#" class="main-nav__link">Work</a>
</li>
<li class="main-nav__item">
<a href="#" class="main-nav__link">About us</a>
</li>
</ul>
</nav>
</div>
/ / / / /
<div class="main">
<nav class="main-nav">
<ul class="main-nav-list">
<li class="main-nav-list-item">
<a href="#" class="main-nav-list-item__link">Home</a>
</li>
<li class="main-nav-list-item">
<a href="#" class="main-nav-list-item__link">Work</a>
</li>
<li class="main-nav-list-item">
<a href="#" class="main-nav-list-item__link">About us</a>
</li>
</ul>
</nav>
</div>
Answer the question
In order to leave comments, you need to log in
The second option is more correct, but you put the wrong meaning into it, you indirectly attached main-nav to the main context and this is very noticeable in the 3rd example, where you exaggerated this problem, the 3rd example is terrible, never do that. The 1st example is correct in naming, but will not always be correct in structure, since navigation is most likely a separate block. As a result, it will be more correct, short and concise like this:
<div class="main">
<nav class="main__nav nav">
<ul class="nav__list">
<li class="nav__item">
<a href="#" class="nav__link">Home</a>
</li>
<li class="nav__item">
<a href="#" class="nav__link">Work</a>
</li>
<li class="nav__item">
<a href="#" class="nav__link">About us</a>
</li>
</ul>
</nav>
</div>
Everyone writes as he pleases.
3rd option - the class structure accurately displays the nesting of elements
.main__nav
, not to the block.main-nav
<div class="main">
<nav class="main-nav main__nav">
<ul class="main-nav__list">
<li class="main-nav__item">
<a href="#" class="main-nav__link">Home</a>
</li>
<li class="main-nav__item">
<a href="#" class="main-nav__link">Work</a>
</li>
<li class="main-nav__item">
<a href="#" class="main-nav__link">About us</a>
</li>
</ul>
</nav>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question