Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

vanilla-extract

> 编程语言
Open source

Zero-runtime Stylesheets-in-TypeScript

10.4K stars0 likes1 views
WebsiteGitHub

About

Zero-runtime Stylesheets-in-TypeScript

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.

typescript
// 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.

typescript
// 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

  • Nathan Nam Tran for creating css-in-js-loader, which served as the initial starting point for treat, the precursor to this library.
  • Stitches for getting us excited about CSS-Variables-in-JS.
  • SEEK for giving us the space to do interesting work.

License

MIT.

Issues· 74 open

View all issuesOpen on GitHub
  • #1242

    Libraries shipping `vanilla.js` files break the build when app uses a vanilla-extract plugin as well.

    good first issuepriority-lowrollupUpdated Sep 16, 2026
  • #1786

    Turbopack: expose `unstable_splitCssPerRule` or default it off in dev (one module per CSS rule makes `next dev` memory-bound)

    Updated Sep 8, 2026
  • #1574

    'Invalid exports' in vite-plugin-vanilla-extract when loading external library containing style files with file extensions `.css.ts`

    pending triageUpdated Jul 28, 2026
  • #1774

    Feature: allow a custom module file filter (support a bare `css.ts` convention)

    Updated Jul 23, 2026
  • #1563

    Support `deno.json` and `package.json` without a `name` field

    pending triageUpdated Jul 22, 2026
  • #1641

    Plugin Hook Filters for Vite plugin

    viteUpdated Jul 17, 2026
  • #1746

    Duplicated hash on build

    cssneeds reproductionUpdated Jul 13, 2026
  • #991

    Cannot consume exported theme vars from a library that is built with rollup-plugin

    rolluphas-workaroundUpdated Apr 12, 2026
  • #1279

    Support @page (print media styles in general)

    enhancementgood first issuehelp wantedUpdated Jan 19, 2026
  • #1664

    Vanilla Extract + Bun Runtime Incompatibility

    pending triageUpdated Dec 5, 2025

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言