Skip to main content
Bun has a built-in CSS bundler that handles @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
During bundling, all imported CSS is combined into a single .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+
Modern CSS that isn’t supported in these targets is automatically lowered to compatible equivalents.

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 evaluates color-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 to min-width/max-width equivalents:

Logical properties

Logical CSS properties are compiled to their physical equivalents with directional fallbacks:

Math functions

CSS math functions like round(), mod(), sin(), cos(), pow(), and sqrt() are evaluated at build time when all operands are constants:

Modern shorthand properties

CSS shorthands like place-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
Import it in TypeScript/TSX:
app.tsx
The imported styles object maps original class names to scoped unique identifiers:

Composition

CSS Modules support composes to reuse styles across classes:
styles.module.css
You can also compose from a separate CSS module file:
button.module.css
Composition rules: the composes property must come before any regular CSS properties, and can only be used on simple class selectors.
When composing from separate files, avoid conflicting properties between the composed classes — the CSS Modules spec leaves the order of conflicting properties undefined.

PostCSS not required

Bun’s CSS bundler handles the features most commonly added via PostCSS plugins:
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
Or import it in CSS:
styles.css