Skip to main contentSkip to docs navigation

Chassis

Use Chassis CSS tokens, components, and utilities in a Tailwind CSS v4 project, with every Tailwind variant available on Chassis utilities.

Chassis CSS ships a separate entry point for Tailwind CSS v4 projects. It keeps Chassis components (.button.outline, .card, .navbar) as plain CSS and emits Chassis utilities (.fg-primary, .font-xl) as Tailwind @utility rules, so every Tailwind variant (dark:, lg:, hover:, @md:, print:) works on them. The entry also resets Tailwind's default theme, which leaves Chassis tokens as the only source of design values.

The Tailwind entry point ships as Sass source, like the regular Chassis entry. Compile it in your own build so your token build and settings apply. Installation covers the parts every Chassis project shares; this guide covers what's specific to Tailwind.

Setup

This guide assumes a project that already compiles Sass, as set up in the Vite, Webpack, or Parcel guide. Tailwind CSS 4.1 or later is required: the entry point excludes clashing class names with @source not inline(), which 4.0 doesn't support.

  1. Install Chassis CSS, its tokens, and Tailwind. postcss and postcss-prefix-custom-properties run the --cx- prefix step described in Build it.

    Shell
    pnpm add @chassis-ui/css @chassis-ui/website-tokens
    pnpm add -D sass tailwindcss postcss postcss-prefix-custom-properties
  2. Point Sass at your token source. Chassis resolves its tokens through a bare chassis-tokens specifier, which Sass finds through loadPaths, the same as in the regular Sass setup. Create _chassis-tokens.scss in a directory your loadPaths already search (src/scss in the bundler guides) and forward your token package from it:

    SCSS
    // src/scss/_chassis-tokens.scss
    @forward "@chassis-ui/website-tokens/dist/web/docs/chassis/main" hide $prefix
    with (
      $cx-color-base-context-light-primary-base-color: #ff6b35,
      $cx-color-base-context-dark-primary-base-color: #ff6b35,
    );

    Customize → Sass → Token sources describes the full mechanism, including partial overrides that need no file at all.

  3. Use the Tailwind entry point in place of the regular Chassis entry. A single @use loads the layer order, theme, tokens, reboot, components, and utilities.

    SCSS
    // src/scss/tailwind-entry.scss
    @use "@chassis-ui/css/scss/tailwind";

    To change $breakpoints or any other setting, configure scss/config first, as you would for the regular entry:

    SCSS
    // src/scss/tailwind-entry.scss
    @use "@chassis-ui/css/scss/config" with (
      $breakpoints: (
        xs: 0,
        sm: 36rem,
        md: 48rem,
        lg: 64rem,
        xl: 80rem,
        2xl: 96rem,
      ),
    );
    @use "@chassis-ui/css/scss/tailwind";

    Write the 2xl key without quotes, as the maps of Chassis do. To Sass a quoted "2xl" is another key, and the gutter, the page margin, and the column count of that breakpoint are then ignored, with a warning for each.

Build it

The --cx- custom-property prefix has to run before the compiled CSS reaches Tailwind's compiler, whichever way your bundler turns Sass into CSS. The JS plugins read --cx-carousel-interval, --cx-breakpoint-*, and similar properties at runtime (see Installation). @chassis-ui/css/postcss exports chassisPrefix({ tailwind: true }), a version of that prefix step that leaves Tailwind's own names alone.

A Tailwind build can't skip the prefix the way a plain Sass build can. Unprefixed, Chassis's --breakpoint-*, --container-*, and --color-* properties collide with Tailwind's theme keys, so prefix: '' throws an error. Any other prefix works. Pick the recipe below that matches your build.

Remove @import "tailwindcss" from your CSS. The Chassis entry loads Tailwind's utilities itself, and a second import declares the @layer order again, which breaks the order the entry depends on.

Two-step build

This recipe works with any bundler, including Parcel and the Tailwind CLI. A script compiles the Sass entry and applies the prefix, and your Tailwind build then imports the resulting CSS file.

