vanilla-extract README

The project's README from github.com/vanilla-extract-css/vanilla-extract. As one markdown file: README.md.

🧁 vanilla-extract

Zero-runtime Stylesheets-in-TypeScript.

Write your styles in TypeScript (or JavaScript) with locally scoped class names and CSS Variables, then generate static CSS files at build time.

Basically, it’s “CSS Modules-in-TypeScript” but with scoped CSS Variables + heaps more.

🔥   All styles generated at build time — just like Sass, Less, etc.

✨   Minimal abstraction over standard CSS.

🦄   Works with any front-end framework — or even without one.

🌳   Locally scoped class names — just like CSS Modules.

🚀   Locally scoped CSS Variables, @keyframes and @font-face rules.

🎨   High-level theme system with support for simultaneous themes. No globals!

🛠   Utils for generating variable-based calc expressions.

💪   Type-safe styles via CSSType.

🏃‍♂️   Optional runtime version for development and testing.

🙈   Optional API for dynamic runtime theming.


🌐 Check out the documentation site for setup guides, examples and API docs.


🖥   Try it out for yourself in CodeSandbox.


Write your styles in .css.ts files.

// styles.css.ts

import { createTheme, style } from '@vanilla-extract/css';

export const [themeClass, vars] = createTheme({
  color: {
    brand: 'blue'
  },
  font: {
    body: 'arial'
  }
});

export const exampleStyle = style({
  backgroundColor: vars.color.brand,
  fontFamily: vars.font.body,
  color: 'white',
  padding: 10
});

💡 Once you've configured your build tooling, these .css.ts files will be evaluated at build time. None of the code in these files will be included in your final bundle. Think of it as using TypeScript as your preprocessor instead of Sass, Less, etc.

Then consume them in your markup.

// app.ts

import { themeClass, exampleStyle } from './styles.css.ts';

document.write(`
  <section class="${themeClass}">
    <h1 class="${exampleStyle}">Hello world!</h1>
  </section>
`);

Want to work at a higher level while maximising style re-use? Check out 🍨 Sprinkles, our official zero-runtime atomic CSS framework, built on top of vanilla-extract.


Contributing

Thanks

License

MIT.

vanilla-extract (vanilla-extract-css/vanilla-extract)

webpack
Searching Database…

What is this?vanilla-extract lets you write CSS styles in TypeScript (or JavaScript) with locally scoped class names and CSS variables, then compiles everything into static CSS files at build time with zero runtime cost.
Is this a CSS framework or more like a preprocessor?It's a build-time compiler/library, not a framework — think of it as using TypeScript as your preprocessor instead of Sass or Less. It works with any front-end framework, or no framework at all.
How do I start writing styles with it?You write your styles in .css.ts files and import them into your markup like normal code; once your build tooling is configured, those files are evaluated at build time and compiled to CSS.
Do I need special bundler plugins to use it?Yes — you need to configure your build tooling (webpack, Vite, esbuild, etc.) with a vanilla-extract plugin; the documentation site covers setup guides for different bundlers.
Does any of my TypeScript styling code end up in the production bundle?No — none of the code inside .css.ts files is included in your final JS bundle; it's stripped out and only the generated static CSS ships to the browser.
What is the theme system like?vanilla-extract has a high-level theme system supporting multiple simultaneous themes with no global CSS variables, so different themes can coexist on the same page without conflicts.
What is Sprinkles?Sprinkles is the project's official zero-runtime atomic CSS framework, built on top of vanilla-extract, for teams that want a higher-level, utility-style API with maximum style reuse.
Can I use runtime styling for testing or development?Yes, there is an optional runtime version of vanilla-extract intended for development and testing scenarios, plus an optional API for dynamic runtime theming.
Are the generated class names and CSS variables scoped automatically?Yes, both class names and CSS variables (including @keyframes and @font-face rules) are locally scoped by default, similar to how CSS Modules work.
Size
10.6 MB
Stars
10.4K
Age
5y
Commits · 90 Days