Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does BEM often use two underscores instead of one for modifiers?

Tags:

css

bem

In BEM, I understand that with modifiers, two dashes makes sense so that you can distinguish the modifier in my-block-my-modifier with my-block--my-modifier.

But why use block__element instead of block_element?

like image 310
Gil Birman Avatar asked Jul 10 '14 06:07

Gil Birman


People also ask

How do you properly use BEM?

BEM names intentionally use double underscores and double hyphens instead of single to separate Block-Element-Modifier. The reason is so that single hyphens can be used as word separators. Class names should be very readable, so abbreviation isn't always desirable unless the abbreviations are universally recognizable.

What is the BEM principle?

The Block, Element, Modifier methodology (commonly referred to as BEM) is a popular naming convention for classes in HTML and CSS. Developed by the team at Yandex, its goal is to help developers better understand the relationship between the HTML and CSS in a given project.

What is BEM pattern?

What is BEM? BEM is a front-end naming method for organizing and naming CSS classes. The Block, Element, Modifier methodology is a popular naming convention for class names in HTML and CSS. It helps to write clean CSS by following some simple rules.

What is the BEM naming convention?

BEM stands for block, element, and modifier. It's a naming convention that divides the user interface into small, reusable components that will prepare us for the changes in design of our websites. This convention also enhances the cross-site copy/paste feature by helping make elements reusable components.


1 Answers

Double Underscore is used to define sub element of a block.

i.e:

<nav class="main-nav">     <a class="main-nav__item" href="#">Text</a> </nav> 

Where main-nav is a block & main-nav__item is a sub element.

This is done because some people might name their block like this main_nav which will create confusion with single underscore like this : main_nav_item

Therefore double underscore will clarify stuff like this: main_nav__item.

like image 85
Imran Bughio Avatar answered Sep 29 '22 19:09

Imran Bughio