JavaScript
// scripts/build-tailwind-source.mjs
import { writeFile } from 'node:fs/promises'
import { chassisPrefix } from '@chassis-ui/css/postcss'
import postcss from 'postcss'
import { compileAsync } from 'sass'

const { css } = await compileAsync('src/scss/tailwind-entry.scss', {
  loadPaths: ['src/scss', 'node_modules'],
  style: 'expanded'
})

const { css: prefixed } = await postcss([chassisPrefix({ tailwind: true })]).process(css, {
  from: undefined
})

await writeFile('src/tailwind-source.css', prefixed)

Run the script to write src/tailwind-source.css:

Shell
node scripts/build-tailwind-source.mjs

Then import the result from the CSS file your Tailwind build compiles:

CSS
/* app.css */
@import "./tailwind-source.css";

Re-run the script whenever src/scss/ changes, before the tool that compiles app.css runs (the Tailwind CLI, @tailwindcss/vite, or @tailwindcss/postcss). That tool resolves the @import and expands the @theme and @utility rules inside it like any other Tailwind source.

Vite

Vite's Sass preprocessor compiles the Tailwind entry directly, and the prefix preset and @tailwindcss/postcss run in the same PostCSS pipeline, so this recipe needs no separate script.

@tailwindcss/vite doesn't transform .scss modules. Vite's Sass preprocessor compiles the file, but the @theme and @utility rules that come out pass through unprocessed. Use @tailwindcss/postcss for a Sass-sourced Tailwind entry.

Install the PostCSS plugin:

Shell
pnpm add -D @tailwindcss/postcss

Add both plugins and the Sass loadPaths to the Vite config:

JavaScript
// vite.config.js
import { defineConfig } from 'vite'
import { chassisPrefix } from '@chassis-ui/css/postcss'
import tailwindcssPostcss from '@tailwindcss/postcss'

export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        loadPaths: ['src/scss', 'node_modules']
      }
    },
    postcss: {
      plugins: [chassisPrefix({ tailwind: true }), tailwindcssPostcss()]
    }
  }
})

Then import the Sass entry from your JavaScript:

JavaScript
// src/js/main.js
import '../scss/tailwind-entry.scss'

Keep the preset before @tailwindcss/postcss in the plugins array. Vite runs this pipeline over every CSS file in your project, so the preset renames your own custom properties too. It leaves Tailwind's names alone: --tw-*, --color-*, and every key you declare in an @theme block, along with var() references to those keys.

Webpack

Webpack runs the same two PostCSS plugins through postcss-loader, placed between css-loader and sass-loader.

Shell
pnpm add -D @tailwindcss/postcss

@chassis-ui/css/postcss is ESM-only. Name the config webpack.config.mjs so it can import the preset instead of going through require().

JavaScript
// webpack.config.mjs
import { chassisPrefix } from '@chassis-ui/css/postcss'
import tailwindcssPostcss from '@tailwindcss/postcss'

export default {
  // … the rest of the config from the Webpack guide
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              postcssOptions: {
                plugins: [chassisPrefix({ tailwind: true }), tailwindcssPostcss()]
              }
            }
          },
          {
            loader: 'sass-loader',
            options: { sassOptions: { loadPaths: ['src/scss', 'node_modules'] } }
          }
        ]
      }
    ]
  }
}

Check it

Markup that combines a component, a responsive variant, and a color-mode variant confirms the whole pipeline at once.

HTML
<div class="container py-lg px-md mx-auto">
  <h1>Hello, Chassis CSS and Tailwind!</h1>
  <button type="button" class="button primary">Primary button</button>
  <button type="button" class="button outline lg:font-xl dark:fg-primary">Responsive, themed</button>
</div>

The second button's text grows at the lg breakpoint from your $breakpoints map, and turns the primary color in dark mode. If both happen, tokens, Sass, the prefix step, and Tailwind are wired correctly.

Prebuilt CSS

