Utilize Chassis source Sass files to take advantage of variables, maps, mixins, and functions to customize and extend the framework.
Chassis ships its source on the Sass module system (@use / @forward). Pull individual modules in, override their defaults with @use … with (…), and compose your own bundle without touching framework source.
File structure
Whenever possible, avoid modifying Chassis source files. Create your own stylesheet that uses Chassis instead. With a package manager you'll have something like:
your-project/
├── scss/
│ └── custom.scss
└── node_modules/
│ └── @chassis-ui/
│ └── css/
│ ├── js/
│ └── scss/
└── index.htmlIf you downloaded the source files manually, mirror that layout — keep Chassis's source separate from your own.
Importing
In your custom.scss, pull Chassis in with @use. Two options are available: load all of Chassis, or pick the parts you need. Prefer the latter, though be aware components have dependencies across the framework.
// custom.scss
// Option A: Load all of Chassis CSS
@use "@chassis-ui/css/scss/chassis";
// Then add custom code here// custom.scss
// Option B: Load parts of Chassis CSS
// 1. Variables first — configure here with `@use … with (…)` if needed
@use "@chassis-ui/css/scss/config" as *;
// 2. Functions (so you can manipulate colors, SVGs, maps, etc)
@use "@chassis-ui/css/scss/functions" as *;
// 3. Maps and mixins
@use "@chassis-ui/css/scss/maps" as *;
@use "@chassis-ui/css/scss/mixins" as *;
// 4. CSS custom property layer
@use "@chassis-ui/css/scss/root";
// 5. Optional parts; see chassis.scss for the full list
@use "@chassis-ui/css/scss/reboot";
@use "@chassis-ui/css/scss/type";
@use "@chassis-ui/css/scss/grid";
@use "@chassis-ui/css/scss/utilities";
@use "@chassis-ui/css/scss/helpers";
// 6. Utilities API last — generates classes from the `$utilities` map
@use "@chassis-ui/css/scss/utilities-api";With that setup in place, you can override variables (see below) and add Chassis modules as needed. Use the @use stack in chassis.scss as a starting reference.
Importing Chassis with bare specifiers (@chassis-ui/css/scss/…) requires your Sass setup to resolve node_modules. Vite, Webpack, and Astro do this automatically. For the Sass CLI, add --load-path node_modules/.
Compiling
You need a Sass compiler. Sass ships as a CLI package, but you can also compile with Vite, Webpack, Parcel, Gulp, or any other build tool.
# Install Sass
npm install -D sass
# Watch your custom Sass for changes and compile it to CSS
npx sass --watch --load-path node_modules/ ./scss/custom.scss ./css/custom.cssIncluding
Once your CSS is compiled, include it in your HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Custom Chassis CSS</title>
<link href="/css/custom.css" rel="stylesheet">
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>Variable defaults
Every Chassis Sass variable is declared with !default. Under the module system, you configure the defaults where you load the module, with @use … with (…):
@use "@chassis-ui/css/scss/config" with (
$enable-rounded-borders: false,
$paragraph-margin-bottom: 1.5rem,
);
@use "@chassis-ui/css/scss/chassis"; // picks up your configured defaultsscss/config is the one module to configure. It forwards the feature flags of scss/config/_settings.scss, the defaults of scss/config/_defaults.scss, and the token variables of scss/tokens/, such as the context colors:
@use "@chassis-ui/css/scss/config" with (
$primary: #0074d9,
$danger: #ff4136,
);
@use "@chassis-ui/css/scss/chassis";Sass loads each module exactly once, so the configured instance is shared by every downstream module that uses it. That has two consequences for your file:
- The
with (…)rule must come before any module that loads the configuration, so put it first. - A module is configured once. Put every variable you change in the same
with (…); a second one stops the compile with an error.
Some variables default to null. Those don't emit the property unless you override them.
Those three places hold the complete list of variables. @use "@chassis-ui/css/scss/config/defaults" with (…) configures the same ones.
Get started with Chassis CSS via npm with our starter project! Head to the Sass & JS example template repository to see how to build and customize Chassis CSS in your own npm project. Includes Sass compiler, Autoprefixer, Stylelint, PurgeCSS, and Chassis CSS Icons.
Maps and loops
Chassis ships several Sass maps — key/value pairs that power families of related CSS (colors, breakpoints, etc.). Every map is !default: you replace one through @use … with (…), and you add to one or remove from one by assigning to it before the framework loads.
Modify a map
Most map entries are exposed as standalone variables ($primary, $danger, etc.). Configure those variables and the maps that reference them update automatically:
@use "@chassis-ui/css/scss/config/defaults" with (
$primary: #0074d9,
$danger: #ff4136,
);Replace a map
Configure the map itself to replace it. The build then has the entries you list and none of the default ones. This leaves two ratio utilities, .ratio-1x1 and .ratio-2x1:
@use "@chassis-ui/css/scss/config" with (
$aspect-ratios: (
"1x1": #{"1 / 1"},
"2x1": #{"2 / 1"},
)
);
@use "@chassis-ui/css/scss/chassis";Add to a map
A with (…) configuration can't read the map it replaces: Sass evaluates it before the module loads. To extend a map, load its module, assign the merged map to the module's variable, and load the framework after the assignment. This adds .ratio-2x1 to the default ratios:
@use "sass:map";
@use "@chassis-ui/css/scss/config" as config;
config.$aspect-ratios: map.merge(config.$aspect-ratios, ("2x1": #{"2 / 1"}));
@use "@chassis-ui/css/scss/chassis";The assignment has to come before @use "@chassis-ui/css/scss/chassis". The framework writes its CSS when it loads, so an assignment after that rule changes nothing, and Sass reports nothing. A plain $aspect-ratios: map.merge(…) without the config. namespace only creates a variable in your own file.
To set variables and assign to a map in the same file, add the with (…) to the rule that loads the module: @use "@chassis-ui/css/scss/config" as config with (…).
Remove from a map
Assign the result of map.remove() in the same way. This removes .ratio-4x3 and .ratio-21x9:
@use "sass:map";
@use "@chassis-ui/css/scss/config" as config;
config.$aspect-ratios: map.remove(config.$aspect-ratios, "4x3", "21x9");
@use "@chassis-ui/css/scss/chassis";The maps of scss/maps/, such as $spaces, take the same assignment through @use "@chassis-ui/css/scss/maps" as maps. For the utility classes themselves, see $utilities-overrides.
Grid maps
Three maps, keyed by breakpoint, set the measures of the grid system: $grid-gutters (the gap of .grid), $grid-column-counts (its number of columns), and $container-paddings (the padding of .container, the page margin). Each becomes a custom property on :root, declared again at a breakpoint only where the value changes, so a map can list just the breakpoints where something changes:
@use "@chassis-ui/css/scss/config/defaults" with (
$grid-column-counts: (xs: 4, md: 8, lg: 12),
$container-paddings: (xs: 1rem, md: 1.5rem, xl: 2rem),
);
@use "@chassis-ui/css/scss/chassis";The first breakpoint (xs) must be in the map: it is the value every viewport starts from, and the compile stops on a map without it. A key that is not a breakpoint is ignored, with a warning, and so is a width of $container-max-widths. $grid-gutter-x, $grid-gutter-y, $grid-row-columns, $gutters, and $container-padding-x configured the flexbox grid and were removed with it in v0.7.0; see Migrating.
Required keys
Chassis assumes certain keys exist in some maps. For example, the framework consumes primary, success, and danger from $context-colors for links, buttons, and form states. Changing their values is safe; removing them may cause Sass compilation errors that you'll have to address in your own overrides.
A context color also spans more maps than $context-colors: its dark value is in $context-colors-dark, and the palettes and the button colors have entries of their own. A key added to $context-colors alone stops the compile, and a key removed from it alone leaves the component rules of that color in the CSS.
Functions
Colors
Chassis uses oklch as its default color space. For the full picture, see Color System and Design Tokens.
The following functions in scss/functions/_color.scss are the primary tools for working with colors.
to-color()
Converts any Sass-compatible color to a rounded oklch() string. The framework uses it internally to normalize tokens before writing them to CSS custom properties.
/// Convert a color to an oklch() value with rounded channel values
/// Converts any Sass-supported color to the OKLCh color space, rounding lightness
/// to 2 decimal places of a percentage, chroma to 3 decimal places, and hue to 2 decimal places.
/// Alpha is preserved when less than 1.
///
/// An achromatic color (chroma rounds to 0) has no hue, and is written as oklab()
/// with the same lightness: the color is the same one, with no hue to write.
///
/// @param {Color} $color - Any Sass-compatible color value
/// @return {String} - Unquoted oklch() color with rounded L, C, H channels and preserved alpha,
/// or oklab() for an achromatic color
/// @example
/// to-color(#ff0000) => oklch(62.8% 0.258 29.23deg)
/// to-color(rgba(#ff0000, 0.5)) => oklch(62.8% 0.258 29.23deg / 0.5)
/// to-color(#fff) => oklab(100% 0 0)
@function to-color($color) {
$oklch: color.to-space($color, oklch);
// Extract and round channels
$l: math.div(math.round(color.channel($oklch, "lightness", oklch) * 100), 100);
$c: math.div(math.round(color.channel($oklch, "chroma", oklch) * 1000), 1000);
$a: color.alpha($color);
// Achromatic colors (chroma rounds to 0) have no meaningful hue, and Sass gives
// them the `none` keyword. `oklch(L 0 none)` is valid, but it is also the computed
// value, which axe-core cannot parse: its color-contrast rule then skips the page.
// A hue of 0 is no replacement, since color-mix(in oklch, …) and gradients
// interpolate towards it, where a missing hue takes the hue of the other color.
// oklab() has no hue to write, and a browser that converts it to oklch for an
// interpolation finds a chroma of 0 and treats the hue as missing again.
$value: "oklab(#{$l} 0 0";
@if $c != 0 {
$h: math.div(math.round(color.channel($oklch, "hue", oklch) * 100), 100);
$value: "oklch(#{$l} #{$c} #{$h}";
}
// Use string interpolation so the CSS '/' is a channel separator, not Sass division.
@if $a < 1 {
@return #{"#{$value} / #{$a})"};
}
@return #{"#{$value})"};
}$converted: to-color(#0d6efd);
// => oklch(57.82% 0.228 260.03deg)
$with-alpha: to-color(rgba(#0d6efd, 0.5));
// => oklch(57.82% 0.228 260.03deg / 0.5)
$achromatic: to-color(#fff);
// => oklab(100% 0 0)A color with no chroma (white, black, a gray) has no hue, and to-color() writes it as oklab(). It is the same color: oklch(100% 0 none) is valid CSS with a missing hue, but tools that read computed colors, such as axe-core, cannot parse it. When you mix such a token with color-mix(in oklch, …), the browser finds no chroma and takes the hue of the other color, as it does for #fff.
Because to-color() outputs a string in the oklch space, it works in any browser with oklch support. To use a different color space as your default, swap calls to to-color() for a function that emits your preferred space (color(display-p3 …), lch(…), etc.).
to-opacity()
Wraps a color or CSS variable in a CSS relative color expression that applies an opacity value via the oklch channel syntax. This is how Chassis applies contextual opacity to tokens at runtime without generating separate color variants.
/// Generate a CSS relative color expression that applies an opacity variable to a CSS custom property
/// Uses the CSS relative color syntax to derive an oklch color from an existing
/// CSS variable and apply a separate opacity (alpha) CSS variable to it.
///
/// @param {Color|String} $color - Color value or `var()` expression used as the relative color origin
/// @param {Number|String} $opacity - Alpha value (0–1) or `var()` expression for the opacity channel
/// @return {String} - Unquoted CSS relative color string: oklch(from {color} l c h / {opacity})
/// @example
/// to-opacity(var(--cx-primary), 0.5) => oklch(from var(--cx-primary) l c h / 0.5)
/// to-opacity($white, .15) => oklch(from #fff l c h / 0.15)
/// to-opacity(var(--cx-fg-main), var(--cx-fg-opacity, 1)) => oklch(from var(--cx-fg-main) l c h / var(--cx-fg-opacity, 1))
@function to-opacity($color, $opacity) {
@return #{"oklch(from #{$color} l c h / #{$opacity})"};
}$half: to-opacity(var(--cx-primary), 0.5);
// => oklch(from var(--cx-primary) l c h / 0.5)
$faint: to-opacity(#fff, .15);
// => oklch(from #fff l c h / 0.15)
$runtime: to-opacity(var(--cx-fg-main), var(--cx-fg-opacity, 1));
// => oklch(from var(--cx-fg-main) l c h / var(--cx-fg-opacity, 1))The from keyword and channel names (l c h) are specific to oklch. If you change the default color space, update the channel names accordingly.
opacity-var()
A shorthand variant of to-opacity() designed to work as a map-loop callback. It takes an unprefixed color identifier and an opacity component name and returns a relative color expression. The framework's --cx- prefix is added later by the PostCSS prefix step — the Sass output uses unprefixed variable names.
/// Generate a CSS relative color expression that applies a component opacity variable to a color token
/// Uses CSS relative color syntax to derive an oklch color from a CSS custom property and apply
/// a separate opacity CSS variable to it. Designed to work as a `map-loop` callback.
///
/// The framework's `--cx-` prefix is added later by the PostCSS prefix step;
/// the Sass output of this function uses unprefixed variable names.
///
/// @param {String} $identifier - Color CSS variable name without prefix (e.g., "primary", "fg-main")
/// @param {String} $target - Opacity variable component name without prefix (e.g., "fg", "bg", "icon")
/// @return {String} - Unquoted CSS relative color: oklch(from var(--{identifier}) l c h / var(--{target}-opacity, 1))
/// @example
/// opacity-var("primary", "bg") => oklch(from var(--primary) l c h / var(--bg-opacity, 1))
/// opacity-var("fg-main", "fg") => oklch(from var(--fg-main) l c h / var(--fg-opacity, 1))
@function opacity-var($identifier, $target) {
@return #{"oklch(from var(--#{$identifier}) l c h / var(--#{$target}-opacity, 1))"};
}$bg: opacity-var("primary", "bg");
// => oklch(from var(--primary) l c h / var(--bg-opacity, 1))
$fg: opacity-var("fg-main", "fg");
// => oklch(from var(--fg-main) l c h / var(--fg-opacity, 1))This function is used when generating utility classes and component styles that need to respect a runtime opacity variable.
Escape SVG
The escape-svg() function escapes <, >, and # for SVG background images. Data URIs passed to it must be quoted.
Mixins
The scss/mixins/ directory contains the mixins that power Chassis components; they're also useful in your own code.
Color schemes
A shorthand for the prefers-color-scheme media query with light and dark support. See the color modes documentation for the broader color-mode mixin.
/// Wrap `@content` in a `@media (prefers-color-scheme: ...)` query.
///
/// @param {String} $name - Color scheme name (`light` or `dark`)
/// @content Styles to apply under this color scheme preference
@mixin color-scheme($name) {
@media (prefers-color-scheme: #{$name}) {
@content;
}
}@use "@chassis-ui/css/scss/mixins" as *;
.custom-element {
@include color-scheme(light) {
// light mode styles
}
@include color-scheme(dark) {
// dark mode styles
}
}Token sources
Chassis loads its design tokens through a single override point — a Sass module named chassis-tokens, which scss/config/_vendor.scss forwards and Sass finds on its loadPaths. The framework's default is scss/vendor/_chassis-tokens.scss, so swapping the entire token feed is a one-line change in a file you control.
By default _chassis-tokens.scss forwards from @chassis-ui/website-tokens/dist/web/docs/chassis/main. Sass loads each module exactly once, so every downstream module — variables, maps, components — picks up whatever your override produces.
Switching token source
Create a _chassis-tokens.scss file in your project that forwards your preferred token set:
// my-project/sass-overrides/_chassis-tokens.scss
@forward "@chassis-ui/website-tokens/dist/web/docs/sinefil/main";Then configure your build tool to search your override directory before the Chassis defaults. Because _chassis-tokens.scss sits at the root of the token dependency tree, all downstream modules pick up your token values automatically. A token set of your own is built with @chassis-ui/tokens and its chassis-tokens command, and forwarded the same way.
// vite.config.ts (or astro.config.ts)
import path from 'node:path'
export default {
css: {
preprocessorOptions: {
scss: {
loadPaths: [
path.resolve('./sass-overrides/'), // your _chassis-tokens.scss first
path.resolve('./node_modules/@chassis-ui/css/scss/vendor'), // framework fallback
path.resolve('./node_modules'), // bare package specifiers (@chassis-ui/website-tokens/…)
],
},
},
},
}Grid tokens
The page margins ($margin-xsmall to $margin-2xlarge) and the column counts ($columns-xsmall to $columns-2xlarge) come from the token source, as cx-grid-margin-* and cx-grid-columns-*, like the gutters, the breakpoints, and the container widths (cx-grid-gutter-*, cx-grid-breakpoint-*, cx-grid-container-*). @chassis-ui/website-tokens ships the margins and the column counts. Rebuild a token set of your own that was built with @chassis-ui/tokens before 0.7.0: without the twelve variables the compile stops at an undefined variable.
To change a value without a token build, set the variables of scss/tokens/_grid.scss, or the grid maps that read them. They go in your config rule, with the other variables you change:
@use "@chassis-ui/css/scss/config" with (
$margin-xsmall: 1rem,
$columns-xsmall: 4,
);
@use "@chassis-ui/css/scss/chassis";Configuring variables
For partial overrides — adjusting a handful of token values — set the tokens by name in the same config rule. Sass loads the configured token source once and shares it with every downstream module:
// custom-entry.scss
@use "@chassis-ui/css/scss/config" with (
$cx-color-base-primitive-light-primary-50: #ff385c,
$cx-color-base-primitive-light-primary-40: #ff6a85,
);
// All subsequent chassis modules use the configured tokens
@use "@chassis-ui/css/scss/chassis";This is practical for a handful of targeted adjustments. For a full theme swap (~1,200 variable differences between token sets), the _chassis-tokens.scss override above is far more maintainable.
Overriding properties
To adjust visual output after the Sass compilation step, override the generated CSS custom properties:
:root {
--cx-primary: oklch(0.61 0.23 11.3);
}CSS custom property values are written by scss/_root.scss during compilation. Computed values — color maps, palette entries used inside component selectors — reflect the compiled token set and can't be changed post-compile. CSS custom property overrides are best suited for targeted, runtime adjustments.