liveBook · Manning

CSS-in-JS

As explained in CSS in Depth, Second Edition

CSS-in-JS is a styling technique that uses JavaScript to define styles and generate or manage CSS class names.

CSS-in-JS uses JavaScript to manufacture guaranteed-unique class names instead of relying on CSS class-naming conventions. It addresses naming conflicts in large, modular projects. section 9.2.2

Evaluate the technique against these practical constraints:

  • Use it mainly in applications rendered completely by a JavaScript framework, especially single-page applications. section 9.2.2
  • Expect tradeoffs: adopting CSS-in-JS can lock a project into a particular JavaScript toolset or framework. section 9.2.2
  • Recognize established implementations including Styled Components, vanilla-extract, and CSS Modules. section 9.2.2

How CSS in Depth, Second Edition covers it

How deep it goes
Defines automatic class-name generation and explains tradeoffs, but stops short of implementation details or code.
Examples
Names Styled Components, vanilla-extract, and CSS Modules as representative implementations.
What it assumes
Assumes JavaScript-framework rendering and awareness of modular CSS naming conventions.
What you can do after
Evaluate whether automated class-name generation suits a framework-rendered application and its toolset constraints.
How it connects
Connects CSS-in-JS with modular CSS, JavaScript frameworks, React, Webpack, and single-page applications.

Also explained in

Compare how 2 books explain CSS-in-JS →

Related concepts

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