@chassis-ui/css/tailwind also resolves to a prebuilt CSS file, compiled with Chassis's default docs/chassis tokens. Use it to prototype without custom tokens or a Sass compile step.

Shell
pnpm add @chassis-ui/css
pnpm add -D tailwindcss

Import the entry from the CSS file your Tailwind build compiles, in place of @import "tailwindcss":

CSS
/* app.css */
@import "@chassis-ui/css/tailwind";

Installation describes the same relationship for dist/css/chassis.css. The prebuilt file suits a prototype; a real project follows Setup so its own tokens and settings apply.

Separate modules

To drop reboot or the components, @use the modules one by one instead of the combined entry.

SCSS
@use "@chassis-ui/css/scss/tailwind/layers";     // @layer order + Tailwind's own utilities layer
@use "@chassis-ui/css/scss/tailwind/theme";      // Chassis breakpoints/containers, variants, exclusions
@use "@chassis-ui/css/scss/tailwind/root";       // Chassis tokens: :root, [data-cx-theme], [dir=rtl]
@use "@chassis-ui/css/scss/tailwind/reboot";     // optional
@use "@chassis-ui/css/scss/tailwind/components"; // optional: type, containers, grid, components, helpers
@use "@chassis-ui/css/scss/tailwind/utilities";  // Chassis utilities as @utility rules

The six rules compile to the same CSS as the combined @chassis-ui/css/scss/tailwind entry, which loads the same parts in this order. Keep layers first and the rest in the order of the list: Sass writes the CSS of a module where it's first loaded, and the layer order has to come before every other rule. Configure settings the same way, with a @use "@chassis-ui/css/scss/config" with (…) before the first module.

The prebuilt CSS has the same split, in the same order:

CSS
@import "@chassis-ui/css/tailwind/layers.css";
@import "@chassis-ui/css/tailwind/theme.css";
@import "@chassis-ui/css/tailwind/root.css";
@import "@chassis-ui/css/tailwind/reboot.css";     /* optional */
@import "@chassis-ui/css/tailwind/components.css"; /* optional */
@import "@chassis-ui/css/tailwind/utilities.css";

Theme reset

The Tailwind entry resets Tailwind's default theme with @theme { --*: initial; }, then declares only the keys Tailwind's variants need: --breakpoint-* and --container-*, read from the $breakpoints map. Tailwind's default color, spacing, font, and shadow scales never generate, so every component and utility resolves through Chassis tokens.

Excluded class names

Some Chassis component and layout classes share a name with a Tailwind core utility: .outline, .collapse, .container, .grid, .static, .list-item, .inline, .table, and .caption-top. The Tailwind entry excludes these names from Tailwind's generation with @source not inline(), so only the Chassis rule applies.

The nav-overflow plugin toggles .d-none at runtime through classList.toggle(), which Tailwind's source scanner never sees. The Tailwind entry safelists the class with @source inline("d-none"), so it always generates.

Grid classes

In the Tailwind entry the grid is split between Chassis and Tailwind core:

  • Chassis provides the grid. .grid, .grid-fill, and the .contained modifier stay plain CSS in the layout layer, and :root carries the gutter, the column count, and the container padding of each breakpoint (--cx-grid-gutter, --cx-grid-columns, --cx-container-padding).
  • Tailwind core provides the placement. col-span-*, col-start-*, col-end-*, row-span-*, row-start-*, row-end-*, col-auto, and row-auto are Tailwind's own utilities. The regular build declares the same properties under the same names, so markup renders the same with either build. Tailwind generates only the classes it finds in your source files, with the sm:–2xl: prefixes of the Chassis breakpoints and the @sm:–@2xl: prefixes of its container queries, at the same widths.
  • Chassis utilities set the tracks and the gaps. grid-cols-*, grid-rows-*, grid-flow-*, auto-cols-*, and auto-rows-* match Tailwind's declarations, as the justify-items-*, justify-self-*, place-content-*, and place-self-* alignment utilities do, and gap-*, row-gap-*, and column-gap-* take the sizes of the Chassis spacing scale (gap-md), not Tailwind's numeric scale.
