# BEM in CSS: Block, Element, Modifier Naming Explained

> BEM (Block, Element, Modifier) explained with a real example: the naming rules, how to handle nested elements and modifiers, BEM with Sass, common mistakes, and BEM vs Tailwind and CSS Modules.

Author: [Marko Denic](https://markodenic.com/) | Published: 2026-10-18 | Updated: 2026-10-18 | Topics: CSS, Tutorial, Web Development | Canonical: https://markodenic.com/bem-css/

![BEM in CSS: Block, Element, Modifier Naming Explained](https://markodenic.com/wp-content/uploads/2026/10/og-bem-css.png)

**BEM** (Block, Element, Modifier) is a naming convention for CSS classes. Every class name says what it styles and where it belongs, so styles don’t leak between components and you can tell from the HTML alone which CSS applies.

The pattern is `block__element--modifier`:

- **Block**: a standalone component, like `card`, `menu` or `search-form`.
- **Element**: a part of a block, joined with two underscores: `card__title`.
- **Modifier**: a variation or state, joined with two hyphens: `card--featured`, `card__button--disabled`.

### Demo:

```html
<div class="bem-demo">
  <article class="card">
    <h3 class="card__title">Regular card</h3>
    <p class="card__text">Block and elements.</p>
    <a class="card__button" href="https://markodenic.com/css-tips/">Read more</a>
  </article>

  <article class="card card--featured">
    <h3 class="card__title">Featured card</h3>
    <p class="card__text">Same block, with a modifier.</p>
    <a class="card__button card__button--ghost" href="https://markodenic.com/css-tips/">Read more</a>
  </article>
</div>
```

```css
.bem-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  padding: 16px;
  border-radius: 16px;
  background: #f1f5f9;
  font: 16px/1.5 system-ui, sans-serif;
}

/* Block */
.card {
  padding: 20px;
  border-radius: 12px;
  background: #fff;
  color: #0f172a;
}

/* Elements */
.card__title {
  margin: 0 0 4px;
  font-size: 18px;
}

.card__text {
  margin: 0 0 16px;
  color: #475569;
}

.card__button {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  background: #1d4ed8;
  color: #fff;
  text-decoration: none;
}

/* Block modifier */
.card--featured {
  background: #1e3a8a;
  color: #fff;
}

.card--featured .card__text {
  color: #cbd5e1;
}

/* Element modifier */
.card__button--ghost {
  background: transparent;
  box-shadow: inset 0 0 0 2px currentColor;
}
```

[See the live demo](https://markodenic.com/bem-css/#demo)

Both cards use the same block and elements. The second adds a block modifier (`card--featured`) and an element modifier (`card__button--ghost`). Everything else is shared.

## The rules

### Blocks

A block is a reusable, independent piece of the interface. Name it after what it *is*, not what it looks like: `alert`, not `red-box`. Blocks can be nested inside other blocks, but they never depend on them.

```html
<form class="search-form">...</form>
<nav class="menu">...</nav>
```

### Elements

An element is a part of a block that has no meaning on its own. It’s always written as `block__element`, and that’s the only selector you need: no nesting like `.card .title`.

```html
<form class="search-form">
  <input class="search-form__input" type="search">
  <button class="search-form__button">Search</button>
</form>
```

### Modifiers

A modifier changes the look, state or behavior of a block or element. A modified element keeps its base class too, so the modifier only has to contain the differences. Boolean modifiers are one word (`--disabled`); key-value modifiers use a second word (`--size-large`).

```html
<button class="button button--primary button--size-large">Buy</button>
<li class="menu__item menu__item--active">Home</li>
```

## Common mistakes

### Don't chain elements: card__header__title

BEM names don’t mirror the DOM tree. Every element belongs directly to the block, however deep it sits in the HTML. Long chains break the moment you move something.

```html
<!-- Avoid -->
<div class="card__header__title"></div>

<!-- Do -->
<div class="card">
  <div class="card__header">
    <h3 class="card__title"></h3>
  </div>
</div>
```

### Don't use a modifier on its own

A modifier only describes the difference, so it needs its base class next to it.

```html
<!-- Avoid: loses all the base .button styles -->
<button class="button--primary">Buy</button>

<!-- Do -->
<button class="button button--primary">Buy</button>
```

### Keep specificity flat

BEM works because almost every selector is a single class, so every rule has the same specificity and the order of your CSS decides what wins. Here is how [CSS class selectors](https://markodenic.com/css-class-selector/) and their specificity work. Avoid IDs, tag selectors and `!important` ([here’s why](https://markodenic.com/css-important/)). The one accepted exception is styling an element inside a modified block, like `.card--featured .card__text` in the demo.

### BEM with Sass

Sass’s `&` parent selector makes BEM shorter to write, and still compiles to flat, single-class selectors.

```css
.card {
  padding: 20px;

  &__title {
    font-size: 18px;
  }

  &--featured {
    background: #1e3a8a;
  }
}

/* Compiles to: .card {} .card__title {} .card--featured {} */
```

## BEM vs Tailwind vs CSS Modules

|  | BEM | Utility CSS (Tailwind) | CSS Modules / scoped CSS |
| --- | --- | --- | --- |
| Avoids style conflicts by | Naming discipline | Not writing component CSS | Generating unique class names |
| Needs a build step | No | Yes | Yes |
| HTML readability | Descriptive class names | Long class lists | Short names |
| Good fit | Plain CSS, WordPress themes, CMS templates | Apps with a component framework | React, Vue and Svelte components |

They also mix well: many teams use utilities for spacing and layout, and BEM-named classes for components that are reused across templates. Cascade layers and native CSS nesting have made plain CSS easier to organize too, but BEM is still the most widely understood convention.

## FAQ

### What does BEM stand for?

Block, Element, Modifier. It was created at Yandex and is now one of the most common CSS naming conventions.

### Why two underscores and two hyphens?

So block names can contain single hyphens (`search-form`) without ambiguity. `search-form__button--disabled` is always readable as block, element and modifier.

### Is BEM still relevant?

Yes, especially for plain CSS and server-rendered sites. With component frameworks, scoped styles or utility classes solve the same problem, so BEM is less necessary there.

### Can an element have its own elements?

Not in the name. Every element is `block__element`. If a part needs its own elements, it’s probably a block of its own.

Related: [CSS !important](https://markodenic.com/css-important/), [comments in CSS](https://markodenic.com/comments-in-css/), [CSS tips you won’t see in most tutorials](https://markodenic.com/css-tips/) and the [CSS tutorial](https://markodenic.com/css-tutorial/).
