Lesson 8 of 9 · 20m
Component Styling Strategies: BEM, Scoped, Utility, CSS-in-JS
An honest comparison of the four mainstream strategies — what each one actually costs and buys, and how to choose for your team instead of the internet's team.
There is no best styling strategy. There are trade-offs, and the teams that suffer are the ones who picked based on hype cycles instead of their actual constraints. Here's what twenty years of watching all four succeed and fail looks like.
BEM / naming-convention CSS
.card { }
.card__title { font-size: 1.25rem; }
.card--featured { border-color: var(--color-accent); }Block, element, modifier — one class per thing, flat specificity (0,1,0) everywhere, no nesting. Costs: verbose class names, discipline is manual (nothing stops a teammate from nesting .card .title and reintroducing specificity wars), global namespace collisions are possible. Buys: zero build tooling, zero runtime cost, trivially debuggable in DevTools, works with any backend. Still the right answer for content sites and apps with small teams and long-lived code.
Scoped CSS (CSS Modules, Vue SFC, Svelte)
/* Card.module.css */
.title { font-size: 1.25rem; }import styles from "./Card.module.css";
<h3 className={styles.title}> /* compiles to .Card_title_x7f2a */The build rewrites class names to be unique — collisions become impossible, and dead styles are grep-able because every class is referenced from exactly one component. Costs: dynamic class composition requires care, theming needs the custom-property escape hatch anyway. Buys: locality (the strongest form of encapsulation CSS has), zero runtime. This is the sensible default for component-based apps.
Utility-first (Tailwind)
<div class="flex items-center gap-4 rounded-lg border p-4 hover:bg-gray-50">Costs: markup noise, the design system lives in a config file and team convention rather than in enforceable structure, junior devs can ship inconsistent spacing by improvisation. Buys: no naming, no dead CSS (the compiler emits only used utilities), incredibly fast iteration, and — underrated — the constraint of a finite spacing scale, which is half of what design tokens give you, for free. The honest failure mode: long class strings nobody reads, duplicated across files, that should have been extracted into a component. The fix is almost never @apply — it's extracting the component.
CSS-in-JS (styled-components, emotion)
const Title = styled.h3`
font-size: 1.25rem;
color: ${p => p.$muted ? "gray" : "inherit"};
`;Costs: runtime overhead (or complex compile-time extraction), server-rendering edge cases, debugging is indirect, and the ecosystem has partially abandoned runtime CSS-in-JS — even styled-components' maintainers steered people away. Buys: colocation, props-driven dynamic styles, dead-simple composition. Today: fine on existing codebases, hard to justify starting fresh in 2025+ given that scoped CSS + custom properties covers the same ground without the runtime.
The actual decision framework
Ask: does the team need enforced encapsulation (scoped), maximum iteration speed (utility), or zero tooling (BEM)? Then enforce the choice mechanically — lint rules against mixing strategies, because the worst outcome isn't any of the four, it's all four at once, which is what ungoverned codebases drift into.
Field notes
- Whatever you choose, cascade layers and design tokens (lessons 2 and 7) compose with all of them — they're strategy-independent infrastructure.
- "Our CSS is a mess" is almost never solved by switching strategies. It's solved by deleting dead CSS and enforcing boundaries, which is unglamorous and works in any strategy.
Was this lesson helpful?