๐Ÿ‹
Menu
Comparison Beginner 1 min read 292 words

CSS Naming Conventions: BEM vs SMACSS vs Atomic

Compare CSS naming methodologies and choose the right approach for your project size and team.

CSS Naming Methodologies

As CSS codebases grow, consistent naming conventions prevent specificity wars, make styles predictable, and enable confident refactoring. Different methodologies suit different project scales.

BEM (Block Element Modifier)

BEM uses a strict naming pattern: .block__element--modifier. Example: .card__title--highlighted. The double underscore separates blocks from elements, the double hyphen marks modifiers. BEM is explicit and self-documenting โ€” you know exactly what each class does and where it belongs. The trade-off is verbose class names that can clutter HTML.

SMACSS (Scalable and Modular Architecture)

SMACSS categorizes styles into five types: Base (defaults), Layout (page structure), Module (reusable components), State (dynamic changes), and Theme (visual theming). Each category has naming conventions: .l- for layout, .is- for state. SMACSS is less prescriptive than BEM, which can be either a benefit (flexibility) or a drawback (inconsistency).

Utility-First (Atomic CSS / Tailwind)

Instead of semantic class names, use small, single-purpose utility classes directly in HTML: class="flex items-center gap-4 p-2 rounded-lg bg-white shadow". This eliminates naming entirely for most styles. The trade-off: HTML becomes verbose, and design changes require updating every template that uses those classes. Tailwind CSS is the dominant utility-first framework.

Choosing a Methodology

Small projects (personal sites, marketing pages): utility-first is fastest. Medium projects (SaaS products, apps with designers): BEM provides structure without excessive overhead. Large projects (enterprise, design systems): combine BEM for components with utilities for one-off adjustments. Legacy projects: adopt the convention that requires the least refactoring of existing code.

Consistency Over Methodology

The specific methodology matters less than using it consistently. A codebase mixing BEM and SMACSS and ad-hoc naming is worse than a codebase using any single approach uniformly. Document your chosen approach, enforce it in code review, and add linting rules to catch violations.

็›ธๅ…ณๅทฅๅ…ท

็›ธๅ…ณๆ ผๅผ

็›ธๅ…ณๆŒ‡ๅ—