WhoBuilt

How I'm Writing CSS in 2024

Jan 8, 2024· 13 min· 61K views·Watch on YouTube

Lee Robinson of leerob discusses CSS features and styling tools, using browser examples and recommendations for modern web development.

What good CSS tooling should deliver

For users, styles should load quickly, stay small, cache until they change, and avoid shifting page content. Fonts should also load quickly with minimal layout shift. Developer tools can help by removing unused styles, minifying and compressing files, bundling requests, using hashed filenames for caching, and preventing naming collisions.

New CSS features and when to build

Robinson demonstrates native nesting, custom properties, and container queries, including a container query that changes a blog post's padding and font size below 500 pixels. These features work across browsers without extra tooling, but a build step can still help support older browsers or newer syntax. He mentions progressive enhancement with @supports and syntax lowering with Lightning CSS.

CSS Modules and Tailwind

CSS Modules offer a lightweight, widely supported way to scope styles, and Next.js bundles and minifies module files; its App Router also supports streaming. Tailwind generates CSS for the utility classes a project actually uses, allowing a small, compressed stylesheet with a hashed filename and immutable caching. Robinson likes Tailwind's stable API and colocated styles, while noting that its approach is not for everyone.

Zero-runtime CSS-in-JS and streaming

Robinson describes runtime JavaScript and compatibility with streaming and Server Components as challenges for some CSS-in-JS libraries. He presents StyleX as a zero-runtime option built at Meta and used across products including WhatsApp, Facebook, Instagram, and Threads. Its separate styling declarations and design tokens have trade-offs compared with Tailwind's utility classes, so he suggests trying the approach to see whether it fits.

Takeaways

  • Set CSS goals around fast loading, small files, reliable caching, and minimal layout shift.
  • Use native nesting, custom properties, and container queries where target browser support allows.
  • Keep a build step when you need to support older browsers or lower newer CSS syntax.
  • Choose CSS Modules or Tailwind when you want broadly supported, compiled styles; Tailwind can emit only the utilities a project uses.
  • Evaluate zero-runtime styling options such as StyleX against your needs for streaming, Server Components, tokens, and code organization.

Mentioned in this talk

Search inside this talk

What was claimed 11

  • feature
    Next.js: Supports streaming server rendering and streaming CSS
    “the latest features in React and Next.js support streaming server rendering and streaming CSS”
    YouTube
    Unverified1 source· Talk
  • feature
    React: Supports streaming server rendering and streaming CSS
    “the latest features in React and Next.js support streaming server rendering and streaming CSS”
    YouTube
    Unverified1 source· Talk
  • feature
    CSS Modules: Supported in basically every bundler and framework
    “CSS Modules are supported in basically every single bundler and framework.”
    YouTube
    Unverified1 source· Talk
  • feature
    Next.js: App Router supports streaming CSS Modules
    “In the context of the App Router, this also supports streaming.”
    YouTube
    Unverified1 source· Talk
  • feature
    Tailwind CSS: Generates only the classes used during compilation
    “it generates the classes used on demand during the compilation process.”
    YouTube
    Unverified1 source· Talk
  • uses
    “used for WhatsApp, Facebook, Instagram, Threads”
    YouTube
    Unverified1 source· Talk
  • uses
    “used for WhatsApp, Facebook, Instagram, Threads”
    YouTube
    Unverified1 source· Talk
  • uses
    “used for WhatsApp, Facebook, Instagram, Threads”
    YouTube
    Unverified1 source· Talk
Show all 11 facts

Related talks