- Transpile modern/future features for compatibility with all browsers (including vendor prefixes)
- Minification
- CSS Modules
- Tailwind (via native bundler plugin)
Transpilation
Bun’s CSS bundler lets you use modern/future CSS features without worrying about browser compatibility—thanks to transpilation and vendor prefixing enabled by default. Bun’s CSS parser and bundler is a direct port of LightningCSS from Rust to Zig, with bundling methodology inspired by esbuild. The transpiler converts modern CSS syntax into backwards-compatible equivalents for a range of browsers.Special thanks to the authors of LightningCSS and esbuild for their excellent work.
Browser compatibility
By default, Bun’s CSS bundler targets browsers that support:- ES2020
- Edge 88+
- Firefox 78+
- Chrome 87+
- Safari 14+
Syntax downleveling
Nesting
The CSS nesting specification allows you to write more concise and intuitive stylesheets by nesting selectors within each other. Instead of repeating parent selectors throughout your CSS file, you can write child styles directly inside parent blocks.styles.css
styles.css
styles.css
styles.css
Color mixing
Thecolor-mix() function lets you easily blend two colors in a specified proportion within a chosen color space. This powerful feature lets you create color variations without manually calculating result values.
styles.css
styles.css
Relative colors
CSS now allows you to modify individual components of colors using relative color syntax. This powerful feature lets you create color variants by adjusting lightness, saturation, or individual channels without recalculating the entire color.styles.css
LAB colors
Modern CSS supports perceptually uniform color spaces like LAB, LCH, OKLAB, and OKLCH, which offer significant advantages over traditional RGB. These color spaces can represent colors beyond the standard RGB gamut, bringing more vibrant and visually consistent designs.styles.css
styles.css
color function
Thecolor() function provides a standardized way to specify colors using various predefined color spaces, expanding your design options beyond traditional RGB space. This enables access to wider color gamuts, creating more vibrant designs.
styles.css
styles.css
CSS Modules
CSS Modules provide local scoping for CSS by default, preventing naming conflicts and making styles more maintainable.Button.module.css
Button.tsx
- Generate unique class names
- Export a mapping object
- Bundle the transformed CSS
Output
Importing CSS
CSS can be imported in JavaScript/TypeScript files:app.ts
@import statements
CSS@import statements are resolved and bundled:
main.css
url() references
Asset references inurl() are resolved and copied to the output directory:
styles.css
Output
Minification
Enable CSS minification:Vendor prefixes
Vendor prefixes are automatically added based on the browser targets:Input
Output
Custom properties
CSS custom properties (variables) are preserved:Media queries
Media queries are preserved and can be nested:CSS chunking
When code splitting is enabled, CSS is also split into chunks:Tailwind CSS
Bun provides a native bundler plugin for Tailwind CSS. See the Tailwind documentation for setup instructions.Performance
Bun’s CSS bundler is extremely fast:- Written in Zig for maximum performance
- Parallel processing of CSS files
- Efficient memory usage
- Fast source map generation
Limitations
- No PostCSS support yet (use plugins as an alternative)
- No SASS/SCSS support (but nesting is supported natively)
- CSS layers are preserved but not optimized