skip to content

Stylesheet Tooling

Rival ways to write CSS beyond the language: compile it from Sass, transform it with PostCSS, scope it per file, author it in JavaScript or compose utilities. Interviewers ask which fits a team.

on this pageshow

explore

questions

page 1 of 2

In CSS-in-JS, what is the difference between a runtime library that injects styles and a zero-runtime library that extracts them at build time?

level: juniorimportance: must knowfreq 30%

answer

  1. when does the CSS come to exist
  2. an engine running in the page
  3. a static stylesheet from the bundler
  4. values only known while the page runs
  5. a custom property or a fixed variant

basics

~20 s

A runtime library generates CSS in the browser as components render and injects it into style elements; a zero-runtime library evaluates the styles during the build and ships a static stylesheet plus class names, with no styling engine in the page.

solid answer

~50 s

Both let you write styles in JavaScript or TypeScript next to the component; they differ in *when* the CSS comes into existence. A **runtime** library (styled-components or Emotion, for example) ships its engine to the browser: as a component renders, it turns the style template or object, with the current props and theme, into CSS, hashes it into a class name and inserts the rule into a `<style>` element if that class is new. A **zero-runtime** library (vanilla-extract, for example) runs your style files during the build and emits ordinary `.css` files plus the generated class names, so the browser only downloads a stylesheet. The price of extraction is that a value known only while the page runs cannot be precompiled: it becomes a CSS custom property set at runtime, or one of a fixed set of variants written in advance.

go deeper

for a junior

Recall the one axis that matters: when the CSS is produced. Runtime libraries generate and inject it in the page; zero-runtime libraries produce a static stylesheet during the build.

for a middle

Explain what each family does with a prop-driven value: a runtime library interpolates it into a new rule, while extraction needs a custom property set at runtime or a predefined variant.

for a senior

Show where the difference bites in production: runtime injection adds work while rendering, needs server-side style collection, and meets content security policies, while extraction removes all three.

for a principal

Frame the choice as flexibility against a static stylesheet, and decide which dynamic values a codebase truly needs before committing a design system to either family.

## What "CSS-in-JS" covers **CSS-in-JS** is any approach where you author styles in JavaScript or TypeScript modules, usually next to the component that uses them, instead of in separate `.css` files. Under that single name sit two families that behave very differently once the code ships: - **Runtime injection** — a library in the page generates CSS while components render and writes it into the document. - **Build-time extraction** (often called *zero-runtime*) — a compiler or bundler plugin evaluates the style definitions during the build and writes static CSS files. React's own documentation lists three common approaches: static extraction to CSS files with a compiler, inline styles, and runtime injection of `<style>` tags. It recommends a combination of the first two and advises against runtime injection. ## Runtime injection Take a concert-ticketing site whose event cards are written with a runtime library such as styled-components or Emotion. When an event card renders, the library: 1. evaluates the style template or object, including any interpolation that reads props or the theme; 2. serialises the result into a CSS string; 3. hashes that string into a class name, so identical styles share one class; 4. inserts the rule into a `<style>` element if that class has not been inserted before; 5. hands the class name to the element. Everything above happens in the browser (and again on the server if the page is server-rendered). The library's code is part of the JavaScript bundle, and the stylesheet is built up rule by rule as new styles appear. ## Build-time extraction A zero-runtime library moves the same work to the build. In vanilla-extract, for example, styles live in `.css.ts` files; the bundler integration evaluates them during the build, emits static CSS, and the module's exports become plain class-name strings. Its README describes the result as "Zero-runtime Stylesheets-in-TypeScript", with all styles generated at build time. The browser receives a normal stylesheet, which it downloads, parses and caches like any other. ## Side by side | Question | Runtime injection | Build-time extraction | |---|---|---| | When is the CSS produced? | While components render | During the build | | What reaches the browser? | A styling engine plus rules created on the fly | A `.css` file plus class-name strings | | Can a style use a prop's value directly? | Yes, interpolated on render | Only through a custom property or a known variant | | Extra work during rendering | Serialising, hashing, inserting new rules | None for styling | | What server rendering needs | Collecting the rules each render produced | Nothing beyond linking the stylesheet | Both families usually generate **scoped class names**, so the protection against two components' `.title` rules colliding is the same. What differs is where CSS generation happens: in every visitor's browser on every page load, or once on the build machine. ## The value you cannot extract Extraction has one firm limit: the compiler can only write down what it can compute **before the page runs**. A promoter's brand colour fetched from an API, a seat's live demand level or a dragged element's position does not exist at build time. Such a value takes one of two forms: - a **CSS custom property**: the static rule reads `var(--promoter-accent)`, and the component sets the property's value on the element at runtime; - a **known variant**: when the value comes from a small fixed set (sold, held, available), every variant is written as its own rule in advance and the component picks one. This is also why "zero-runtime" does not always mean zero JavaScript. vanilla-extract's documentation, for instance, offers a small `@vanilla-extract/dynamic` package that it describes as a tiny runtime for assigning scoped variables inline, and its Sprinkles package keeps a small runtime that only looks up pre-generated class names. What disappears is *generating and injecting CSS* in the page, not every line of styling code. ## Choosing between them - A runtime library is flexible: any expression can drive any declaration, and nothing is configured in the build. - Extraction trades that flexibility for a static stylesheet: no engine in the bundle, no rule insertion while rendering, and nothing to collect on the server. - Teams that start with runtime libraries often feel the difference first on server rendering, server components and strict content security policies, each of which is a separate question. - A common middle path is to keep a runtime library on existing screens while new shared components are written for extraction, with dynamic values already expressed as custom properties so either family can consume them.

  • Does "zero-runtime" mean no styling JavaScript reaches the browser at all?
    Not quite. The stylesheet is static, but components still import the generated class names as strings, and some extraction libraries ship a small helper: vanilla-extract's docs describe `@vanilla-extract/dynamic` as a tiny runtime that assigns scoped variables inline. What disappears is generating and injecting CSS while the page runs.
  • Where do inline styles fit next to these two families?
    React's documentation lists three approaches: static extraction to CSS files, inline styles, and runtime injection of `<style>` tags. It recommends combining the first two, static CSS for static styles and inline styles for dynamic values, and advises against runtime injection because it makes the browser recalculate styles more often.