HTML
<div class="grid">
  <div class="col-span-full md:col-span-8">Main</div>
  <div class="col-span-full md:col-span-4">Aside</div>
</div>

Tailwind core has placement utilities the regular build does not generate, such as negative lines (-col-end-1), row-span-full, and arbitrary values (col-span-[14]), and numeric gaps (gap-4, gap-x-2) generate nothing, since the entry has no numeric spacing scale. Markup that has to render with both builds stays within the classes of the grid system: col-span-{1…12}, col-span-full, col-auto, col-start-{1…12}, col-end-{1…13}, row-span-{1…6}, row-start-{1…6}, row-end-{1…7}, their auto resets, and the grid utilities.

Tailwind's scanner can't see class names built at runtime (`col-span-${n}`). Load the safelist for them.

Removed classes

The flexbox grid (.row, .col-6, .md:col-4, .lg:offset-2, .row-cols-3, .g-md) and the old names of the placement classes (.g-col-4, .g-start-2) were removed in v0.7.0, with the layout sublayer of utilities that held them. See Migrating for the replacement of each class.

col-{n} and col-auto are Tailwind core's own utilities again: col-6 sets grid-column: 6, a column line of a grid, not half the width of a row. Markup that still carries a flexbox grid class compiles without an error in the Tailwind entry and renders something else; search for the old names before upgrading.

Runtime class names

Tailwind generates a class only where its scanner finds the whole name in one of your source files. A name that JavaScript builds from parts (`col-span-${span}`, `${breakpoint}:flex-row`) is never found, so its rule is missing, and nothing warns you: the build passes and the layout is wrong. A component library that turns props into classes works this way. <GridItem span={{ base: 6, md: 3 }}> of @chassis-ui/react renders col-span-6 md:col-span-3, and neither name is in your source.

For such a project the entry has an opt-in safelist. @use it after the main entry:

SCSS
// src/scss/tailwind-entry.scss
@use "@chassis-ui/css/scss/tailwind";
@use "@chassis-ui/css/scss/tailwind/safelist";

With the prebuilt CSS, import safelist.css after the main entry:

CSS
@import "@chassis-ui/css/tailwind";
@import "@chassis-ui/css/tailwind/safelist.css";

The module holds @source inline() rules and nothing else. They name the responsive layout classes, the ones a component maps a layout prop to, so Tailwind generates them whether your source files mention them or not:

  • The placement classes of .grid. col-span-{1…12}, col-span-full, col-auto, col-start-{1…12}, col-end-{1…13}, row-span-{1…6}, row-start-{1…6}, row-end-{1…7}, row-auto, and the auto resets of the lines.
  • The tracks and the gaps. grid-cols-*, grid-rows-*, grid-flow-*, gap-*, row-gap-*, and column-gap-*.
  • The flex layout. flex-row and the other directions, flex-wrap and the other wraps, flex-fill, justify-content-*, align-items-*, and align-content-*.
  • The widths. w-1/12 to w-11/12, w-100, and w-auto.

Each class is listed without a prefix, with the sm:–2xl: prefixes, and with the @sm:–@2xl: prefixes of the container queries, as the regular build generates it. Compiled from Sass, the list follows your settings: $breakpoints, $grid-columns, $grid-rows, $utilities-overrides, $enable-grid-system, and $enable-container-queries.

The safelist trades on-demand generation for the whole set. With the default settings it adds about 80 KB to the minified CSS (9 KB gzipped). Load it only when class names are built at runtime: a project that writes its classes in full needs none of it.

Every other class is still generated on demand, where you write its whole name: the margins, the paddings, d-*, order-*, and the rest of the utilities, and every variant that isn't a breakpoint (hover:, dark:, print:). For one of these that your code builds at runtime, add a rule of your own:

CSS
@source inline("{,md:}p-{sm,md,lg}");

