Skip to content

Styling

Bun's CSS bundler is the one CSS loader in a Hamur build. It inlines @import, lowers nesting, adds prefixes, minifies, and names the classes of a CSS module. Hamur puts what it lacks in front of it and never in its place: a compiler for Sass, Less and Stylus, PostCSS plugins, and aliases in @import. This page covers those, the places a stylesheet can be named, and how Tailwind v4, UnoCSS and CSS-in-JS libraries fit.

A stylesheet reaches a page in one of two ways. import "./card.css" in a module links it on the pages that render that module, so an import in the app root, which renders on every page, links it on every page (Global CSS). A <style> block of a Vue or Svelte component is part of that component. The client entry's own CSS is never linked; route, layout and app-root CSS is linked only where it renders, and a client navigation adds the target's stylesheets before the swap and removes the ones it no longer needs.

Which key does what

Each key has one reader and one meaning.

KeyHolds
cssCompilersthe options of @hamur/css: sass, less, stylus, postcss
build.pluginsBun plugins, the only key named plugins; an app plugin is a file in app/plugins/
build.inlineStylesthe size below which a first render's stylesheet is written into the document
build.assetsInlineLimitthe size below which a CSS url() file is a data: URI (4096 bytes by default)

cssCompilers never holds a file, and a Sass file that is a CSS module takes cssCompilers.sass for its language and Bun for its class names.

Global CSS

A stylesheet the app root imports is linked on every page, in a build and in hamur dev, since app/app.<ext> renders on every page. A package's stylesheet is imported by its name, as Bun resolves it.

tsx
import { Outlet } from "@hamur/adapter-react"
import "modern-normalize"
import "./assets/main.css"

export default function App() {
  return <Outlet />
}

A stylesheet an app plugin imports is global CSS too: the plugins load with the app modules, whose CSS every page links ahead of the app root's. A layer makes its stylesheet global this way, with a plugin in the layer's app/plugins/, so the layer's rules come before the app root's in the cascade.

ts
import "../theme.css"

export default () => {}

The config has no css list. A config that sets css fails when it loads: css was removed; import the stylesheet in app/app.<ext> (import "modern-normalize").

Imports and packages in CSS

@import "#app/styles/base.css" in a stylesheet resolves through the imports of package.json as a script import does, in the client, server and dev builds and in a ?inline file. url() takes a path relative to the stylesheet, since url(#x) is a fragment reference in CSS. A package specifier resolves from the importing file's directory, and a file that exists next to the stylesheet wins over a package of the same name.

css
@import "#app/styles/base.css";
@import "modern-normalize/modern-normalize.css";

.hero {
  background: url("./assets/hero.png");
}

An @import "~/styles/a.css" fails as a script's ~/ import does, with the file and the line. The webpack form @import "~pkg/x.css" fails with app/main.css: remove the ~ from "~pkg/x.css".

?inline

import css from "./card.css?inline" is the bundled, minified text of the file, with no <link>. It is the string for adoptedStyleSheets and shadow roots. For a style language the text is the compiled CSS, with the same additionalData and imports as an ordinary import, and ?url of the same file is the URL of the bundled file. hamur dev gives the same string without a sourceMappingURL comment.

ts
import cardCss from "./card.scss?inline"

const sheet = new CSSStyleSheet()
sheet.replaceSync(cardCss)
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet]

Sass, Less and Stylus

Bun has no loader for these languages, so the @hamur/css module compiles them with the compiler your app installs and hands the CSS to Bun. Install the module and the compilers you use, add it to modules, and set options under cssCompilers.

sh
bun add @hamur/css
bun add -d sass less stylus postcss
ts
import { defineConfig } from "hamur"
import css from "@hamur/css"

