BEM: Block Element Modifier Naming
Apply the Block-Element-Modifier methodology to create predictable, reusable class names.
BEM: Block Element Modifier Naming is a free CSS Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What is BEM?
BEM (Block–Element–Modifier) is a naming convention that creates self-describing class names. It makes CSS components predictable and self-documenting.
Block
A Block is a standalone, meaningful UI component that can exist independently. It is the root class of the component.
/* Blocks: */
.card { }
.nav { }
.button { }
.search-form { }Element
An Element is a child of a block that has no meaning outside of it. Elements use double underscore: .block__element.
.card__image { }
.card__title { }
.card__body { }
.nav__item { }
.nav__link { }Modifier
A Modifier is a variation or state of a block or element. Modifiers use double hyphen: .block--modifier.
.button--primary { }
.button--large { }
.card--featured { }
.nav__item--active { }Complete BEM Example
A card component with BEM naming:
<div class="card card--featured">
<img class="card__image" src="..." alt="">
<div class="card__body">
<h2 class="card__title">Title</h2>
<p class="card__text">Content</p>
<a class="button button--primary card__action">Read More</a>
</div>
</div>BEM CSS Structure
Corresponding CSS for the BEM card:
.card { border-radius: 8px; overflow: hidden; }
.card--featured { border: 2px solid gold; }
.card__image { width: 100%; aspect-ratio: 16/9; object-fit: cover; }
.card__body { padding: 16px; }
.card__title { font-size: 1.25rem; margin-bottom: 8px; }
.card__text { color: #666; }
.card__action { margin-top: 16px; }BEM Specificity Benefit
BEM classes are all single classes (specificity 0,1,0). No selector is more specific than another, so overriding is straightforward — just add the right modifier class.
Common BEM Mistakes
Avoid these BEM pitfalls:
- Multi-level elements:
.card__body__title— flatten to.card__title - Elements outside their block in HTML
- Using element selectors like
.nav__link a— adds unnecessary specificity
BEM with CSS Custom Properties
BEM and CSS variables pair naturally. Define block-level tokens that modifiers override:
.button {
--button-bg: royalblue;
--button-color: white;
background: var(--button-bg);
color: var(--button-color);
}
.button--danger {
--button-bg: crimson;
}When Not to Use BEM
BEM is verbose and not ideal for utility classes or one-off styles. Utility-first frameworks like Tailwind replace BEM entirely. Use BEM for custom component libraries where semantic naming matters.
BEM in Practice
Many design systems use BEM variants or similar naming schemes. The specific syntax matters less than the consistent principle: block → element → modifier, no deep nesting, flat specificity.
Quick Check
In BEM, which syntax represents an element named "title" inside a "card" block?
Recap
BEM uses Block, Element, and Modifier naming: .block__element--modifier. All classes are single classes for flat, equal specificity. Elements (__) belong inside their block. Modifiers (--) create variants. Avoid deep nesting like .card__body__title — flatten to .card__title.
Frequently asked questions
Is the “BEM: Block Element Modifier Naming” lesson free?
Yes — the full text of “BEM: Block Element Modifier Naming” is free to read here on the web, and the CSS Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO.
What will I learn in “BEM: Block Element Modifier Naming”?
Apply the Block-Element-Modifier methodology to create predictable, reusable class names. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “BEM: Block Element Modifier Naming” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Why CSS Architecture Matters
- BEM: Block Element Modifier Naming
- File Organization: ITCSS and 7-1 Pattern
- Avoiding Specificity Wars