DEV Community

Aman Kureshi
Aman Kureshi

Posted on

Inline CSS vs External CSS in React Components 🎨

When styling React components, you can use inline CSS or external CSS files. Both have their pros and cons.

🎯 Inline CSS:
β€’ Defined directly inside the JSX as an object
β€’ Styles are scoped to that component
β€’ Quick for small components

<div style={{ color: "blue", fontSize: "20px" }}>Hello</div>
Enter fullscreen mode Exit fullscreen mode

🎯 External CSS:
β€’ Defined in .css files
β€’ Easier for large projects
β€’ Keeps code clean & reusable

.text {
  color: blue;
  font-size: 20px;
}
Enter fullscreen mode Exit fullscreen mode
<div className="text">Hello</div>
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Which to use?
β€’ Small, dynamic styles β†’ Inline CSS
β€’ Big apps & reusable styles β†’ External CSS

Top comments (0)