Full answer
React does not decide how you style. It only renders className and style props. Each approach trades something.
Plain CSS with global class names is simple, but names collide in a large app and dead code is hard to find. A naming convention such as BEM reduces the problem.
CSS Modules scope class names per file at build time: styles.button becomes a unique class. There is no runtime work, normal CSS syntax is kept and server rendering works well. Dynamic variants use a class switch or CSS custom properties.
Utility-first CSS such as Tailwind composes small classes in markup. There is no naming and the output CSS is small, but markup gets long, so teams extract components. It works with Server Components.
CSS-in-JS libraries (styled-components, Emotion) write CSS in JavaScript with props-based styling. Runtime versions add JavaScript work during render and are harder to use with Server Components and streaming, so many teams moved to zero-runtime options (Vanilla Extract, Panda, Linaria) that extract CSS at build time.
Inline style objects (style={{ color }}) have no pseudo-classes, media queries or cascade, and a new object each render. They are right for values that truly change at runtime, such as a width from state. A good combination is classes for structure and CSS custom properties set inline for dynamic values: style={{ '--progress': '40%' }}.
Whatever you pick, keep design tokens (colours, spacing) in one place and make components accept a className so callers can adjust them.
The example uses a class for structure and a custom property for the dynamic value.
const css = `
.bar { background: #eee; height: 8px; }
.bar > span { display: block; height: 100%; width: var(--progress); background: teal; }
`;
function ProgressBar({ percent, className = '' }) {
return (
<div className={'bar ' + className} style={{ '--progress': percent + '%' }}>
<span />
</div>
);
}
export default function App() {
return (
<div>
<style>{css}</style>
<ProgressBar percent={40} />
<ProgressBar percent={85} className="wide" />
</div>
);
}Structure lives in CSS and the changing value is passed through a custom property. A real project would keep the CSS in a file or a CSS Module. Rendered result: <div><style> .bar { background: #eee; height: 8px; } .bar > span { display: block; height: 100%; width: var(--progress); background: teal; } </style><div class="bar " style="--progress: 40%;"><span></span></div><div class="bar wide" style="--progress: 85%;"><span></span></div></div>
Key points
- React renders className and style. The styling system is your choice.
- CSS Modules and utility classes have no runtime cost and suit server rendering.
- Runtime CSS-in-JS costs render time and complicates Server Components. Zero-runtime options avoid it.
- Inline styles lack pseudo-classes and media queries. Use them for a few dynamic values.
- Classes plus inline CSS custom properties is a clean way to handle dynamic values.
Common mistakes
- Using inline style objects for everything and losing hover states and media queries.
- Using runtime CSS-in-JS in a Server Components app without checking support.
- Letting components ignore className so they cannot be adjusted.
- Mixing three styling systems in one project.
- Hard-coding colours instead of using tokens.
Follow-ups
- Why is runtime CSS-in-JS a problem for Server Components?
- How do CSS Modules produce unique class names?
- How would you build a theme with CSS custom properties and a toggle?
Tips
- Compare by runtime cost and server rendering support. Those are the real differences.
- Do not argue for one tool. Show a decision rule.
- Mention CSS custom properties for dynamic values. It is a modern, practical answer.