CSS Methodologies
๐ Covered in this chapter:
BEM ยท OOCSS ยท SMACSS ยท Utility-First ยท Component-Driven ยท CSS Modules ยท Scoped Styles ยท Tailwind ยท Choosing Methodology ยท Large Project Maintenance
Welcome to Chapter 41: CSS Methodologies โ part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
๐ What You Will Learn
- BEM, OOCSS, SMACSS methodologies comparison
- Utility-first CSS (Tailwind) vs component-driven CSS trade-offs
- CSS Modules and scoped styles in modern frameworks
- Choosing the right methodology for your project size
- Maintaining CSS in large teams and long-term projects
๐ก Why This Matters
There is no single "best" CSS methodology. A startup MVP might use Tailwind utilities for speed. An enterprise design system uses BEM + component library. Understanding all approaches helps you pick the right tool and communicate with any team.
1Methodology Comparison
| Methodology | Core Idea | Best For |
|---|---|---|
| BEM | Block__Element--Modifier naming | Component libraries, design systems |
| OOCSS | Separate structure from skin (appearance) | Reusable object patterns |
| SMACSS | 5 categories: Base, Layout, Module, State, Theme | Large organized codebases |
| Utility-First | Small single-purpose classes (Tailwind) | Rapid prototyping, startups |
| CSS Modules | Scoped class names at build time | React/Vue component apps |
2BEM vs Utility-First โ Same UI, Two Approaches
CSS โ BEM Approachโถ Try in Editor
/* CSS */
.btn { padding: 10px 20px; border-radius: 8px; font-weight: 600; }
.btn--primary { background: #2563eb; color: #fff; }
.btn--large { padding: 14px 28px; font-size: 1.125rem; }
HTML โ Tailwind Utility Approachโถ Try in Editor
BEM pros: Semantic HTML, reusable components, smaller HTML. Utility pros: No context switching, no naming fatigue, rapid iteration.
3CSS Modules & Scoped Styles
CSS Modules โ React exampleโถ Try in Editor
/* Button.module.css */
.primary {
background: #2563eb;
color: #fff;
padding: 10px 20px;
border-radius: 8px;
}
/* Button.jsx */
import styles from './Button.module.css';
export function Button() {
return ;
}
/* Compiled class: Button_primary_x7f2a */
Build tool automatically scopes class names โ zero global conflicts. Vue SFC <style scoped> similar concept.
4Choosing a Methodology & Large Project Maintenance
- Small project / MVP: Utility-first (Tailwind) or single organized CSS file
- Medium team / design system: BEM + CSS variables + component folder structure
- React/Vue SPA: CSS Modules or styled-components + design tokens
- Maintenance tips: Stylelint linting, PurgeCSS unused removal, Storybook component docs, CSS review in PRs
โ Mini Quiz
Q1 Utility-first CSS main disadvantage enti?
HTML becomes verbose with many classes. Harder to enforce consistent design without discipline. Component extraction needed for repeated patterns.
Q2 CSS Modules global conflicts enduku prevent chestayi?
Build tool hashes class names uniquely per file โ .primary becomes .Button_primary_x7f2a at compile time.
โ
Quick Recap
- BEM for component naming, SMACSS for file organization, OOCSS for separation of concerns
- Tailwind/utility-first = speed; BEM/components = maintainability at scale
- CSS Modules auto-scope classes in JS frameworks
- Pick methodology based on team size, project lifespan, and framework
- Linting + component docs + design tokens = long-term CSS health