CSS in React
-
This lesson introduces CSS in React and explains how to style components using different CSS techniques.
Topic Overview
Styling in React can be done in multiple ways, depending on project size, team preference, and complexity.
React does not force one styling method, giving developers full flexibility.CSS in React
Global CSS
Global CSS is normal CSS applied to the entire application.
Example:
/* index.css */
body {
margin: 0;
font-family: Arial;
}
import "./index.css";
Characteristics:
Applied to all components
Easy for small projects
Can cause style conflicts
👉 Best for:
Reset styles
Global themes
Common layout styles
Component-Level CSS
Component-level CSS is scoped logically by importing CSS into a component.
Example:
import "./Button.css";
function Button() {
return <button className="btn">Click</button>;
}
- Still global in nature, but organized per component.