Component Styling
Get a bird's-eye view of every major way to style React components, from plain CSS files to utility frameworks and CSS-in-JS.
Introduction
React does not force you into a single way of styling your components. Unlike some frameworks that ship with an official styling solution, React leaves the choice entirely up to you — which is powerful, but can feel overwhelming when you first see how many options exist.
This lesson is a survey: a bird's-eye tour of the main approaches you will encounter in real React codebases. You will not go deep into any single one here — the next several lessons each dedicate themselves to one approach in detail. By the end of this lesson, you will know what options exist, roughly how each one works, and which situations they tend to fit best.
- The main categories of styling approaches available in React.
- How plain CSS files are imported and used in components.
- What CSS Modules and inline style objects look like at a glance.
- How utility frameworks like Bootstrap and Tailwind fit into React.
- What CSS-in-JS libraries are, briefly, and why they exist.
The Styling Landscape
Every styling approach in React ultimately produces the same thing — CSS applied to rendered HTML — but they differ in how class names are scoped, how dynamic values are handled, and how much tooling is required.
Plain CSS
One or more .css files imported into your app, styled the traditional way.
CSS Modules
.module.css files whose class names are automatically scoped per component.
Inline Styles
JavaScript objects passed directly to the style prop on an element.
Utility Frameworks
Prebuilt class names, like Bootstrap or Tailwind, applied straight in JSX.
CSS-in-JS
Libraries like styled-components that let you write CSS inside JavaScript files.
Plain CSS Files
The simplest approach is exactly what you likely already know from plain HTML and CSS: write a .css file and import it into a component. The styles apply globally to the whole page, exactly as they would in a non-React project.
import './Card.css';
function Card({ title, children }) {
return (
<div className="card">
<h3 className="card-title">{title}</h3>
<div className="card-body">{children}</div>
</div>
);
}
export default Card;.card {
border: 1px solid #e2e2e2;
border-radius: 8px;
padding: 16px;
}
.card-title {
font-size: 1.1rem;
font-weight: 600;
}Because plain CSS classes are global, two components that both define a class called .card can silently override each other. This is the exact problem CSS Modules were built to solve, which you will explore in the next lesson.
CSS Modules
CSS Modules look almost identical to plain CSS files, but with one crucial difference: the file is named with a .module.css suffix, and the build tool automatically rewrites every class name to be unique to that file. This means you get the scoping benefits of a component-based system while still writing ordinary CSS.
import styles from './Card.module.css';
function Card({ title }) {
return <div className={styles.card}>{title}</div>;
}Under the hood, styles.card resolves to something like card_a8f3e, guaranteeing no other component's .card class can ever collide with it. We will dig into this fully in the next lesson.
Inline Style Objects
React also lets you style an element directly using the style prop, passed as a JavaScript object rather than a CSS string. This is useful for styles computed at runtime, such as a progress bar width based on a percentage.
function ProgressBar({ percent }) {
return (
<div style={{ width: `${percent}%`, backgroundColor: '#4caf50' }} />
);
}Inline styles skip the CSS file entirely, trading some CSS features (like :hover) for the convenience of plain JavaScript values. You will look at this in depth two lessons from now.
Utility Frameworks
Frameworks like Bootstrap and Tailwind CSS ship large libraries of prebuilt, single-purpose class names — things like d-flex, p-3, or text-center — that you compose directly in your JSX className attribute instead of writing custom CSS rules yourself.
Bootstrap
A widely used component and utility library with prebuilt classes for buttons, cards, grids, and more.
Tailwind CSS
A utility-first framework offering small, composable classes for nearly every CSS property.
No Class Naming Decisions
You spend less time inventing class names and more time composing existing ones.
Larger Bundle Considerations
Utility frameworks add extra CSS to your project, though tools like Tailwind can trim unused classes.
You will get a full, hands-on lesson on using Bootstrap with React shortly after CSS Modules and inline styling.
CSS-in-JS Libraries
A final category worth knowing about is CSS-in-JS: libraries such as styled-components or Emotion that let you author actual CSS syntax inside your JavaScript or TypeScript files, often attached directly to a component definition.
import styled from 'styled-components';
const Button = styled.button`
background: #4f46e5;
color: white;
padding: 8px 16px;
border-radius: 6px;
`;
function App() {
return <Button>Click Me</Button>;
}CSS-in-JS libraries are popular in some codebases but require an extra package and add some runtime overhead. This course focuses on the built-in and most widely used approaches, so CSS-in-JS is mentioned here only for awareness, not covered in depth.
Choosing an Approach
There is no single "correct" choice — different teams and projects have different needs. The table below gives a rough sense of when each approach tends to shine.
| Approach | Best For | Trade-off |
|---|---|---|
| Plain CSS | Small projects, quick prototypes | Global scope, risk of class name collisions |
| CSS Modules | Component-scoped styling without new syntax | Requires a build step (handled by most tooling already) |
| Inline Styles | Small, dynamic, computed values | No pseudo-classes or media queries |
| Utility Frameworks | Fast, consistent UI without writing custom CSS | Verbose className strings |
| CSS-in-JS | Fully dynamic, theme-aware styling | Extra dependency and runtime cost |
Common Mistakes
- Assuming there is one "official" React styling method — React intentionally leaves this choice to you.
- Mixing too many approaches inconsistently within the same small project, making the codebase harder to navigate.
- Reaching for CSS-in-JS or a utility framework before understanding plain CSS and CSS Modules first.
- Forgetting that plain CSS class names are global and can unintentionally clash across components.
Best Practices
- Pick one primary styling approach per project and stay consistent with it.
- Reach for CSS Modules by default when you want component-scoped styles without new tooling.
- Save inline styles for genuinely dynamic, computed values rather than static design.
- Consider utility frameworks like Bootstrap or Tailwind when you want to move fast without hand-writing CSS.
- Evaluate CSS-in-JS only once you have outgrown the simpler options and need advanced theming.
Frequently Asked Questions
Which styling approach does React recommend officially?
React does not mandate one. The official docs mention several approaches, and the choice is left to the developer or team based on project needs.
Can I use more than one styling approach in the same project?
Yes, and it is common — for example, using CSS Modules for most components while adding small inline styles for computed values like a dynamic width.
Is Tailwind CSS the same as CSS Modules?
No. Tailwind provides prebuilt utility classes you compose in your markup, while CSS Modules let you write your own custom CSS that gets automatically scoped per component.
Do I need to learn CSS-in-JS to get a job with React?
Not necessarily. Many companies use plain CSS, CSS Modules, or utility frameworks. CSS-in-JS is popular in some codebases, but it is not a universal requirement.
What will the next few lessons cover?
The next three lessons go deep on CSS Modules, inline styling, and using Bootstrap with React, each with hands-on examples.
Key Takeaways
- React does not enforce a single styling approach — you choose based on your project's needs.
- Plain CSS files work like traditional web development but share one global scope.
- CSS Modules automatically scope class names per component while looking like normal CSS.
- Inline style objects are great for small, dynamic values but cannot express pseudo-classes or media queries.
- Utility frameworks like Bootstrap and Tailwind, and CSS-in-JS libraries like styled-components, are additional, popular options.
Summary
You now have a map of the styling landscape in React: plain CSS, CSS Modules, inline styles, utility frameworks, and CSS-in-JS libraries. Each solves the same underlying problem — making components look right — with different trade-offs around scoping, dynamism, and tooling.
With this overview in place, the next lesson dives deep into CSS Modules, the approach that gives you the safety of scoped class names while still writing ordinary CSS.
- You can name the major styling approaches available in React.
- You understand the basic trade-offs of each approach.
- You know what is coming in the next few lessons.
- You are ready to go deep on CSS Modules.