CSS Academy · Lesson

BEM: Block Element Modifier Naming

Apply the Block-Element-Modifier methodology to create predictable, reusable class names.

Lesson 2 of 413 steps

BEM: Block Element Modifier Naming is a free CSS Academy lesson on CoddyKit. This is 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, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.

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.

  <div class="card">Card block</div>
  <nav class="nav">Nav block</nav>
  <button class="button">Button block</button>
  <form class="search-form">Search form block</form>

Element

An Element is a child of a block that has no meaning outside of it. Elements use double underscore: .block__element.

  <div class="card">
    <div class="card__image">Image</div>
    <div class="card__body">
      <h2 class="card__title">Title</h2>
    </div>
  </div>
  <nav class="nav">
    <div class="nav__item"><a class="nav__link" href="#">Link</a></div>
  </nav>

Modifier

A Modifier is a variation or state of a block or element. Modifiers use double hyphen: .block--modifier.

  <button class="button button--primary">Primary</button>
  <button class="button button--large">Large</button>
  <div class="card card--featured">Featured Card</div>
  <nav class="nav">
    <div class="nav__item nav__item--active">Active Item</div>
  </nav>

Complete BEM Example

A card component with BEM naming:

  <div class="card card--featured">
    <div class="card__image" role="img" aria-label="Card image"></div>
    <div class="card__body">
      <h2 class="card__title">Title</h2>
      <p class="card__text">Content</p>
      <a class="button button--primary card__action" href="#">Read More</a>
    </div>
  </div>

BEM CSS Structure

Corresponding CSS for the BEM card:

  <div class="card card--featured">
    <div class="card__image" role="img" aria-label="Card image"></div>
    <div class="card__body">
      <h2 class="card__title">Title</h2>
      <p class="card__text">Content</p>
      <a class="button card__action" href="#">Read More</a>
    </div>
  </div>

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 class="button">Default</button>
  <button class="button button--danger">Danger</button>

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.

Free to start

Learn CSS with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
40
Lessons
159

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. 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. The CSS Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

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

  1. Why CSS Architecture Matters
  2. BEM: Block Element Modifier Naming
  3. File Organization: ITCSS and 7-1 Pattern
  4. Avoiding Specificity Wars
← Back to CSS Academy