Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should you style elements when using BEM or should we add extra classes

Tags:

css

sass

bem

What is the more appropriate approach when using BEM ? Are we allowed to not add extra classes to elements and style the elements themselves

<section class="news-section">
  <a>link</a>
</section>


.news-section {
  a {
    color: blue;
  }

}

Or do we have to add extra classes to all elements and style those classes?

<section class="news-section">
  <a class="news-section_link">link</a>
</section>

.news-section {
  &_link {
    color: blue;
  }

}
like image 757
Paran0a Avatar asked Mar 29 '26 17:03

Paran0a


1 Answers

Are we allowed to not add extra classes to elements and style the elements themselves

No.

With BEM, you have to always use CSS classes:

In HTML, BEM entities are represented by the class attribute. (bem.info)

In return for this rigidity, BEM will bring you :

  • Scalability, because blocks can be nested without limit;
  • Flexibility, because CSS selectors are loosely coupled with HTML tags.
like image 160
Paleo Avatar answered Apr 01 '26 06:04

Paleo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!