In a Sass build you can add whole utilities instead. $safelist-utilities-extra takes keys of the utilities map, and each utility is listed at the prefixes the regular build generates it at:

SCSS
@use "@chassis-ui/css/scss/tailwind";
@use "@chassis-ui/css/scss/tailwind/safelist" with (
  $safelist-utilities-extra: ("padding", "display"),
);

To list fewer utilities than the default, set $safelist-utilities itself, which holds the keys of the list above.

Variants

Every Chassis utility gets every Tailwind variant, not only the ones Chassis's own generator flags as responsive, dark, or print.

Responsive prefixes

sm:, md:, lg:, xl:, and 2xl: read Chassis's $breakpoints map, not Tailwind's default scale: .sm:d-flex activates at 36rem, matching Breakpoints. Container-query prefixes (.@md:d-flex) read the matching --container-* value from the same map. The regular build generates the @ variants of the grid classes and the layout utilities only; in the Tailwind entry every utility has them.

Dark and light

dark: and light: match both the data-cx-theme attribute and prefers-color-scheme, and the nearest attributed ancestor wins over the media query. Chassis's own light-dark() tokens behave the same way, see Color modes. A .dark:fg-primary element inside a [data-cx-theme="light"] subtree doesn't take the primary color, even under prefers-color-scheme: dark or an outer [data-cx-theme="dark"] ancestor.

HTML
<div data-cx-theme="dark">
  <p class="dark:fg-primary">Primary color (dark ancestor)</p>
  <div data-cx-theme="light">
    <p class="dark:fg-primary">Not primary (nearer light ancestor wins)</p>
  </div>
</div>

The variants support one level of override. CSS selectors can't express "closest matching ancestor" through dark → light → dark nesting of any depth.

Hover

hover: uses Tailwind's default, @media (hover: hover) { &:hover }, where Chassis's own CSS uses a bare :hover. Chassis utilities then behave like every other hover: utility in your project. Chassis's component CSS is unaffected.

Print

print: needs no Chassis-specific setup. Tailwind's built-in print variant works on Chassis utilities the same as on its own.

Utility-name clashes

Some utility names exist in both Chassis and Tailwind core with different values, such as .opacity-50 and .rounded-full. Tailwind merges same-name utilities into one rule, and for these names Tailwind's declaration would win the cascade. The Tailwind entry marks the Chassis declaration !important, so the token-driven value applies. The regular dist/css build is unaffected.

Harmless differences

A few names set a different property in each framework with the same visible result, so the Tailwind entry leaves them as they are:

  • .border and .border-0: Chassis's border shorthand wins over Tailwind's border-style and border-width.
  • .top-auto, .bottom-auto, .mt-auto, and .mb-auto: Tailwind sets a physical property next to Chassis's logical one, and both resolve to auto.
  • .text-wrap and .text-nowrap: Tailwind sets text-wrap, Chassis sets white-space.

Custom utilities

Chassis's build checks these clashes against the default $utilities map only. The reviewed result lives in build/tailwind/utility-clashes.json and build/tailwind/bridge-clashes.json.

The check doesn't run against your customized $utilities. A renamed class, a new entry, or an Options override can introduce a clash with Tailwind core, or with another Chassis name, that nothing catches. Use the two JSON files as the reference for which names clash and how each case is resolved when you triage a new one.

Token bridge

@chassis-ui/css/scss/tailwind/bridge is an opt-in Sass module that maps Chassis's color palette into Tailwind's --color-* theme namespace. @use it after the main entry:

SCSS
@use "@chassis-ui/css/scss/tailwind";
@use "@chassis-ui/css/scss/tailwind/bridge";

With the prebuilt CSS, import bridge.css after the main entry:

CSS
@import "@chassis-ui/css/tailwind";
@import "@chassis-ui/css/tailwind/bridge.css";

The bridge makes the Tailwind color utilities that Chassis has no equivalent for work with the Chassis palette: .ring-*, .outline-*, .decoration-*, .caret-*, .accent-*, .fill-*, .stroke-*, .placeholder-*, gradient stops (.from-*, .via-*, .to-*), and the /<opacity> modifier on any color utility (.bg-primary/50).

