Utility Classes vs BEM Components
You'll learn when to reach for single-purpose utility classes instead of BEM component classes, and how to use them together effectively.
BEM gives you structured component classes like .card__title--featured, but sometimes you need quick, reusable helpers. Utility classes are single-purpose classes that apply one specific style, like .text-center or .mb-2 (margin-bottom).
The Core Difference
BEM components encapsulate a UI piece with all its structural styles and variations. Think of them as custom-built furniture—tailored exactly to your needs.
Utility classes apply one atomic style rule. They're like adjustment tools—a shim here, a spacer there—that work on anything.
When to Use Each
Use BEM for:
- Component structure and layout (
.product-card,.product-card__image) - Component-specific styling (
.nav__link--active) - Anything that defines what something is
Use utilities for:
- Spacing adjustments (margins, padding)
- Text alignment or color overrides
- Display properties (
display: none,display: flex) - Anything that tweaks presentation without changing identity
Using Them Together
You can (and should) combine both approaches:
<div class="product-card mb-3">
<h2 class="product-card__title text-center">
Widget Pro
</h2>
<p class="product-card__description">...</p>
</div>
Here .product-card handles the component's core styles, while mb-3 adds bottom margin and text-center aligns text—both quick adjustments that don't need custom BEM modifiers.
Key Takeaway: Use BEM for component identity and structure; use utility classes for common presentation tweaks and spacing. They complement each other—BEM provides the foundation, utilities provide the finishing touches.