Styling in React

Subject: React

🧠 Styling in React — Overview for Multi-Page Tutorial

You can display each section below as a separate page in your app for learners to explore:


šŸ“„ Page 1: Inline Styles

šŸ” What It Is:

Inline styles in React are JavaScript objects that apply CSS directly to elements using the style prop.

āœ… Syntax:

šŸ”§ Notes:

  • CSS property names use camelCase (e.g., backgroundColor)
  • Good for quick styling or conditional styles
  • Not scalable for large projects

āš ļø Drawbacks:

  • No media queries or pseudo-selectors
  • Harder to maintain in big apps

šŸ“„ Page 2: CSS Modules

šŸ” What It Is:

CSS Modules are scoped CSS files that prevent class name conflicts by creating locally scoped styles.

āœ… Setup:

  • File must be named like: Component.module.css

Example:

šŸ”§ Benefits:

  • No class name collisions
  • Supports media queries, animations
  • Easy to maintain and scale

āš ļø Notes:

  • Works out of the box with CRA and Vite
  • Not ideal for dynamic theming

šŸ“„ Page 3: Styled Components / Emotion

šŸ” What It Is:

Styled Components and Emotion are libraries for CSS-in-JS styling — you write styles directly inside JavaScript using template literals.

āœ… Styled Components Example:

šŸ”§ Benefits:

  • Dynamic styling using props
  • Supports themes
  • No class name collisions
  • Styles are scoped to components

šŸ“Œ Emotion is similar but more flexible in large codebases.


šŸ“„ Page 4: Tailwind CSS

šŸ” What It Is:

Tailwind CSS is a utility-first CSS framework with pre-defined classes for rapid UI development.

āœ… Setup (Basic):

Add to tailwind.config.js and your CSS file:

āœ… Example:

šŸ”§ Benefits:

  • Fast development, consistent design
  • Responsive and mobile-friendly by default
  • No need to write custom CSS

āš ļø Drawbacks:

  • Class-heavy markup
  • Slight learning curve for beginners

🧠 Summary Table (For Home/Navigation Page)

Styling MethodDescriptionBest For
Inline StylesJS object applied directlyQuick fixes, dynamic inline values
CSS ModulesScoped CSS per componentMedium apps, avoiding global conflicts
Styled ComponentsWrite CSS inside JS as componentsLarge apps, dynamic styling, theming
Tailwind CSSUtility classes for fast designSpeed, consistency, responsive UI

šŸ”— Slug Links to Pages (For Navigation)

Each of the above can be added as a separate route/page for learners to deep-dive into each method.