What is the BEM methodology? ✨
BEM is a methodology for naming CSS classes.
BEM divides the interface into three parts: Block, Element, and Modifier.
1. Block is a logically and functionally independent page component, such as a header, menu, form, card, or search block.
The name of a block should reflect its purpose ("What is it?") rather than its appearance ("What does it look like?" – big, red).
2. Element is a composite part of a block and can't be used separately from it.
The naming structure for an element should follow the pattern name-block__element-name, with the element name separated by a double underscore.
3. Modifier is an entity that defines the appearance, state, and behavior of an element or block.
Modifiers come in two types: boolean (field_disabled) and key-value (field_theme_dark).
What are the advantages of using BEM:
- Accelerated development:
Page building blocks are isolated, making them easy to use in different project parts.
- Accelerated refactoring:
Each block is a small, self-contained piece of code, allowing for easy navigation and preventing the style of elements in one block from affecting others.
ALT Description of the BEM methodology