Search code examples
cssnaming-conventionswrappernestedbem

Naming A Wrapper Element Class When Using BEM


I understand that when using BEM, the classnames should not directly reflect the HTML structure, but how should a wrapper element be named? Please ignore my particular syntax(close to SUIT); it still follows BEM, just with a different way of differentiating the elements.

For example:

<div class="?">
  <footer class="PageFooter">
    <h4 class="PageFooter-brand>…</h4>
    <ul class="PageFooter-contactDetails">…</ul>
  </footer>
<div>

I would currently class the wrapper in this instance as PageFooterWrapper, but this feels clunky because the wrapper is not independent - it exists purely for the PageFooter. Obviously prefixing everything with PageFooter- is ridiculous, so that only leaves treating the wrapper as a part of PageFooter: PageFooter-wrapper. This irks me as there is an implied suggested applied by this.

So what should the class of the wrapper be?


Solution

  • The way i've always treated it is the wrapper should always be the block so:

    <div class="PageFooter">
      <footer class="PageFooter-inner">
        <h4 class="PageFooter-brand">...</h4>
        <ul class="PageFooter-contactDetails">...</ul>
      </footer>
    </div>
    

    The Block contains Elements so instead of having something around my Block i just followed along with the Element principle and started using inner's instead of containers