Have you heard about Hack Frontend Community?Join us on Telegram!

BEM Methodology: Block, Element, Modifier Naming Convention

BEM (Block — Element — Modifier) is a CSS class naming methodology created for organization, reusability and scalability of HTML and CSS code.

It helps avoid style conflicts, makes code understandable, predictable and easy to maintain when working in a team.


Breakdown

ComponentDescription
Block

Independent entity, semantic component (e.g., header, button)

Element

Part of a block, has no meaning outside it (button__icon)

Modifier

State or variation of block/element (button--active, button__icon--small)

Naming Convention

block__element--modifier

Examples:

.button { }                    /* Block */
.button__icon { }              /* Element */
.button--primary { }           /* Modifier */
.button__icon--large { }       /* Element with Modifier */

Benefits:

BEM makes code self-documenting, prevents style conflicts, and simplifies working in teams.

By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.