React does not enforce a single CSS system, so teams choose between plain stylesheets, CSS Modules, inline style objects, and utility frameworks like Tailwind CSS. Each method solves different problems around style scoping, dynamic values, and bundle size.
Pick a styling method based on team size, dynamic theme needs, and build tooling. CSS Modules keep styles isolated without extra runtime overhead, whereas Tailwind CSS speeds up layout work directly inside JSX class attributes.
| Approach | Scoping | Dynamic Styling | Best Use Case |
|---|---|---|---|
CSS Modules (.module.css) |
Local to component | Combine class names | Medium to large apps |
| Tailwind CSS | Utility classes | Conditional strings | Fast UI development |
Global .css import |
Global cascade | Class toggling | Base resets and fonts |
Inline style={{ ... }} |
Element only | Direct JS values | Dynamic coordinates or widths |
Vite and Next.js support CSS Modules out of the box for any file ending in .module.css. Imported class names receive unique hashes at build time so .badge in one component never collides with .badge in another.
/* AlertBox.module.css */
.box {
padding: 12px 16px;
border-radius: 8px;
border: 1px solid #cbd5e1;
}
.urgent {
border-color: #dc2626;
background-color: #fef2f2;
}
import styles from './AlertBox.module.css';
export function AlertBox({ urgent, progress, message }) {
const boxClass = urgent ? `${styles.box} ${styles.urgent}` : styles.box;
return (
<div className={boxClass}>
<p>{message}</p>
<div style={{ width: `${progress}%`, height: '4px', background: '#2563eb' }} />
</div>
);
}
style={{ 'background-color': 'red' }} or missing camelCase (backgroundColor) fails type checks and triggers warnings.style objects cannot express :hover, :focus-visible, or @media queries. Reserve inline styles for runtime numbers like progress bar widths.Use template literals (${styles.btn} ${styles.primary}) or a tiny helper package like clsx to join conditional class strings.
import './Card.css' files?No. Standard CSS imports remain global across your entire app, which is why CSS Modules or Tailwind CSS are preferred for component isolation.
'px' on numeric inline CSS properties?Yes. For properties like width: 24 or paddingTop: 12, React appends 'px' automatically unless the property is unitless like opacity or zIndex.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With