It covers the 11 context colors (default, alternate, primary, secondary, neutral, warning, success, danger, info, black, white) and the shade ramp of the seven tinted ones (primary-05 through primary-95, and the same for secondary, neutral, warning, success, danger, and info).

HTML
<button type="button" class="button primary ring-2 ring-primary/50">Focus ring from the Chassis palette</button>
<div class="bg-primary-70">A shade the bg-color utility doesn't expose</div>

Bridged name clashes

The bridge re-enables Tailwind's own .bg-* and .border-* utilities for the 11 color names, which Chassis already generates (.bg-primary, .border-primary). Without a fix, Tailwind's bridged value would win the cascade and drop Chassis's --cx-bg-opacity and --cx-border-opacity support.

The Tailwind entry marks the Chassis declarations !important, the same fix as for utility-name clashes, so .bg-primary and .border-primary behave the same with or without the bridge. .shadow-<color> also matches by name, but Tailwind sets --tw-shadow-color and Chassis sets --cx-shadow-color, so the two don't conflict.

Unbridged scales

Font families, border radius, and shadow sizes aren't bridged. Chassis already generates .font-display, .rounded-lg, and .shadow-lg from the same values, so bridging those namespaces would add name clashes and no new utilities.

JavaScript

Chassis JS doesn't depend on which CSS entry point you import, so it works unchanged with the Tailwind entry. Import the plugins you need:

JavaScript
import { Dialog, Tooltip } from '@chassis-ui/css'

JavaScript covers the full plugin list, events, and the data-attribute API.

Merging classes

tailwind-merge resolves conflicting classes when you build a class string at runtime, for example when a component accepts a className prop that overrides a default. It needs to know which classes belong to the same conflict group. Tailwind's own utilities are built in; a project's custom @utility rules, Chassis's included, aren't.

@chassis-ui/css/tailwind/merge.js exports a classGroups config generated from the same utility map the Tailwind entry uses. It covers every Chassis utility name; the placement classes of .grid are Tailwind's own, which tailwind-merge already knows. The width utilities join its group for w-*, so .w-6/12 resolves against .w-100 and .w-auto.

It also exports overrideClassGroups. tailwind-merge lists grid, table, inline, list-item, collapse, and static among Tailwind's display, visibility, and position utilities, and in the Tailwind entry these names are Chassis classes. The override takes them out of those groups, so a display utility leaves .grid in place. Pass both:

JavaScript
import { extendTailwindMerge } from 'tailwind-merge'
import { classGroups, overrideClassGroups } from '@chassis-ui/css/tailwind/merge.js'

const twMerge = extendTailwindMerge({
  override: { classGroups: overrideClassGroups },
  extend: { classGroups }
})

twMerge('fg-primary', 'fg-danger') // -> 'fg-danger'
twMerge('m-sm', 'm-lg')            // -> 'm-lg'
twMerge('col-span-6', 'col-span-4') // -> 'col-span-4'
twMerge('w-6/12', 'w-auto')        // -> 'w-auto'
twMerge('grid gap-md', 'd-flex')   // -> 'grid gap-md d-flex'

Groups follow Chassis's utility names, not CSS properties. Utilities that set the same property from separate map entries land in separate groups and don't resolve against each other: the base, hover-elevation, and hover-color shadow utilities all set box-shadow, for example. Attribute-selector utilities like .ratio-16x9 have no fixed set of class names, so the config leaves them out.

Next steps

These docs cover the systems the Tailwind entry builds on, and how to keep its output small.

  • Color modes — how data-cx-theme and prefers-color-scheme combine, the same logic the dark: and light: variants follow.
  • Breakpoints — the $breakpoints map that drives sm:–2xl: and @md:–@2xl:.
  • Customize → Optimize — Tailwind's scanner doesn't tree-shake component CSS, so trim unused Sass imports the same way a regular build does.