Skip to main content
Saved
Guide strategy Intermediate 4 min read

Choosing a CSS Strategy

Choosing between BEM, CSS-in-JS, utility-first CSS, and CSS Modules for your team and your project.

The way your team writes CSS affects whether it can ship features quickly or ends up struggling with specificity conflicts. This guide compares the main approaches, so you can work out which one suits your team and your project.

Assess Your Situation First

Before you adopt a CSS strategy, it’s worth looking at a few things about your team and your project:

  • Team structure: If your design and engineering teams work closely together, BEM works well. If they work more independently, CSS Modules or stricter isolation can stop styles from accidentally conflicting.
  • Build tooling: With modern build tools and frameworks such as Vite and Next.js, CSS Modules are straightforward to set up. If you have a serverless or custom rendering setup, it’s worth looking carefully at the extra runtime work that CSS-in-JS adds, especially how it affects hydration timing.
  • Design system maturity: If you already have an established design system and tokens, Utility-First CSS or CSS-in-JS work well. If you don’t have standardized design tokens yet, a simple naming convention can keep your styles consistent while the design system matures.
  • Performance requirements: With CSS Modules and utility-first approaches, the styles are built into plain CSS files ahead of time, so no JavaScript has to run to apply them. CSS-in-JS can add work at runtime, and that can affect your Core Web Vitals.

Evaluate the Core Options

BEM Class Naming

BEM Class Naming uses a structured naming system, Block__Element--Modifier, so that your globally scoped CSS stays predictable. The class names can be verbose, but the convention makes it clear what each class belongs to, and it helps you avoid conflicts.

Choose BEM when:

  • You want plain global CSS that doesn’t need a build step, for example on a server-rendered site built with progressive enhancement
  • Multiple teams work together on shared UI components
  • Designers already think in terms of reusable blocks and variations

Keep it manageable: If your team doesn’t agree on rules for using BEM, you can end up with deeply nested class names like .header__nav__list__item__link--active--hover--mobile. If you pair it with Design Tokens and Folder Organization, your stylesheets can stay readable as they grow.

CSS Modules & Scoped Styles

CSS Modules automatically scope class names to each component, so styles in one component don’t conflict with styles in another. You get scoped styles without being tied to a framework.

Choose CSS Modules when:

  • You want to write standard CSS without worrying about class name conflicts
  • You’re building component libraries used across several projects, where global styles make the components harder to reuse
  • Your build tool supports CSS module imports like import styles from "./button.module.css", which most modern bundlers do

Extra protection: Embedded third-party widgets sometimes come with global CSS that can override your styles, and Style Isolation stops those widget styles from affecting your components.

Utility-First CSS

With Utility-First CSS, you build UIs quickly out of small, single-purpose classes, such as p-4 or text-blue-500. Developers tend to either love it or hate it.

Choose Utility-First when:

  • Teams build many UI variations and want to avoid debates over class names
  • Your design system already uses tokenized spacing and colors, because without tokens your styles quickly become inconsistent
  • You want to iterate quickly, with unused styles removed automatically

Keep markup readable: If your team isn’t careful, class lists can get very long, such as <div class="mt-4 md:mt-6 lg:mt-8 xl:mt-10 2xl:mt-12 hover:mt-3 focus:mt-5">. Linting and clear Design Token rules can keep them under control.

CSS-in-JS

With CSS-in-JS, you write styles directly in JavaScript, so they can change based on props or state. That makes dynamic styling easy, but you’ll need to implement it carefully to keep the runtime overhead down.

Choose CSS-in-JS when:

  • Components need styles that change with themes or runtime data. If you only want styles next to your components, CSS Modules can do that too
  • Your SSR setup supports zero-runtime CSS extraction, or you’ve accepted the performance trade-off
  • You already use a Theme Provider and need programmatic access to design tokens

Performance tip: Styles generated from props might be recalculated on every render. It helps to memoize and cache dynamic styles, especially in large lists, where that extra work adds up.

Combine Strategies When It Makes Sense

In my experience, you don’t have to stick to one approach.

  • Foundation + Layout: BEM or CSS Modules for design system components that don’t change much, with utility-first classes for page layouts that change often.
  • Static + Dynamic: You can keep most components in CSS Modules, and only use CSS-in-JS where you need dynamic theming or styles that respond to runtime data.
  • Design tokens everywhere: It helps to define values such as spacing and color in one place, whichever CSS strategy you choose. Otherwise, values that should match tend to drift apart over time.

Quick Decision Guide

Your SituationBest StrategyReason
Refactoring existing global CSSBEM Class NamingYou can improve it a piece at a time without rewriting your build pipeline
Building a shared component libraryCSS ModulesPrevents conflicts across projects, and the teams using the library don’t have to adopt your framework
Prototyping and iterating quicklyUtility-First CSSTeams can ship UI changes without debating semantic class names
Dynamic theming or personalizationCSS-in-JSStyles can change at runtime, but it’s worth measuring the performance cost and checking whether CSS custom properties already cover your theming

Next steps: It’s worth documenting your decision before different developers start using different approaches in different parts of the codebase, and updating your linting rules so they enforce it. You’ll also want to revisit the choice as your team and your requirements change.

Next Guide · 13 min read

Choosing a Frontend Framework

The criteria I use to choose between React, Vue, Svelte, Angular, and other frontend frameworks on real projects.

Read the next guide →

Keep Exploring

A monthly email
from Den Odell.

What I'm thinking about frontend patterns, plus news when the site changes.

No spam. Unsubscribe anytime.