export default defineConfig({
  framework: "react",
  modules: [css],
  cssCompilers: {
    sass: { additionalData: '@use "#app/styles/vars" as *;', loadPaths: ["styles"] },
  },
})
  • The compiler. sass-embedded is used if installed, else sass; less and stylus are the compilers of their languages. They are imported from the app's root when the first file of the language loads, so an app that installs @hamur/css for Less alone needs no Sass.
  • additionalData. A string, or a function of the file's text and its absolute path, prepended to each file of the language on a line of its own. A file's own $c: red; wins over a $c: blue; in additionalData; write $c: blue !default; there to let files override it.
  • loadPaths. Directories from the app root that @use and @import also look in. For Less and Stylus they are the compiler's paths.
  • Imports. A relative path first, then a key of the app's package.json imports (@use "#app/styles/vars"), then pkg: for Sass (@use "pkg:bootstrap/scss/bootstrap"), then loadPaths. Less and Stylus resolve an @import that starts with an imports key the same way.
  • Errors. A compiler error fails the build at the file, line and column where it is, which may be a partial, and additionalData lines are left out of the count.
  • No source map. Bun ignores a source map from a plugin and writes none for CSS, so the output does not map back to the .scss file; the error position is how a mistake is found.
  • hamur dev. An edit of a partial reaches the open page without a restart.

Without the module, importing such a file fails the build: app/main.scss: Sass needs the @hamur/css module: install @hamur/css and sass and add "@hamur/css" to modules. With the module and no compiler it fails with app/main.scss: @hamur/css needs "sass" or "sass-embedded" installed in the app ("less" and "stylus" the same for their files). The full option list, with each error, is in the @hamur/css reference.

PostCSS

cssCompilers.postcss is a pass over each style of the app and its layers, before Bun's CSS loader. It is on when postcss.config.js, .mjs or .ts is in the root, or when you set it. false ignores the file, { config } names another file from the root, and { plugins } lists plugin instances in the config, used instead of a file.

ts
import { defineConfig } from "hamur"
import css from "@hamur/css"

const brand = {
  postcssPlugin: "brand",
  Declaration: {
    color(declaration: { value: string }) {
      if (declaration.value === "brand") declaration.value = "#0b5fff"
    },
  },
}

export default defineConfig({
  framework: "react",
  modules: [css],
  cssCompilers: { postcss: { plugins: [brand] } },
})

