Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS BEM, which chars for the modifier..?

Tags:

css

bem

I'm not sure which is the official website, I've found getbem.com and en.bem.info.

One suggests using -- for the modifier (Naming):

CSS class is formed as block’s or element’s name plus two dashes.

The other _ for the modifier (Modifier name):

A modifier name is delimited by a single underscore (_).

I know I can use either, and really it's just important to be consistent, but I like to try and use official specs whenever possible.

  • Which is the official website..?
  • Should I really be using -- or _ for modifiers..?
like image 493
Stephen Last Avatar asked May 05 '17 13:05

Stephen Last


People also ask

How do you use the BEM modifier?

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 a modifier in BEM?

A modifier is a flag that changes how a block or an element looks or behaves. For example: The two buttons are the same block, but they look different. The power BEM gives us lets us use the same block twice and still have them look very different.

What is a modifier Class CSS?

Modifiers represent different states or styles of classes. They can be used both for blocks or elements. In HTML a modifier must be used together with its Block / Element, as additional features: <form class="form form--large"> <button class="form__button form__button--red"></button>

Is BEM obsolete?

Using BEM today Since class collision between components is not a problem anymore, a lot of devs consider now BEM obsolete.


1 Answers

Which is the official website?

BEM started as an informal set of guidelines by Yandex, which they later formalized on en.bem.info, so in that regard en.bem.info is the "canonical" version of BEM.

With that said, there are many flavors of BEM, and I myself use a variant influenced largely by Harry Roberts and Nicolas Gallagher.

This brings me to your next question:

Should I really be using -- or _ for modifiers?

To that my answer is: you should be consistent in your usage, but you may use whatever character(s) you'd like for the variant of BEM that you're using. Just be sure that everyone on your team understands which variant you're standardizing on.

This is similar to using tabs vs two spaces vs four spaces (vs hotdogs). It doesn't actually make a difference beyond being something that people tend to have an irrationally strong personal preference for.

To help normalize people, I use an example syntax of a block, element, and modifier that shows what the variant is normalizing on:

I used to primarily use:

the-block__the-element--the-modifier

But I now prefer:

TheBlock_theElement-theModifier

for its brevity.

like image 121
zzzzBov Avatar answered Sep 28 '22 04:09

zzzzBov