While importing plain CSS files into components feels modular, standard imported CSS files are completely global!
Importing import './cards.css' inside CourseCard.jsx does not restrict the .card-title class to CourseCard. If another developer creates UserProfile.jsx and imports profile.css with a .card-title class, both rules conflict globally across the entire application:
1Component A imports: .card-title { color: blue; }
2Component B imports: .card-title { color: red; font-size: 20px; }
3Result: Cascading conflict! Whichever CSS rule loads last overrides the other!
4. Best Practices for Plain CSS in React
If using traditional CSS stylesheets without CSS Modules or Tailwind:
Follow BEM (Block-Element-Modifier): Use strict naming prefixes like .msk-course-card, .msk-course-card__title, .msk-course-card--highlighted to prevent global name clashes.
Global Design Tokens in index.css: Place CSS variables (:root { --primary-color: #0284c7; }), base resets, and typography in index.css.
Prefer CSS Modules or Tailwind CSS for Enterprise Apps: Use modern scoped tools to eliminate global namespace collisions entirely.
Interactive Quiz• Knowledge Check
Practice Quiz
Question 1
How do you import an external CSS file into a React component when using Vite?
Question 2
Why can importing plain CSS files across many components lead to bugs in large applications?
Question 3
What CSS methodology uses Block, Element, and Modifier naming to prevent namespace collisions?
Question 4
Where are global resets and CSS root variables typically imported in a Vite React project?
Question 5
Does standard external CSS support pseudo-classes like :hover and media queries?
Next Lesson
CSS Modules for Scoped Component Styling
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.