The pass is a transform, not a loader, so it also runs on the CSS another plugin returned (a Sass plugin's output, for one), on the output of Sass, Less and Stylus, and on Vue and Svelte <style> blocks. It skips node_modules and any file outside the app's and the layers' srcDir.

Bun already does the work of autoprefixer, postcss-nesting, postcss-preset-env and postcss-import. A config that lists one logs once, for example [hamur] postcss plugin "autoprefixer" is not needed: Bun's CSS bundler already prefixes, and the plugin still runs. Remove it. With the pass on and no plugin to run, the build logs [hamur] cssCompilers.postcss is on and has no plugins: add postcss.config.mjs or cssCompilers.postcss.plugins.

postcss must be installed in the app; without it the build fails with postcss.config.mjs: @hamur/css needs "postcss" installed in the app. A PostCSS error is reported at the file, line and column of the syntax error.

An app on Tailwind v4 needs no postcss.config.*. A config left over from Tailwind v3, with tailwindcss and autoprefixer in it, turns the pass on and runs the old plugin beside the v4 one. Delete it, or set cssCompilers: { postcss: false }.

ts
import { defineConfig } from "hamur"
import css from "@hamur/css"

export default defineConfig({
  framework: "react",
  modules: [css],
  cssCompilers: { postcss: false },
})

Vue and Svelte style blocks

A component's <style lang> goes through the same compilers when @hamur/css is in modules.

  • Vue. lang is scss, sass, less, styl or stylus, and postcss and css are plain CSS. The block is compiled first, then Vue's own scoped and v-bind() run on the CSS. <style module> gives $style and <style module="m"> gives m, with useCssModule() to read them; the class names are the same in the server and the client build. <style src="./x.css"> reads the file through alias, then from the component's directory. Any other lang fails with app/x.vue: <style lang="foo"> is not supported (css, postcss, scss, sass, less, styl, stylus).
vue
<script setup lang="ts">
const label = "Save"
</script>

<template>
  <button class="save">{{ label }}</button>
</template>

<style lang="scss" scoped>
$accent: #0b5fff;

.save {
  background: $accent;
  &:hover {
    opacity: 0.9;
  }
}
</style>
  • Svelte. lang is scss, sass, less, styl, stylus or postcss, and the rule is still scoped by Svelte's class hash.
svelte
<button class="save">Save</button>

<style lang="scss">
  $accent: #0b5fff;

  .save {
    background: $accent;
    &:hover {
      opacity: 0.9;
    }
  }
</style>

Without the module, a block of those languages fails the build: app/pages/styles.vue: <style lang="scss"> needs the @hamur/css module: install @hamur/css and sass and add "@hamur/css" to modules. React, Preact, Solid and html have no style blocks; their styles are files that an import names, and @hamur/css handles those for every adapter.

CSS modules

A *.module.css file is a CSS module in Bun's bundler: the default export is the class map and Bun names the classes. A *.module.scss file compiles first and then is a CSS module the same way. Only the client build has them. The server build loads every CSS file, a .module.css included, as an empty module, so a page that is rendered on the server and reads a class map has no names there, and there is no build.cssModules key yet. Until Hamur gives a CSS module the same class names on both sides, use a plain stylesheet with scoped class names, or Vue's <style module>, which does not depend on this.

build.inlineStyles

build.inlineStyles is a number of bytes, 0 by default (off). In a production document, rendered or prerendered, each stylesheet of the first render whose file is at most that size is written into the document as <style data-hamur-href="<url>"> instead of a link.

ts
import { defineConfig } from "hamur"

export default defineConfig({
  framework: "react",
  build: { inlineStyles: 4096 },
})
  • A negative or non-integer value fails the load: build.inlineStyles must be a non-negative integer (got -1).
  • Every document repeats the CSS it inlines, so a sheet that pages share is not cached across pages; that is why the key is off. Prefer it for a small sheet that decides the first paint.
  • A url() inside the sheet is whatever Bun wrote into the file, an asset URL or a data: URI.
  • With server.csp, the style-src must allow it. A policy whose style-src lacks 'unsafe-inline', in a mode other than "nonce", fails the load: build.inlineStyles needs 'unsafe-inline' in style-src or server.csp.mode "nonce": the hash of an inline style is not written. With mode: "nonce" the style carries the request's nonce.
  • The client navigator counts an inlined style as the stylesheet with that URL, removes it when the next page no longer needs it, and adds no link for a route whose CSS is already inline.
  • hamur dev writes links, not inline styles.

Tailwind v4

@hamur/tailwind compiles Tailwind v4 with @tailwindcss/node and scans your sources with @tailwindcss/oxide, the two packages that @tailwindcss/vite and @tailwindcss/postcss are thin hosts over. It uses no PostCSS: the CSS goes back to Bun, which bundles and minifies it. The module runs the tailwindcss that is installed in your app, so every utility of that version works, and it needs no postcss.config.* and no tailwind.config file. It has no options.

sh
bun add -d tailwindcss @tailwindcss/node @tailwindcss/oxide @hamur/tailwind
ts
import { defineConfig } from "hamur"
import tailwind from "@hamur/tailwind"

export default defineConfig({
  framework: "react",
  modules: [tailwind],
})

The CSS file holds the import and your theme.

css
@import "tailwindcss";

@theme {
  --color-brand: #0b5fff;
}

.pin {
  @apply -inset-s-4;
}

The app root imports it, so every page links it.

tsx
import { Outlet } from "@hamur/adapter-react"
import "./styles/tailwind.css"

export default function App() {
  return <Outlet />
}

A page uses the utilities as class names.

tsx
export default function Home() {
  return <h1 className="pin text-brand font-bold underline">Hello</h1>
}

The module handles a .css file that imports tailwindcss or uses @apply, @theme, @source, @utility, @variant, @custom-variant, @plugin or @config; every other stylesheet goes to Bun as it is. Tailwind scans the app's root for class names, as @source and @import "tailwindcss" source(…) change it, and writes the utilities they use where the CSS imports tailwindcss. The client build carries the CSS; the server build carries none. In hamur dev, an edit of a source file that adds a class builds the CSS again and the page takes the new stylesheet without a restart or a reload. A class that an edit removes stays in the dev stylesheet until the CSS file changes or hamur dev restarts; the production build holds only the classes the sources use.

tailwindcss 4, @tailwindcss/node and @tailwindcss/oxide are peers of the module and must be installed in the app. With tailwindcss 3 the build fails at setup with @hamur/tailwind needs tailwindcss 4; found 3.4.17. The sample test (apps/web/styling-samples.test.ts) builds this app with version 4.3.5 of the three packages and checks that text-brand, font-bold and -inset-s-4, a utility added in Tailwind 4.2, are in the client CSS.

Tailwind with other PostCSS plugins

To run Tailwind in the same pass as other PostCSS plugins, use @tailwindcss/postcss under @hamur/css instead of the module. The plugin goes in cssCompilers.postcss.plugins and needs no postcss.config.*; base is the directory Tailwind scans for class names. Do not use both.

sh
bun add -d tailwindcss @tailwindcss/postcss postcss @hamur/css
ts
import tailwindcss from "@tailwindcss/postcss"
import { defineConfig } from "hamur"
import css from "@hamur/css"

export default defineConfig({
  framework: "react",
  modules: [css],
  cssCompilers: { postcss: { plugins: [tailwindcss({ base: import.meta.dir })] } },
})

The pass runs on the client build only. The CSS file, the app root that imports it and the page are the ones above. The sample test builds this app with tailwindcss and @tailwindcss/postcss 4.3.5 and checks the same three utilities.

bun-plugin-tailwind is not the recommended path. Tailwind does not maintain it and recommends PostCSS, Vite or its CLI for Bun (tailwindlabs/tailwindcss#19471); a native Bun integration is an open pull request there. Its latest release, 0.1.2 (2025-10), bundles its own Tailwind compiler and ignores the tailwindcss you installed, so it cannot compile utilities added in Tailwind 4.2 or later. A stylesheet that uses one, such as -inset-s-4 in fumadocs-ui, fails the build with Cannot apply unknown utility class.

UnoCSS

There are three ways to run UnoCSS in a Hamur app. This page uses the first, and its test proves that one.

  1. Its PostCSS entry, under @hamur/css. @unocss/postcss is a PostCSS plugin: it reads the files you name, generates the utilities they use and writes them where the CSS says @unocss;. @hamur/css runs it over app/styles/uno.css before Bun's CSS loader. The sample test builds this app with @unocss/postcss and @unocss/preset-mini 66.13.0 and checks that p-4 and text-red-500 are in the client CSS.
  2. @hamur/vite-compat with @unocss/vite. This fails. The build stops in the plugin's configResolved, which reads config.build.rollupOptions, and the plugin generates its CSS in renderChunk, a hook the compat layer does not run. See Vite plugins.
  3. Its CLI, writing app/assets/uno.css (unocss "app/**/*.tsx" -o app/assets/uno.css --watch) next to hamur dev, and import "./assets/uno.css" in the app root. This page does not test it. It needs a second process that rewrites a file, and hamur build does not start it, so a build must run the CLI first.
sh
bun add @hamur/css
bun add -d postcss @unocss/postcss @unocss/preset-mini
ts
import unocss from "@unocss/postcss"
import presetMini from "@unocss/preset-mini"
import { defineConfig } from "hamur"
import css from "@hamur/css"

export default defineConfig({
  framework: "react",
  modules: [css],
  cssCompilers: {
    postcss: {
      plugins: [
        unocss({
          cwd: import.meta.dir,
          configOrPath: { presets: [presetMini()], content: { filesystem: ["app/**/*.tsx"] } },
        }),
      ],
    },
  },
})
css
@unocss;

The app root imports uno.css as the Tailwind sample's imports tailwind.css.

tsx
export default function Home() {
  return <h1 className="p-4 font-bold text-red-500">Hello</h1>
}
  • cwd is the folder the plugin reads files from. Pass the config's own folder, as the sample does; the default is the directory you run hamur from.
  • content.filesystem lists the globs to scan. Without it the plugin reads every html, js, ts, jsx, tsx, vue, svelte, md and similar file below cwd, which includes .output/. A uno.config.ts file in cwd replaces configOrPath.
  • uno.css must be under the app's srcDir: the PostCSS pass skips every other file.
  • The test builds; it does not run hamur dev. Hamur's dev stamp reloads the CSS that a plugin returned, and uno.css is a file Bun reads from disk, so this page does not promise that a class added to a page reaches the open page without a restart.

CSS-in-JS

A library that makes its CSS while components render has to put it in the HTML on the server, or the first paint has no style and the browser adds it after hydration. Whether styles reach the server HTML depends on the library, and for none of them on a Hamur option: Hamur passes the adapter's output through. The sample test (apps/web/styling-samples.test.ts) fetches a page of each React recipe below from the built server and checks the style in the HTML.

LibraryIn the server HTMLHow
emotion (@emotion/react, @emotion/styled), Reactyesemotion writes a <style data-emotion> element beside the element it styles while it renders on the server; nothing to set up
styled-components, Reactyes, for a page sent wholea ServerStyleSheet in the layout, and the CSS it collected through useHead
Vue <style scoped>, <style module>, Svelte <style>, CSS modules, Tailwind, UnoCSSyescompiled at build time into a stylesheet that the document links
Preact, Solid and htmlper libraryno recipe here; a library that injects <style> in the browser only has no style in the server HTML

emotion. Install @emotion/react and @emotion/styled and use them as in the emotion documentation. The page below renders <style data-emotion="css …"> into its server HTML.

tsx
import styled from "@emotion/styled"

const Title = styled.h1`
  color: blue;
`

export default function Emotion() {
  return <Title>Hello</Title>
}

styled-components. Without a ServerStyleSheet, styled-components has no way to give its CSS to the server render, so the HTML has none. Hamur renders React with renderToReadableStream and has no hook that wraps the tree in a library's collector, so the layout does it: it creates one sheet per render on the server, wraps the children in StyleSheetManager, and a component after them reads what the sheet collected into useHead, which writes it as a <style> in <head>. The browser creates no sheet, so the layout's tree has the same shape on both sides and useId() matches.

tsx
import { useHead } from "@hamur/adapter-react"
import type { ReactNode } from "react"
import { ServerStyleSheet, StyleSheetManager } from "styled-components"

const onServer = typeof document === "undefined"

function CollectedStyles({ sheet }: { sheet: ServerStyleSheet }) {
  useHead({ style: [{ innerHTML: sheet.getStyleTags().replace(/<\/?style[^>]*>/g, "") }] })
  return null
}

export default function Layout({ children }: { children?: ReactNode }) {
  const sheet = onServer ? new ServerStyleSheet() : undefined
  return (
    <StyleSheetManager sheet={sheet?.instance}>
      {children}
      {sheet && <CollectedStyles sheet={sheet} />}
    </StyleSheetManager>
  )
}
tsx
import styled from "styled-components"

const Title = styled.h1`
  color: red;
`

export default function Home() {
  return <Title>Hello</Title>
}

The recipe needs the head to be written after the body has rendered, so the document must be sent whole. The config turns the stream off for every path:

ts
import { defineConfig } from "hamur"

export default defineConfig({
  framework: "react",
  routeRules: { "/**": { stream: false } },
})

A page that streams sends <head> before its components render, so styles that components make later are not in it, and the library adds them in the browser. stream: false costs the first byte of the document, since nothing is sent until the page has rendered; apply it to the paths that use styled-components rather than to /** if the rest of the app benefits from streaming (see Islands and streaming).

For a new app, a build-time solution (Tailwind, UnoCSS, CSS modules, Sass, a Vue or Svelte style block) avoids the question: its CSS is a file the document links, in every adapter.