Runtime injection is a print shop that typesets each flyer when a customer asks for it; extraction prints the whole run before the shop opens, so anything only known at the counter must be left as a blank to fill in by hand.

  • CSS-in-JS always means styles are injected into the page at runtime
  • A zero-runtime library can extract values computed from props at render time
  • Runtime and build-time libraries emit the same output, only the syntax differs
  • Zero-runtime means no styling-related JavaScript at all ever reaches the browser
  • Build-time extraction still needs a style collector during server rendering
open as a page

In a CSS Modules setup, what does `import styles from './BookCard.module.css'` give a component, and why do two files' `.title` classes stop clashing?

level: juniorimportance: must knowfreq 30%

basics

~20 s

An object mapping each class name written in the file to a generated name unique to that file. The build rewrites the CSS to the generated names, so two files' .title become two different classes.

open as a page

What does PostCSS do with a stylesheet, and why does the output stay unchanged until you add plugins such as Autoprefixer?

level: juniorimportance: must knowfreq 22%

basics

~20 s

PostCSS parses CSS into a tree of nodes (Root, AtRule, Rule, Declaration, Comment), lets plugins read and rewrite that tree, then prints it back as CSS. PostCSS itself changes nothing: prefixes, lowering and minification all come from plugins.

open as a page

What is Sass, how do its SCSS and indented syntaxes differ, and what does the browser actually receive from a .scss file?

level: juniorimportance: must knowfreq 28%

basics

~20 s

Sass is a stylesheet language compiled to plain CSS at build time by Dart Sass. SCSS (.scss) is nearly a superset of CSS; the indented syntax (.sass) swaps braces and semicolons for indentation. The browser only receives the compiled CSS.

open as a page

In Tailwind CSS v4, what is a theme variable, and how does declaring one in `@theme` differ from declaring a plain `:root` variable?

level: juniorimportance: must knowfreq 26%

basics

~20 s

A theme variable is a custom property declared inside @theme in Tailwind CSS v4; its namespace, such as --color-* or --font-*, makes Tailwind generate matching utilities. A variable on :root is plain CSS and generates no utility class.

open as a page

In Tailwind CSS, why does a badge class built as `bg-${status}-600` from an API value render with no background, and how do you fix it?

level: juniorimportance: must knowfreq 30%

basics

~20 s

Tailwind scans source files as plain text and generates CSS only for complete class names it finds. The fragment bg-${status}-600 never appears whole, so no rule is generated; map each status to a full class string such as bg-emerald-600.

open as a page

In Tailwind CSS v4, what does the `@apply` directive do to your CSS rule, and when does reaching for it backfire?

level: juniorimportance: must knowfreq 22%

basics

~20 s

In Tailwind CSS v4, @apply copies the declarations of existing utilities into your own rule at build time. It backfires when it rebuilds semantic classes, hides states from the markup, or lands outside a layer where utilities can no longer override it.

open as a page

In Tailwind CSS, what does a responsive variant such as `md:` mean, and how do you limit a utility to a range of widths?

