DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • The Box Model
  • Specificity & The Cascade
  • CSS Units Deep Dive
  • Stacking Contexts & Z-Index
  • Flexbox Mastery
  • CSS Grid Mastery
  • Centering, Subgrid & Container Queries
  • CSS Custom Properties & Variables
  • Selectors: :has(), Pseudo-classes & Pseudo-elements
  • Responsive Functions: calc(), clamp(), min(), max()
  • Media Queries & Mobile-First Design
  • Transitions & Animations
  • Transforms, Filters & Clipping
  • CSS Methodologies: BEM, CSS-in-JS & Tailwind
  • Typography, Color Spaces & Dark Mode
  • CSS Performance & Optimization
  • CSS Interview Questions — Part 1
  • CSS Interview Questions — Part 2
← From Beginner to Expert in Fundamentals of Frontend

CSS Methodologies: BEM, CSS-in-JS & Tailwind

18 min read
BEMCSS ModulesCSS-in-JSTailwind CSSCSS NestingShadow DOM::part()Atomic CSS

Organizing CSS at Scale

As projects grow, CSS becomes unmanageable without a clear methodology. Here are the major approaches:

Methodology Comparison

ApproachScopingBundle SizeDXBest For
BEMConvention-basedCan grow largeClear namingTraditional websites
CSS ModulesBuild-tool scopedModerateImport as objectReact/Vue apps
CSS-in-JSRuntime scopedLarger (JS overhead)Co-located with componentsDynamic styling needs
Tailwind CSSUtility classesSmall (purged)Fast prototypingRapid development
Atomic CSSSingle-purpose classesVery smallSteep learning curveHigh-traffic sites

BEM (Block Element Modifier)

A naming convention that makes CSS relationships explicit:

  • Block: The component itself → .card
  • Element: A part of the block → .card__title (double underscore)
  • Modifier: A variation → .card--featured (double dash)

CSS Nesting (Native)

Modern browsers now support native CSS nesting, eliminating the need for preprocessors just for nesting:

.card {
  padding: 1rem;
  &__title { font-weight: bold; }
  &--featured { border: 2px solid var(--primary); }
  &:hover { transform: translateY(-2px); }
  @media (width >= 768px) { padding: 2rem; }
}

Tailwind CSS Philosophy

Utility-first: compose designs directly in HTML using small, single-purpose classes. Benefits:

  • No naming fatigue — classes describe what they do
  • Dead code elimination (tree shaking) produces tiny CSS bundles
  • No specificity conflicts — all utilities have equal specificity
  • Responsive and state variants built-in: md:flex hover:bg-blue-500

Shadow DOM Styling

SelectorPurpose
::part(name)Style exposed parts of a shadow DOM
::slotted(selector)Style slotted (projected) content
:hostStyle the shadow DOM host element
:host-context(.dark)Style based on ancestor context

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.