vanilla-extract is a framework-agnostic CSS-in-TypeScript library that treats styling as developer tooling rather than a prescriptive CSS framework. The CSS tooling space has been stable for years — PostCSS, Sass, CSS Modules and styled-components all predate 2017 and remain widely used — with Tailwind among the few recent disruptions. vanilla-extract arrived this year and benefits from three shifts: JavaScript developers moving to TypeScript, browser support for CSS custom properties, and the rise of utility-first styling.

No runtime overhead

Conventional CSS-in-JS libraries inject styles into the document at runtime, which enables critical CSS extraction and dynamic styling. But a separate CSS file is generally more performant: JavaScript must go through more expensive parsing and compilation, while a CSS file can be cached and HTTP2 reduces the cost of the extra request. Custom properties also now cover much of what dynamic styling used to require.

Like Linaria and astroturf, vanilla-extract takes the build-time route. You author styles in TypeScript functions, but those functions are stripped out during the build and used to produce a CSS file, so the library adds nothing to your production JavaScript bundle.

Why types help

The main value proposition is type safety for styles. In a TypeScript-aware editor, typing fo surfaces matching properties such as fontFamily, fontKerning or fontWeight, making CSS properties discoverable without leaving the editor — in VS Code, with no extra tooling. Misspellings that would otherwise turn into frustrating bugs get caught, and the type definitions include syntax explanations plus a link to MDN for the property being edited.

One adjustment for developers used to plain CSS: properties use camel case, so you write backgroundColor rather than background-color.

Bundler and framework support

  • webpack
  • esbuild
  • Vite
  • Snowpack
  • NextJS
  • Gatsby

The library is completely framework-agnostic: you import class names, which are converted into strings at build time.

Authoring styles

Styles live in .css.ts files that components import. Function calls inside them become hashed, scoped class name strings during the build. The resemblance to CSS Modules is no coincidence — Mark Dalgleish, one of vanilla-extract's creators, also co-created CSS Modules.

The style() function creates an automatically scoped class: pass in the element's styles, export the return value, import it in your code, and it resolves to a scoped class name.

Scoping and composition rules

These calls are a thin abstraction over CSS, with property names and values mapping to what you already know. Some values can be numbers — padding: 30 defaults to pixels — while others must be strings, such as padding: "10px 20px 15px 15px".

A style function affects only a single HTML node, so Sass- or PostCSS-style nesting to style children is not available; children are styled separately. To vary a child based on its parent, use the selectors property. Alternatively, the Theming API can define custom properties on the parent that child nodes consume. The restriction is deliberate: it keeps large codebases maintainable, because every element's styles have exactly one declared location.

Theming with custom properties

createTheme builds variables into a TypeScript object, and variants of a theme are checked so that they reuse the same property names — forget the background property and TypeScript warns you. A regular theme and a dark mode can both be declared this way; switching between them is plain JavaScript, applying the returned class names to swap themes.

Under the hood, the objects passed to createTheme become CSS custom properties attached to the element's class, hashed to avoid conflicts. Applying the darkmode class to the parent element replaces the mainTheme custom properties with the darkMode ones, so user code only changes a class name.

Reusable variants with the Recipes API

The Recipes API builds on style and createTheme for reusability. It is installed separately:

npm install @vanilla-extract/recipes

You import recipe and pass an object with base and variants. base holds styles applied to all variants; variants describes the ways to customize the element.

// button.css.ts
import { recipe } from '@vanilla-extract/recipes';

export const buttonStyles = recipe({
  base:{
    // Styles that get applied to ALL buttons go in here
  },
  variants:{
    // Styles that we choose from go in here
  }
});
// button.css.ts
import { recipe } from '@vanilla-extract/recipes';
export const buttonStyles = recipe({
  base: {
    fontWeight: "bold",
  },
  variants: {
    color: {
      normal: {
        backgroundColor: "hsl(210deg,30%,90%)",
      },
      callToAction: {
        backgroundColor: "hsl(210deg,80%,65%)",
      },
    },
    size: {
      large: {
        padding: 30,
      },
      medium: {
        padding: 15,
      },
    },
  },
});

You then pick a variant in your markup, and TypeScript autocompletes your own variant names. Variants can be named and populated freely, which makes the API well suited to design systems: components are reusable, the ways they vary are discoverable, and pressing CMD/CTRL + Space in most editors lists the available customizations.

Utility-first styling with Sprinkles

Sprinkles is a utility-first framework built on top of vanilla-extract. The docs describe it as building your own zero-runtime, type-safe version of Tailwind or Styled System. It suits developers who dislike naming things — no more outer-wrapper followed by outer-outer-wrapper. It too is installed separately:

npm install @vanilla-extract/sprinkles

First you define building blocks: objects of colors and lengths whose keys can be anything and whose values must be valid CSS values for the properties they serve. The defineProperties function binds them to properties — pass an object with a properties property, where the keys are the CSS properties a user can set (they must be valid CSS properties) and the values are the objects you created. Finally, pass the return value of defineProperties into createSprinkles and export the result. You then style inline in components by calling sprinkles in the class attribute and selecting options per element. The JavaScript output holds a class name string per style property, each matching one rule in the output CSS.

The result constrains styling to a predefined set inside your markup and removes the chore of naming classes for every element — Tailwind-like in feel, but backed by all the infrastructure built around TypeScript. Sprinkles also supports conditions and shorthands for responsive styles via utility classes.