BEM is a naming convention
BEM is a naming convention in CSS that helps you write clean, scalable, and
maintainable code—especially for large projects.
✅ What is BEM?
BEM stands for:
● B – Block
● E – Element
● M – Modifier
It’s a structured way to name CSS classes based on the role of the component in
the UI.
🧱 1. Block
A standalone component that has meaning on its own.
<div class="button">Click me</div>
.button {
padding: 10px;
}
🧩 2. Element
A part of the block that has no standalone meaning; it depends on the block.
Syntax: block__element
<div class="card">
<div class="card__title">Title</div>
<div class="card__content">Some content</div>
</div>
.card__title {
font-size: 20px;
}
.card__content {
color: gray;
}
🎨 3. Modifier
A flag on a block or element used to change appearance, behavior, or state.
Syntax: block--modifier or block__element--modifier
<div class="button button--primary">Save</div>
<div class="button button--disabled">Save</div>
.button--primary {
background-color: blue;
}
.button--disabled {
opacity: 0.5;
}