Bem and Sass for Component CSS

BEM and Sass solve different problems.
BEM gives us a naming convention for blocks, elements, and modifiers. Sass gives us tools for organising and generating CSS. Used together, they can make component styling much easier to reason about.
Used badly, they can also produce long selectors, over‑nesting, and a stylesheet full of names that look systematic but still behave unpredictably.
Start with the Component Boundary
BEM works best when the block maps to a real component or pattern.
For example:
.card.site‑nav.form‑field.product‑summary.alert
The block should be understandable without knowing where it appears on the page. If the name only makes sense in one layout, it may not be a reusable component.
Elements then describe parts of that block:
.card__title.card__body.site‑nav__link.form‑field__error
Modifiers describe variants:
.card‑‑featured.alert‑‑warning.site‑nav‑‑compact
The official BEM introduction is a useful reference because it keeps the naming idea simple. The value is not in punctuation. The value is in making relationships visible.
Use Sass Nesting to Reduce Repetition, Not to Increase Specificity
Sass makes BEM less tedious because & can build related selectors.
That does not mean every selector should be nested under several parents. A good Sass structure for BEM keeps the compiled selectors flat:
.card.card__title.card__body.card‑‑featured
The Sass file may group them together, but the CSS output should not become .page .content .card .card__title unless that relationship is genuinely required.
BEM is partly useful because it avoids specificity wars. Deep Sass nesting can bring those wars back.
Keep Modifiers Explicit
Modifiers should represent meaningful variants, not every visual adjustment.
Good modifiers:
button‑‑primaryalert‑‑errorcard‑‑compactnav‑‑open
Weak modifiers:
card‑‑margin‑toptitle‑‑bluebox‑‑left
If a modifier describes a one‑off layout adjustment, it probably belongs in the layout. If it describes a reusable state or variant of the component, it belongs with the component.
Avoid Coupling Components to Their Containers
A component should not need to know too much about where it is used.
This is the kind of selector that becomes fragile:
.sidebar .card__title
It may be convenient at first, but it means the card's styling changes because of its container. Sometimes that is necessary, but it should be deliberate. A clearer approach may be a modifier:
.card‑‑sidebar
That keeps the variation attached to the component itself. It also makes the HTML more explicit.
Put Component Partials in Predictable Places
Sass partials and BEM fit nicely together when each component has a clear file.
For example:
_card.scss_site‑nav.scss_form‑field.scss_alert.scss
The article on organising Sass with partials and mixins covers this structure more broadly.
The benefit is not only neatness. When a visual bug appears in .product‑summary__price, the file to open should be obvious.
Do Not Make Bem a Substitute for Judgement
BEM does not automatically make CSS good.
You can still create too many modifiers, duplicate patterns, use unclear names, and build components that are too large. Sass can still hide complexity. The convention helps when it supports decisions. It becomes noise when it is followed mechanically.
A useful component CSS file should make these things clear:
- what the component is
- what its parts are
- what variants it supports
- which states it can enter
- which assumptions it makes about markup
Once components become shared interface pieces rather than isolated templates, the same CSS decisions need better documentation. Using Storybook to document front‑end components shows one way to make those states visible.
Wrapping Up
BEM and Sass work well together when Sass groups the component and BEM keeps the generated CSS explicit.
Keep selectors flat, names meaningful, modifiers deliberate, and component files easy to find. The result is not glamorous, but it is the kind of CSS you can return to months later without having to rediscover the whole page.
Key Takeaways
- BEM names should reflect real component boundaries.
- Sass nesting should group selectors without producing over‑specific output.
- Modifiers should describe meaningful variants or states.
- Avoid styling components through container selectors unless the dependency is intentional.
- Component partials make BEM CSS easier to find and change.
Postscript
This article is part of an archive restored from a previous version of my website on 27 May 2026. The original publication date is accurate. The article has since been restored and lightly edited for formatting, imagery, broken links, and current internal references.