A comprehensive guide to frontend styling approaches: CSS Modules, Tailwind CSS, CSS-in-JS, vanilla CSS, and CSS custom properties vs preprocessors.
CSS ModulesTailwind CSSCSS-in-JSVanilla CSS
What Are Styling Approaches?
A styling approach is the strategy your application uses to apply visual styles to HTML elements. The choice determines how styles are scoped, bundled, maintained, and delivered to the browser.
In the early days of the web, you wrote a single CSS file and included it in your HTML. Selectors were global, naming was a matter of convention, and styles cascaded freely. As web applications grew into complex single-page apps with component architectures, the industry developed new solutions: CSS Modules for scoping, CSS-in-JS for dynamic styles, and utility-first frameworks like Tailwind for rapid development.
Today, the styling landscape has four major contenders:
Vanilla CSS — plain CSS files with global selectors, optionally organized with naming conventions like BEM
CSS Modules — locally scoped CSS via build-time class name transformation
CSS-in-JS — styles written in JavaScript, injected at runtime or extracted at build time
Tailwind CSS — utility-first framework that composes styles from atomic classes
Each approach makes a different tradeoff between bundle size, runtime cost, developer experience, SSR support, and how well it scales across teams. The trick is matching the approach to your project's constraints and team's preferences.
1 · Vanilla CSS
Vanilla CSS is the original approach. You write plain CSS files, import them into your HTML or JavaScript, and styles are applied globally via the cascade. There is no build step, no tooling, and no abstraction layer — just CSS as the browser understands it.
To avoid naming collisions at scale, teams often adopt naming conventions like BEM (Block Element Modifier). BEM gives you a structured way to name classes: .block__element--modifier. It is a convention, not a tool — nobody is enforcing it but your code review.
/* Vanilla CSS — global styles with BEM naming *//* styles.css */.button { padding: 12px 24px; border-radius: 6px; font-size: 16px; cursor: pointer;}.button--primary { background: #0066ff; color: white; border: none;}.button--primary:hover { background: #0052cc;}/* Problem: all .button rules are global. Use BEM to avoid collisions. */
Pros
Zero dependencies: No build tool, no library, no runtime. Just CSS.
Smallest bundle size: No extra JS, no runtime injection. The browser parses CSS natively.
Universally supported: Every framework and every browser supports plain CSS.
SSR native: CSS files are loaded however you like — no SSR extraction needed.
Cons
Global namespace: Every selector is global. Collisions are a real problem at scale.
Manual scoping: BEM or similar conventions are self-enforced. No tooling prevents mistakes.
No dynamic styles: You cannot change a color based on a component prop without inline styles or class toggling.
Dead code elimination: Unused CSS rules persist unless you use PurgeCSS manually.
Warning
Vanilla CSS with a naming convention like BEM is still a solid choice for small-to-medium projects. But as your component tree grows beyond a few dozen components, the lack of enforced scoping becomes a maintenance burden. Every team member needs to know and follow the convention.
2 · CSS Modules
CSS Modules solve the global namespace problem at build time. When you import a CSS Module file (named *.module.css), the build tool transforms every class name into a unique, hashed identifier. The same class name in two different files produces two different hashes — styles are scoped to the component.
CSS Modules are supported by default in Next.js, Vite, and Create React App. No additional configuration needed.
In your component, you import the module and use it as a JavaScript object:
import styles from "./Button.module.css";
export function Button({ primary, children }: Props) {
return (
);
}
Pros
Real scoping: Class names are hashed and unique. No collisions, ever.
Zero runtime cost: The scoping happens at build time. The browser receives static CSS with hashed class names.
Standard CSS: You write plain CSS with all the features you know (media queries, animations, keyframes).
Dead code elimination: Unused CSS in a module is obvious and can be removed confidently.
Cons
Complex class composition: Combining multiple classes or adding conditional styles requires a utility library like classnames or cn().
No dynamic styling: CSS Modules are static. Values cannot change based on props.
Global styles still needed: Resets, fonts, and theme variables must live outside modules.
Key Insight
CSS Modules hit a sweet spot for many projects. You get real scoping with zero runtime cost, using standard CSS syntax. Next.js, Vite, and most modern bundlers support them out-of-the-box. If you need dynamic styles, you can combine CSS Modules with CSS custom properties — the variables change at runtime, the structure stays in the module.
3 · CSS-in-JS (styled-components & Emotion)
CSS-in-JS takes a different philosophy: styles are part of the component. You write CSS directly in your JavaScript files using tagged template literals or the css prop. The library generates unique class names, injects them into the DOM, and handles dynamic styles through props.
The two dominant libraries are styled-components and Emotion. Both solve the same problems with slightly different APIs.
styled-components
styled-components uses tagged template literals to create React components with attached styles. Props are interpolated directly into the CSS string, making dynamic styles feel natural.
Emotion offers two APIs: a styled-components-compatible API and a css prop that works with any element or component. The css prop is unique to Emotion and feels more "React-native" — styles are objects or template literals attached directly to elements.
True component isolation: Styles live with the component, die with the component. No global pollution.
Dynamic props: Styles respond to props natively. No conditional class name logic needed.
Dead code elimination: Unused components mean unused styles. Automatic.
No class name collisions: Unique hashed class names are generated for every styled component.
Cons
Runtime cost: Style injection happens in the browser. Every styled component adds JS execution time during rendering.
Bundle size: The library itself (styled-components is ~15 KB gzipped) plus serialized CSS strings in the bundle.
SSR complexity: Server-rendered CSS must be extracted and injected into the HTML. Both libraries support this, but it is not automatic.
Debugging: Runtime-generated class names are hard to inspect. Emotion and styled-components generate readable names in dev, but production hashes are opaque.
Warning
CSS-in-JS runtime cost is real. On low-end devices, the style injection phase can delay the first paint. If your target audience includes users on mid-range Android phones or slow networks, consider Emotion's zero-runtime alternative (@emotion/css) or a build-time extraction approach.
4 · Tailwind CSS
Tailwind CSS is a utility-first framework. Instead of writing custom CSS selectors, you compose styles by applying atomic utility classes directly in your HTML. Every utility maps to a single CSS property: p-4 sets padding,text-center centers text, and so on.
The idea sounds counterintuitive at first — "aren't we back to inline styles?" — but there is a key difference. Tailwind utilities are constrained by a design system defined in your configuration. You cannot write an arbitrary color or spacing value unless it is in your config. This enforces consistency across the entire codebase.
Tailwind scans your source files at build time, finds every class name, and generates only the CSS you actually use. The output is a tiny CSS file — often under 10 KB gzipped — with zero runtime JavaScript. No runtime cost, no style injection.
Pros
Minimal production CSS: Purged CSS means you ship only what you use. Typical production builds are 5-15 KB.
Zero runtime: All CSS is generated at build time. No JavaScript execution for styling.
Design system baked in: Colors, spacing, typography — all constrained by a central config file. Consistency is automatic.
Rapid prototyping: No context-switching between JS and CSS files. Everything lives in the template.
Team scaling: New developers learn the utility names, not a codebase's custom CSS. The config is the source of truth.
Cons
Readability: A long string of utility classes can look noisy. Patterns like cn() or component abstractions help.
Learning curve: You do not write CSS — you learn a new vocabulary of utility names.
Custom designs: Anything outside the config requires custom CSS or arbitrary value syntax.
HTML size: Utility classes add to your HTML size. On large pages, the class attribute itself can be hundreds of characters.
Tip
Tailwind v4 introduces the CSS-first configuration approach, where you define your design tokens in CSS rather than JavaScript. This aligns with the platform's move toward CSS custom properties as the single source of truth. If you are starting a new project today, Tailwind v4 is worth evaluating.
5 · CSS Custom Properties vs Preprocessors
Before CSS custom properties, the only way to use variables in CSS was through preprocessors like Sass, Less, or Stylus. They added variables, nesting, mixins, and functions — features vanilla CSS lacked.
Today, CSS custom properties (also called CSS variables) give you variables at the browser level, with a critical advantage over preprocessor variables: they are dynamic.
CSS Custom Properties
Defined with -- prefix and accessed with var(). They cascade, can be overridden per element, and can be changed at runtime via JavaScript. This makes them ideal for theming.
Preprocessor variables are compile-time only. You write Sass, it compiles to static CSS. The variable values are baked in and cannot change without a rebuild. But they offer features CSS custom properties cannot: mixins, loops, and nesting.
Follows CSS cascade (inherits, overrides per element)
Scoped to file, no cascade
Mixins
Not supported (use utility classes)
Yes — @mixin / @include
Nesting
Native nesting in modern CSS (2024+)
Yes — standard feature
Browser support
All modern browsers, IE11 with polyfill
Compiles to CSS — universal
Computation
Limited (calc() only)
Full functions, loops, math
Key Insight
Modern CSS has caught up to preprocessors on many fronts. Native nesting, container queries, and cascade layers eliminate some of Sass's biggest advantages. For most projects today, CSS custom properties + PostCSS (for nesting and future syntax) is a lighter alternative to Sass. Keep Sass only if you rely on mixins or complex build-time logic.
6 · Head-to-Head Comparison
Here is how the four major approaches stack up across the dimensions that matter most in production:
Figure 1 — Styling approach comparison across key metrics. No single approach wins in every dimension.
Dimension
Vanilla CSS
CSS Modules
CSS-in-JS
Tailwind CSS
Bundle size (CSS)
Minimal (hand-written)
Minimal (per component)
Library + serialized CSS
Smallest (purged)
Runtime cost
None
None
Style injection per render
None
Scoping
Global (BEM convention)
Build-time hashed
Runtime-generated
Global utilities + variants
Dynamic styles
Class toggling + inline
Class toggling + custom props
Native prop interpolation
Variant + custom props
SSR support
Native
Native
Requires extraction
Native (static CSS)
DX (Developer Experience)
Manual — naming conventions
Good — auto-scoped
Excellent — co-located
Great — config-driven
Team scaling
Hard — convention-dependent
Good — filename scoping
Moderate — coupling concern
Best — config enforcement
Learning curve
Low — standard CSS
Low — standard CSS
Medium — tagged templates
Medium — utility vocabulary
7 · Scoping Strategies
CSS scoping — preventing styles from leaking between components — is the central challenge that every approach addresses differently. The spectrum runs from globally-scoped vanilla CSS to fully-isolated CSS-in-JS.
Figure 2 — How each approach handles CSS scoping. The tradeoff is isolation vs. complexity.
How each approach scopes
Vanilla CSS + BEM: Convention-based. You write .block__element--modifier and hope everyone on the team follows the pattern. No enforcement.
CSS-in-JS: Runtime-generated unique class names like .sc-bdVaJa. Styles are injected into a <style> tag.
Tailwind: Global utility classes. Scoping is achieved by design — utilities are atomic and do not cascade in complex ways. The className attribute on each element explicitly declares every property.
Key Insight
Scoping is not binary. Even with CSS Modules or CSS-in-JS, you still need global styles for resets, fonts, and CSS custom properties. The question is: how much of your styling lives in the global scope vs. the component scope? The less global, the easier the maintenance.
8 · Design System Integration
A design system needs a styling approach that supports consistency, reusability, and theming. Each approach integrates with design systems differently.
Design tokens
Design tokens — colors, typography, spacing, shadows — are the foundation of any design system. How you define and consume them depends on your styling approach:
CSS custom properties: Tokens as --color-primary. Work everywhere, changeable at runtime. Best for theming.
Tailwind config: Tokens defined in tailwind.config (v3) or @theme (v4). Consumed via utility classes. Enforces constraints.
CSS-in-JS theme: A ThemeProvider passes a theme object down the tree. Consumed via props => props.theme.colors.primary. Dynamic and typed.
Sass variables: Tokens as $color-primary. Compile-time only. No runtime theming.
Component library distribution
If you are building a shared component library (like a design system package), the styling approach affects how consumers use it:
CSS Modules: Ship compiled CSS with hashed class names. Consumers cannot override styles easily unless you expose CSS custom properties.
CSS-in-JS: Ship the runtime components. Consumers get theming and style overrides via the theme object. But this requires the consumer to also use the same CSS-in-JS library.
Tailwind: Ship unstyled or lightly-styled components. Consumers compose with their own Tailwind config. The @tailwindcss/typography plugin pattern is a good model.
Tip
Most production design systems use a hybrid approach: CSS custom properties for theme tokens, a component library with scoped styles, and a utility framework for layout and spacing. No single approach covers all use cases.
9 · SSR & Build Considerations
Server-side rendering introduces specific requirements for styling. The browser must receive styles with the initial HTML to avoid a flash of unstyled content (FOUC).
Vanilla CSS — ideal
Link tags in the HTML head. CSS files are loaded by the browser as part of the initial critical path. No SSR extraction needed.
CSS Modules — ideal
Same as vanilla CSS. The build tool extracts CSS into separate files (or inline styles). Next.js and Vite handle this automatically.
Tailwind — ideal (static)
Tailwind generates a static CSS file at build time. SSR outputs the HTML with utility class names. No FOUC risk.
CSS-in-JS — requires extraction
Server renders components, collects generated CSS, and injects it into the HTML as a <style> tag. styled-components has ServerStyleSheet. Emotion has extractCritical. Next.js does this automatically with the styled-components compiler.
Zero-runtime CSS-in-JS
A newer category called "zero-runtime CSS-in-JS" (like Linaria, Vanilla Extract, or StyleX) compiles CSS at build time into static CSS files. You get the developer experience of CSS-in-JS — co-located, prop-driven — with the SSR characteristics of vanilla CSS. No runtime injection, no SSR extraction needed.
Warning
The biggest SSR risk with CSS-in-JS is FOUC. If your framework does not extract CSS during SSR, the browser renders the HTML without styles, then injects them on the client. The user sees a split-second of unformatted content. Next.js 13+ handles this for styled-components via the compiler option, but always verify in production.
10 · Team Scaling & DX
The right styling approach depends heavily on your team size and how you organize work. Here is how each approach scales:
Small teams (1-5 developers)
Small teams move fast and value simplicity. CSS Modules or a lightweight CSS-in-JS work well. Styles are co-located with components, scoping is automatic, and there is no need for elaborate conventions. Tailwind also shines here — one config-driven design system eliminates style decisions.
Large teams (10+ developers)
At scale, the key challenge is maintaining consistency across dozens of developers who may not know the codebase intimately. Tailwind's config-driven approach shines here: the design system is enforced by the configuration, not by code review. CSS Modules also work well because scoping is automatic and the CSS syntax is standard.
Cross-team design systems
When multiple teams share a design system, CSS-in-JS creates a runtime dependency that every consumer must adopt. Tailwind's utility approach or a vanilla-extract-based system scales better because the output is static CSS — any framework can consume it.
Scenario
Best fit
Why
Solo developer, static site
Vanilla CSS
No build overhead. Standard CSS works everywhere.
Small team, component-heavy app
CSS Modules
Scoped, zero-runtime, standard CSS. Sweet spot.
Rapid prototyping, startup
Tailwind CSS
Fast iteration, built-in design constraints, tiny prod CSS.
Tailwind for design constraints, CSS Modules for isolated overrides.
11 · When to Use Each Approach
Choosing a styling approach is about matching your project's constraints to the right tradeoffs. Here is a decision framework:
Figure 3 — Decision flowchart for choosing a styling approach. Start with your priority: bundle size, DX, or team scaling.
Quick decision guide
Reach for vanilla CSS when you need zero dependencies, maximum compatibility, and you are comfortable with manual naming conventions. Best for simple sites, email templates, or environments where npm is not available.
Reach for CSS Modules when you want standard CSS syntax with guaranteed scoping and zero runtime cost. This is the default recommendation for most React projects. Next.js, Vite, and Create React App all support it out of the box.
Reach for CSS-in-JS when dynamic, prop-driven styles are central to your application. If you are building a complex dashboard where a button's color depends on data, not just a variant prop, CSS-in-JS eliminates a layer of conditional logic.
Reach for Tailwind when team consistency and development speed are your top priorities. The config-based design system eliminates most style decisions. If you have ever spent 20 minutes debating the exact hex value of "brand blue," Tailwind solves that permanently.
Tip
The best teams do not pick one approach and stick with it dogmatically. They use Tailwind for layout and spacing, CSS Modules for complex component styles that benefit from named selectors, and CSS custom properties for theme tokens. The approaches are complementary, not mutually exclusive.
12 · Key Takeaways
Styling approaches are not a one-time framework decision. They are a strategy that evolves with your team and project. Here is what to remember:
There is no single best approach. Vanilla CSS, CSS Modules, CSS-in-JS, and Tailwind each make different tradeoffs. The right choice depends on your team, project, and performance requirements.
CSS Modules hit the sweet spot for many projects. Standard CSS syntax, automatic scoping, zero runtime cost. They work everywhere and are supported by every major framework.
Tailwind enforces consistency at scale. The config-based design system eliminates style drift across large teams. Production CSS is tiny thanks to purging.
CSS-in-JS is powerful but costly. The runtime overhead is real, especially on low-end devices. Consider zero-runtime alternatives (Linaria, Vanilla Extract, StyleX) for production applications.
CSS custom properties make preprocessors optional.Native variables, nesting, and cascade layers cover most of what Sass offers. Keep Sass only if you rely on mixins.
Hybrid is common and fine. Using Tailwind for layout, CSS Modules for components, and custom properties for theming is a pragmatic combination that many production apps use successfully.
Key Insight
The best styling approach is the one your team uses consistently. A "worse" approach used consistently across the entire codebase is better than a "better" approach that is used haphazardly. Pick one, document it, and move on to building features.