How Does BEM Structure CSS Class Names?

The Block Element Modifier (BEM) methodology is a front-end naming convention developed to make CSS scalable, modular, and maintainable across complex web applications. By establishing a clear relationship between components, their internal parts, and their visual variations, BEM eliminates naming conflicts and reduces CSS specificity wars. The structure relies on breaking UI patterns into three clear layers—Blocks, Elements, and Modifiers—connected by standardized delimiters (__ and --) that make class names instantly readable and self-documenting.

The Core Components of BEM

BEM divides every interface component into three distinct conceptual layers:

Delimiter Syntax and Naming Rules

BEM relies on specific formatting rules to differentiate multi-word names from component hierarchies:

The complete pattern resolves to block-name__element-name--modifier-name.

Practical Implementation in HTML and CSS

Consider a standard user profile card. Rather than nesting tag selectors or generic classes, BEM establishes explicit classes for every visual node.

<article class="profile-card profile-card--featured">
  <img class="profile-card__avatar" src="avatar.jpg" alt="User avatar">
  <h2 class="profile-card__name">Jane Doe</h2>
  <p class="profile-card__bio">Full-stack software engineer.</p>
  <button class="profile-card__button profile-card__button--primary">Follow</button>
</article>

In the stylesheet, all classes remain at a single level of specificity (0-1-0), avoiding deeply nested CSS selectors:

/* Block */
.profile-card {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
}

/* Block Modifier */
.profile-card--featured {
  border-color: #3b82f6;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Elements */
.profile-card__avatar {
  border-radius: 50%;
  width: 64px;
  height: 64px;
}

.profile-card__name {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 8px;
}

.profile-card__bio {
  color: #64748b;
  font-size: 0.875rem;
}

.profile-card__button {
  padding: 8px 16px;
  border-radius: 4px;
}

/* Element Modifier */
.profile-card__button--primary {
  background-color: #3b82f6;
  color: #ffffff;
}

Key Advantages of the BEM Architecture

Adopting BEM provides substantial architectural benefits for individual developers and large teams alike: