@import statements, url() references, modern syntax lowering, vendor prefixing, and CSS Modules. It is a direct Rust→Zig port of LightningCSS, with a bundling approach inspired by esbuild.
Importing CSS
Import CSS files from JavaScript or TypeScript:app.tsx
.css file in outdir. The @import statements and url() references in your CSS are processed and rebased automatically.
CSS can also be imported from HTML files (via <link rel="stylesheet">), which is the most common pattern when using the fullstack dev server.
Default browser targets
Bun’s CSS bundler targets the following browsers by default:- Chrome 87+
- Firefox 78+
- Safari 14+
- Edge 88+
Syntax lowering
Nesting
CSS nesting is automatically flattened for browser compatibility:Custom properties (CSS variables)
CSS variables work as-is — no special configuration needed. Bun’s bundler does not transform them, since they are widely supported and their runtime behavior cannot be replicated at build time.Modern color functions
Bun evaluatescolor-mix(), relative color syntax, LAB/LCH/OKLAB/OKLCH, and HWB colors at build time when all values are constants, and generates browser-compatible fallbacks.
light-dark() function
The light-dark() function is automatically lowered to a @media (prefers-color-scheme) equivalent:
Media query ranges
Range syntax in media queries is converted tomin-width/max-width equivalents:
Logical properties
Logical CSS properties are compiled to their physical equivalents with directional fallbacks:Math functions
CSS math functions likeround(), mod(), sin(), cos(), pow(), and sqrt() are evaluated at build time when all operands are constants:
Modern shorthand properties
CSS shorthands likeplace-items, place-content, overflow: hidden auto, and display: inline flex are expanded to longhands for older browsers:
system-ui font
system-ui is expanded to a comprehensive cross-platform font stack:
CSS Modules
CSS Modules scope class names to the file to prevent collisions. Create a file with the.module.css extension:
styles.module.css
app.tsx
styles object maps original class names to scoped unique identifiers:
Composition
CSS Modules supportcomposes to reuse styles across classes:
styles.module.css
button.module.css
Composition rules: the
composes property must come before any regular CSS properties, and can only be used on simple class selectors.PostCSS not required
Bun’s CSS bundler handles the features most commonly added via PostCSS plugins:| Feature | PostCSS plugin | Bun |
|---|---|---|
| Vendor prefixes | autoprefixer | Built-in |
| CSS nesting | postcss-nesting | Built-in |
| Modern colors | postcss-color-* | Built-in |
| Media query ranges | postcss-media-minmax | Built-in |
| Logical properties | postcss-logical | Built-in |
| CSS Modules | postcss-modules | Built-in |
PostCSS is not run by Bun’s bundler. If you rely on PostCSS plugins not covered by Bun’s built-in transforms, you can add a plugin via the bundler plugin API or use TailwindCSS’s
bun-plugin-tailwind.TailwindCSS
Use TailwindCSS with the official Bun plugin:bunfig.toml
index.html
styles.css