Styling approaches for React

Beginner · 6 min

CSS Modules, CSS-in-JS, and Tailwind compared honestly, including the styled-components backlash, with a short decision guide at the end.

Before thisComponents and propsCompound components

Fireship · 6 min

Styling approaches for React

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by FireshipReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A React component's markup and its styling are two separate concerns, and React itself has no opinion on which styling approach you use.
  • CSS Modules give you real CSS, scoped per file by a build-time class name rewrite, with zero runtime cost.
  • CSS-in-JS libraries like styled-components and Emotion colocate styles with components and support dynamic, prop-driven styles, but they ran that logic in the browser, and that runtime cost is why styled-components moved to maintenance mode in 2025.
  • Tailwind skips custom CSS almost entirely by giving you a large vocabulary of single-purpose utility classes directly in your JSX.
  • None of these approaches is strictly correct. The right one depends on team size, how dynamic your styles need to be, and how much custom visual design the project has.
  • A project can and often does mix approaches, for example Tailwind for layout and a CSS Module for one complex, highly custom component.

Styling is a separate decision from components

Nothing about JSX or the component model tells you how to style anything. A <button> is just an element, and the class or style you attach to it can come from plain CSS, a bundler-processed module, a JavaScript library, or a framework of utility classes. By the time you reach this lesson you already know how to build components and compose them (compound-components), so the question left is purely: where does the CSS live, and how does it get attached?

Three approaches dominate real React codebases today: CSS Modules, CSS-in-JS, and utility-first CSS. This lesson is a survey of their tradeoffs, not a tutorial in any one of them.

CSS Modules: scoped, boring, and that’s a compliment

A CSS Module is an ordinary .css file with one rule: its class names are local to the file that imports it.

/* Card.module.css */
.card {
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
import styles from "./Card.module.css";

function Card({ children }) {
  return <div className={styles.card}>{children}</div>;
}

At build time, the bundler rewrites .card into something like Card_card__a1b2c and rewrites styles.card to match, so a .card class in another file’s module never collides with this one. You get real CSS — every selector, pseudo-class, and media query you already know — with no runtime library, no extra JavaScript shipped to the browser, and full editor support for CSS itself. The cost is that dynamic styling (a color that depends on a prop) needs a workaround, usually inline styles or toggling between a few predefined classes.

CSS-in-JS: styled-components, Emotion, and the backlash

CSS-in-JS libraries let you write CSS inside a JavaScript template literal, attached directly to a component:

import styled from "styled-components";

const Button = styled.button`
  background: ${(props) => (props.variant === "danger" ? "#dc2626" : "#2563eb")};
  padding: 8px 16px;
  border-radius: 6px;
  color: white;
`;

<Button variant="danger">Delete</Button>;

This is genuinely convenient: the style lives next to the component, and it can read props directly, so dynamic styling is trivial. The honest problem is cost. Parsing those template literals and injecting <style> tags happens in the browser, on every render that touches a styled component, and at scale that measurably slows an app down compared to plain CSS or CSS Modules. That tradeoff is not hypothetical — it’s the reason styled-components itself moved into maintenance mode in 2025, with its own maintainers pointing people toward zero-runtime alternatives. Emotion has similar runtime costs, though it optimizes harder than styled-components did. If you reach for CSS-in-JS today, know what you’re trading for the convenience.

Utility-first CSS: Tailwind

Tailwind takes a different bet: instead of writing CSS at all, you compose a design system’s worth of small, single-purpose classes directly in your markup.

function Card({ children }) {
  return (
    <div className="rounded-lg p-4 shadow-md bg-white dark:bg-slate-800">
      {children}
    </div>
  );
}

There is no separate stylesheet to maintain per component, no naming to invent, and a build step strips every class you never used, so shipped CSS stays small regardless of project size. The tradeoff is upfront: class lists get long, and reading a component’s visual design means reading a string of abbreviations rather than named CSS properties. Teams either get fast with it or find it noisy; there is not much middle ground.

A short decision guide

  • Small team, design-system-driven, want to move fast without naming things: Tailwind.
  • Need standard, debuggable CSS with zero runtime cost, and don’t mind a .module.css file per component: CSS Modules.
  • Heavily prop-driven, highly dynamic visual styling where colocating logic and style actually pays off, and runtime cost is an acceptable tradeoff for your app’s scale: CSS-in-JS, but prefer a zero-runtime option over styled-components for a new project today.
  • Mixed is normal: Tailwind for layout and spacing, a CSS Module for one component whose styling is too complex for utility classes, is a common and reasonable combination.

What the video covers

Fireship’s “7 ways to deal with CSS” surveys inline styles, Sass, CSS Modules, styled-components, Tailwind, Emotion, and vanilla-extract at speed, with a quick code sample for each. It is a good fast map of the landscape, but it predates 2025 and doesn’t carry the styled-components backlash this lesson describes — that context comes from the sections above and the Better Stack link below.

Where this fits

Styling is independent of the rest of the React model, which is why this lesson only needed components and composition as prerequisites. Next, move from how a component looks to how you prove it behaves correctly: testing components with React Testing Library.

Check yourself

  1. 01Why does a CSS Module class name like `styles.card` not collide with a `.card` class defined in a different file?

    The build tool rewrites each class name in the module into a unique, file-scoped identifier such as `Card_card__a1b2c`, so two files can both use the name `card` without ever producing the same class in the compiled output.

  2. 02What specifically changed about styled-components that this lesson calls a backlash, rather than just a trend?

    Styled-components parses template-literal CSS and injects style tags at runtime in the browser, which adds a real performance cost on every render path that touches a styled component, and by 2025 that cost, plus the rise of zero-runtime and utility-first alternatives, led the maintainers to put the project into maintenance mode rather than continued active development.

  3. 03What is the main criticism people have of writing Tailwind's utility classes directly in JSX?

    Class lists on elements can get long and visually noisy, since every spacing, color, and layout decision becomes an inline class string rather than a named, reusable style.

  4. 04If a component needs a background color that is computed from a prop at render time, which of the three approaches handles that most directly without extra tooling?

    CSS-in-JS, because a styled-components or Emotion template literal can read the component's props directly and interpolate a value into the generated CSS; CSS Modules and Tailwind both need an extra step, such as inline styles or a lookup table of class names, to express the same thing.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark