Syntax - Tasty Web Development Treats
Syntax - Tasty Web Development Treats

807: CSS Components: Tailwind, Panda, Scoped, Modules, Classes, Variables, CSS-in-JS and Sprinkles!

In this episode of Syntax, Wes and Scott talk about CSS components, including class-based components, CSS modules, scoped CSS, utility CSS, and CSS-in-JS strategies. They share their thoughts, what differentiates these approaches, and why you may (or may not) want to use them. Show Notes 00:00 - Wel

Featured Speakers

Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers HostScott Tolensky Guest

Topics Discussed

Episode Summary

Executive Summary: The episode surveys major CSS authoring approaches for component-based UIs, centering on scoping, reuse, consistency, composability, and dead code elimination. Scott and Wes compare class-based CSS, BEM, CSS Modules, scoped CSS, CSS-in-JS, utility CSS, utility sprinkles, and CSS variables/design tokens, emphasizing trade-offs between flexibility, maintainability, runtime cost, and developer experience.

Main Topics: What makes good component CSS: The hosts define the core requirements of a solid CSS component system: scope control, reuse, predefined style APIs, composability, and bundling only used styles. Class-based CSS and BEM: Traditional class-based styling and BEM are presented as earlier, still-useful ways to structure reusable UI pieces, especially before modern component frameworks. CSS Modules: CSS Modules are explained as file-scoped styles imported into components, offering uniqueness and dead code elimination, though Wes expresses strong skepticism about the approach. Scoped CSS and @scope: Svelte/Vue-style scoped CSS and the emerging CSS @scope rule are discussed as preferred approaches for local styling with better control over inheritance and child styling. CSS-in-JS and build-time styling: The conversation contrasts runtime CSS-in-JS (styled-components, emotion) with newer build-time systems like Panda and StyleX that rely more on CSS variables and compile-time generation. Utility CSS and utility sprinkles: Tailwind-style utility CSS is discussed as a powerful system for fast styling and design consistency, while utility sprinkles are framed as a more customizable, system-driven variant. CSS variables and design tokens: The episode closes by framing CSS variables as the backbone of design systems, enabling tokens, defaults, component arguments, and reusable style constraints.

Key Arguments: A good component CSS system must support scoping at multiple levels so styles can be localized without leaking globally. Reusable components reduce inconsistency and make it easier to maintain a coherent visual system across a large app. Predefined style APIs are valuable because unconstrained one-off values lead to visual drift and expensive maintenance. Composability matters because UI pieces are often nested; styles should adapt when cards, avatars, tables, and child elements combine. Dead code elimination is a major advantage of component-scoped styling because unused styles should not inflate bundles. Scoped CSS is favored because it keeps styles close to the component while still allowing targeted global exceptions when truly needed. CSS Modules provide true scoping and bundling benefits, but the hosts criticize them as heavy-handed and less ergonomic than alternatives. Runtime CSS-in-JS solved scoping early on, but build-time systems are now preferred because many dynamic style needs can be handled with CSS variables. Utility CSS is powerful because it creates a consistent styling language, but it can become verbose and requires learning a DSL on top of CSS. Utility sprinkles are framed as a middle ground: keep utilities as a system while allowing project-specific meaning and reusable abstractions. CSS variables act like component props for styling and are central to enforcing design tokens and consistent values like colors and font sizes.

Data Points: Browser support for @scope: 82% - Wes notes the CSS @scope rule is at 82% browser support, including Firefox behind a flag. Browser support mentioned for Safari: 8–9 months - Wes says @scope has been in Safari for roughly eight or nine months. Nesting guideline: 3 levels - The hosts reference the soft rule of not nesting CSS deeper than three levels. Suggested arbitrary spacing example: 25px - Scott contrasts Tailwind-like tokenized spacing with simply using a value like 25px in custom CSS. Text utility examples: text-xs, text-base, text-md, text-lg, text-xl, 2xl - Scott describes utility classes added to the Syntax site for typography sizing.

Pivotal Quotes: "being able to scope things if I need to... from a very wide range to a very narrow range" — Scott Tolensky: Scott identifies scoping as the most essential requirement for component-based CSS. "I don't get it. I mean, I get it, but I don't get why you would like this." — Wes Bos: Wes reacts skeptically to CSS Modules, arguing they are unnecessarily heavy-handed. "I just want to be able to style the children with this class name." — Wes Bos: Wes explains why CSS @scope and donut scoping are appealing for parent-to-child styling.

Implications: The future of CSS authoring likely favors scoped, token-driven, build-time systems that reduce runtime cost and improve consistency. Teams will increasingly mix approaches rather than commit to one universal styling method.

🔓 Sign Up for Unlimited Episode Search

About Syntax - Tasty Web Development Treats

View all episodes from Syntax - Tasty Web Development Treats