liveBook · Manning

Style

As explained in React in Depth

Styling is the specification and application of visual presentation rules for an interface.

Styling specifies and applies visual presentation rules to an interface. React projects can express those rules through CSS files and class names, CSS Modules, styled-components, inline CSS, or Tailwind CSS; no approach is universally best because project, team, audience, and preference change the trade-offs. section 7.0 section 7.6

Select a styling approach by weighing language support, developer experience, and application behavior:

  • Use CSS files and class names for familiarity and simplicity, especially when a project is small; expect weaker scaling and possible class-name collisions. section 7.0 section 7.7
  • Use CSS Modules when autogenerated class names can improve collision resistance and scaling without substantially changing regular CSS authoring. section 7.7
  • Use styled-components when colocating JavaScript, HTML, and CSS improves component overview, particularly in medium-to-large projects; reassess the benefits for very large components. section 7.7
  • Compare inline CSS and Tailwind CSS alongside the other options rather than treating any library as a default, because ecosystems and requirements change. section 7.6
Table 7.1 Evaluating CSS methods on several attributes
Category and attribute
Inline CSS
CSS files
CSS Modules
Styled- components
Tailwind CSS
Folder
inline
classnames
cssmodules
styled
tailwind
CSS language features
Specificity
!
✗
!
✓
✗
Collisions
✓
✗
✓
✓
✓
Composition
✗
!
✓
✓
!
Pseudoclasses
✗
✓
✓
✓
!
Pseudoelements
✗
✓
✓
✓
!
At-rules
✗
✓
✓
✓
!
Conditional rules
✗
✗
✗
✓
✓
Dynamic rules
✓
✗
✗
✓
✓
Vendor prefixes
✗
✗
✗
✓
✓
DX
Colocation
✓
!
!
✓
✓
Familiarity
✓
✓
✓
!
✗
Simplicity
!
✓
!
!
✗
Scaling
✗
✗
!
✓
✓
Readability
!
✓
✓
!
✗
Debugging
✓
✓
!
✓
!
Encapsulation
✗
!
!
✓
✓
Theming
✗
!
!
✓
✓
Web application development
Bundle size
✗
✓
✓
!
!
Performance
✗
!
!
✓
✓
Cacheability
✗
✓
✓
!
✓
Code-splitting
!
!
!
✓
✓
Maintenance
!
✓
✓
✓
✗

Compare styling methods across CSS features, colocation, scaling, debugging, encapsulation, theming, performance, cacheability, code-splitting, and maintenance. section 7.6

Style an application shell

In a Remix expense tracker, add root styles through app/root.tsx or an imported stylesheet, then create a menu component and menu-item component. Extend Remix Link for navigation, highlight the current item, and render logout as a submit button inside a Form rather than as a link. Reuse menu-item styles while preserving the button’s form behavior. section 12.2.1

How React in Depth covers it

How deep it goes
Compares five approaches, implements three, and leaves inline CSS and Tailwind CSS as linked implementations rather than detailed treatments.
Examples
Uses an expense-tracker shell with root styles, authorization-sensitive menus, highlighted navigation, and a styled logout form.
What it assumes
Assumes React and CSS familiarity while introducing the comparative concerns behind styling solutions.
What you can do after
Evaluate styling options and apply a chosen approach to React components and a Remix application shell.
How it connects
Connects CSS, CSS-in-JS, CSS Modules, styled-components, Tailwind CSS, React, and Remix navigation.

Also explained in

Compare how 7 books explain style →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.