level: juniorimportance: must knowfreq 30%

basics

~20 s

A breakpoint variant such as md: applies its utility from that breakpoint upward through a min-width media query, so unprefixed classes are the phone styles. Stacking md: with a max-* variant, as in md:max-xl:, limits it to a range.

open as a page

When a component styled with a runtime CSS-in-JS library renders, what work does the library do, and what does it cost against a static stylesheet?

level: middleimportance: must knowfreq 20%

basics

~20 s

On render it evaluates the style template with current props and theme, serialises it to CSS, hashes it into a class name and inserts the rule once per new hash, costing library bytes, render-time CPU and extra style recalculation.

open as a page

How does Autoprefixer decide which vendor prefixes to add or remove, and where does it read its target browsers from?

level: middleimportance: must knowfreq 16%

basics

~20 s

Autoprefixer checks each unprefixed property, value and selector against Can I Use data for the browsers a Browserslist query selects, from .browserslistrc or package.json, else defaults. It adds only the prefixes those browsers need and removes outdated ones.

open as a page

With Dart Sass's module system, how does @use differ from the deprecated @import in how members are named, loaded and kept private?

level: middleimportance: must knowfreq 18%

basics

~20 s

@use loads a file once per compilation as a module whose members are namespaced (tokens.$navy), visible only to the loading file, and private when named with - or _. @import shared one global scope; Dart Sass 1.80.0 deprecated it.

open as a page

In Tailwind CSS v4, how do you extend, override or completely replace a default theme namespace such as the colour palette or the breakpoints?

level: middleimportance: must knowfreq 19%

basics

~20 s

In Tailwind CSS v4, add a variable to extend a namespace, redeclare a default to override it, set one to initial to remove it, and write --color-: initial (or --: initial for everything) before your values to replace it.

open as a page

In Tailwind CSS v4, which cascade layers does `@import "tailwindcss"` set up, and where should your own base styles and component classes go?

level: middleimportance: must knowfreq 16%

basics

~20 s

Tailwind CSS v4 declares four native cascade layers in the order theme, base, components, utilities. Element defaults go in @layer base, on top of Preflight; reusable classes such as .btn go in @layer components, so a utility on the same element still overrides them.

open as a page

In Tailwind CSS, how do `group` and `peer` let you style an element from a parent's hover state or a sibling checkbox's checked state?

level: middleimportance: must knowfreq 22%

basics

~20 s

Put the group class on an ancestor and use group-hover: on its descendants; put the peer class on an earlier sibling and use peer-checked: on elements after it. Name them, as group/card or peer/notify, when markers nest or repeat.

open as a page

Why does a runtime CSS-in-JS seat map inject thousands of rules when each seat's colour comes from props, and how do you fix it?

level: middleimportance: should knowfreq 13%

basics

~20 s

Each distinct interpolated colour is a distinct CSS string, so the library hashes and inserts a new class per value. Keep one static rule reading a custom property, set the colour inline per seat, and make small fixed sets variants.

open as a page

In CSS Modules, how does `composes` let a Button module's `.primary` reuse `.base`, and what rules limit where and how `composes` may be written?

level: middleimportance: should knowfreq 14%

basics

~20 s

composes copies no declarations: it makes the class map's value for .primary list both generated names, so the element carries both classes. It works only on a single local class selector, before other declarations, and cross-file order is undefined.

open as a page

In a CSS Modules file, how do `:global` and `:local` work, and how do you style a component when a dialog adds `is-modal-open` to body?

level: middleimportance: should knowfreq 12%

basics

~20 s

A class set by code outside the module keeps its plain name, so it must be marked global: :global(.is-modal-open) .catalogue { … } keeps that class unhashed while .catalogue stays local. :local switches back to local scope.

open as a page

With CSS Modules, a file declares `.book-card` but `className={styles.bookCard}` leaves the element unstyled without any error — why, and what fixes it?

level: middleimportance: should knowfreq 18%

basics

~10 s

The class map is a plain object whose keys are the names as written, so styles.bookCard is undefined unless the toolchain converts keys to camelCase. Use styles['book-card'], rename the class, or enable key conversion.

open as a page

In a postcss.config.js listing postcss-import, postcss-preset-env and cssnano, why does plugin order matter, and which order do you use?

level: middleimportance: should knowfreq 12%

basics

~20 s

Plugins run in the order listed, each on the tree the previous ones left. Put postcss-import first so later plugins see one tree, non-standard plugins before postcss-preset-env (which already runs Autoprefixer), and cssnano last so it compresses everything the others emitted.

open as a page

In postcss-preset-env, what do the stage and features options control, and why does it leave some modern CSS untransformed?

