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)