level: middleimportance: should knowfreq 8%

basics

~20 s

postcss-preset-env picks features by spec maturity (stage, 0 to 4 or false, default 2) and per-feature overrides (features), then lowers a feature only if a Browserslist target lacks support. Syntax every target supports passes through untouched.

open as a page

In Sass, when do you write a @mixin with @content rather than a @function, and what can each one produce?

level: middleimportance: should knowfreq 13%

basics

~20 s

A @function computes a value and hands it back with @return; it cannot emit declarations or rules. A @mixin, pulled in with @include, emits styles, and @content lets the caller pass a block the mixin wraps, such as a media query.

open as a page

In Tailwind CSS v4, how do you apply a one-off value the theme lacks: a hex colour, a CSS variable, or an unsupported property?

level: middleimportance: should knowfreq 18%

basics

~10 s

Tailwind CSS v4 accepts arbitrary values in square brackets, such as bg-[#316ff6] or top-[117px]; a CSS variable uses parentheses, bg-(--promo); a property with no utility is written as [mask-type:luminance]. Spaces become underscores.

open as a page

In Tailwind CSS v4, `dark:` utilities follow the OS setting although `<html>` has `class="dark"`; why, and how do you make them follow the class?

level: middleimportance: should knowfreq 15%

basics

~20 s

Tailwind CSS v4's dark variant uses the prefers-color-scheme media query by default, so a dark class does nothing. Override it in CSS with @custom-variant dark (&:where(.dark, .dark *)); a data attribute works the same way.

open as a page

In Tailwind CSS v4, why does a PostCSS config shrink to just @tailwindcss/postcss, and when would you pick another integration instead?

level: middleimportance: should knowfreq 11%

basics

~10 s

Tailwind CSS v4 bundles @import files, adds vendor prefixes and flattens nesting itself, so postcss-import and Autoprefixer are redundant. Use @tailwindcss/vite with Vite, @tailwindcss/webpack (since 4.2) with webpack, and @tailwindcss/cli without a bundler.

open as a page

In Tailwind CSS v4, why do components from a shared UI package installed in node_modules render unstyled, and what fixes it?

level: middleimportance: should knowfreq 14%

basics

~20 s

Tailwind CSS v4's automatic source detection skips node_modules, so classes used only inside an installed package are never generated. Register it with @source "../node_modules/@clinic/ui" in the stylesheet that imports Tailwind; the path is relative to that stylesheet.

open as a page

In Tailwind CSS v4, why does `@apply` fail inside a Vue or Svelte `<style>` block or a CSS Module, and what does `@reference` fix?

level: middleimportance: should knowfreq 12%

basics

~20 s

In Tailwind CSS v4, each component style block and CSS Module is compiled separately, without your main stylesheet's theme, custom utilities or custom variants. @reference loads those definitions for lookup without emitting any CSS; plain var(--color-…) references sidestep it for single values.

open as a page

In Tailwind CSS v4, how do `@container`, `@sm:` and named containers like `@container/main` make a sidebar reflow by its own width instead of the viewport's?

level: middleimportance: should knowfreq 13%

basics

~20 s

In Tailwind CSS v4, the @container class makes an element an inline-size query container, and @sm: on its descendants compiles to @container (width >= 24rem). Naming it @container/main and using @sm/main: targets that container rather than the nearest one.

open as a page

In Tailwind CSS v4, how do the `data-*` and `aria-*` variants style a save button by its `data-state` and an accordion by `aria-expanded`?

level: middleimportance: should knowfreq 14%

basics

~10 s

In Tailwind CSS v4, data-[state=saved]: compiles to a [data-state="saved"] attribute selector and a bare data-saving: checks the attribute is present; aria-expanded: compiles to [aria-expanded="true"]. The script sets the attribute and the styles follow.

open as a page

In a React Server Components app, why have runtime CSS-in-JS libraries classically needed to run as client components, and is that still universally true?

level: seniorimportance: should knowfreq 7%

basics

~20 s

The classic design reads the theme from context, uses hooks and keeps a stylesheet in the browser, none of which a server component has. Not universally now: styled-components, since 6.3.0, renders in server components, losing context-based theming there.

open as a page

When pages styled with a runtime CSS-in-JS library are server-rendered with streaming, how must the library collect its styles, and why does one stylesheet in the head no longer work?

level: seniorimportance: should knowfreq 9%

basics

~20 s

On the server the library must collect the rules each render produces and write them into the HTML, or the first paint is unstyled. Streaming sends the head early, so rules must be flushed with each chunk, ahead of the markup using them.

open as a page

showing 1–30 of 46