Make a repository of tokens with chassis-tokens init, change and build its tokens, and use them in a web, iOS or Android project.
This page is a work in progress. Parts of it may be incomplete or differ from the current version of Chassis Tokens.
Introduction
This guide takes you from an empty folder to a repository of tokens, a first build, and the tokens in a project.
The repository is yours. chassis-tokens init writes the Chassis token system into it, and from then on you own its values: you change them, name your brands and apps, and build them with the chassis-tokens command. The token system is built on three groups, brand, theme and app; the introduction describes them.
Prerequisites
The repository needs Node.js and Git, and each project needs the tools of its platform.
- Repository: Git, Node.js 22.12 or later, and npm or pnpm.
- Web: a project with Sass.
- iOS: an app that targets iOS 13 or later and uses Swift Package Manager.
- Android: a module with a minimum SDK of 21 or later.
Create the repository
chassis-tokens init writes a repository of tokens into a new folder. --brand and --app name what it starts with, and --app gives each app its platforms:
npx @chassis-ui/tokens init acme-tokens --brand acme globex --app site:web mobile:ios,android
cd acme-tokens
git init
npm installThe folder now holds a package.json with the chassis.build block and the scripts, .gitignore and .nvmrc, a README, a changelog, the instructions for AI coding agents in AGENTS.md and CLAUDE.md, the workflows of CI and of a release, and the token sets of the Chassis token system in source/. @chassis-ui/tokens is a development dependency, and every command runs from the root of the repository. Commit the lockfile of the install with the rest: the workflows install from it.
Check the setup with a dry run, which prints the builds and the files of each and writes nothing:
npx chassis-tokens build --dry-runThe plan starts with the web files of the first brand:
• acme_site_light
dist/web/site/acme/: main.scss, string.scss, color-light.scss, number.scss
• acme_site_dark
dist/web/site/acme/: color-dark.scssChange the tokens
The token sets are the JSON files of source/, in Tokens Studio format. source/base/ holds the sets of every brand, app and theme, and source/brand-<brand>/brand-base.json the values of one brand, which override the base. Edit them in Figma with Tokens Studio, synced to your repository with the file path source, or edit the JSON files directly. The Tokens Studio guide describes the token sets and the groups.
Lint the token sets before you build:
npx chassis-tokens lint-sourceThe lint names the token set and the token of each mistake that the build would accept, such as a token that one theme declares and another does not.
Configure the build
The build writes only what chassis.build lists. The block that init wrote, in package.json:
"chassis": {
"build": {
"brands": ["acme", "globex"],
"themes": ["light", "dark"],
"apps": {
"site": ["web"],
"mobile": ["ios", "android"]
}
}
}| Key | Holds |
|---|---|
brands | Options of the brand group of source/$themes.json |
themes | Options of the theme group; the first is the default |
apps | Options of the app group, each with its platforms |
screens | Optional: options of the screen group; the first is the default |
options | Optional: Style Dictionary options by platform name |
A brand, a theme or an app is an option of its group in source/$themes.json and a name in chassis.build, so keep the two in step. Without screens the build writes one number file, with no screen in its name; a repository that needs values per screen adds a screen group, as the Style Dictionary guide describes.
A platform is web, ios, android or a preset: web-scss, web-px and web-vw for a CSS framework other than Chassis CSS, ios-swiftui and android-compose for SwiftUI and Jetpack Compose. The Style Dictionary guide describes every key, platform and preset.
Build
Build the tokens of the configuration:
npx chassis-tokens buildThe build writes the files of every app and brand to dist/<platform>/<app>/<brand>/. Filters build a part of the configuration, and you can combine them:
npx chassis-tokens build --brand acme --platform webWhen an app has an iOS platform, write the manifest of the Swift package after the first build, and again after a change to the brands or apps of chassis.build. It has one library for every app and brand with an iOS platform, and CI checks that it follows the configuration, so commit it with dist/:
npx chassis-tokens swift-packageReview what a change does to the token names and values, compared with the main branch, and commit dist/ with your change. Before the repository has a main branch, the command says so, and --base names a branch, tag, commit or folder to compare with instead:
npx chassis-tokens diffRelease a version
A release is a push to main with a new version in package.json and its entry in CHANGELOG.md. The workflow that init wrote publishes the package to npm, and creates the tag v<version> and its GitHub release, with the Android libraries and one archive per platform, app and brand attached. The repository at that tag is the Swift package. A push whose version has a tag releases nothing.
Use the tokens
A project takes the tokens of one app and brand from a release. The examples use the package acme-tokens, the repository acme/acme-tokens on GitHub and the brand acme.
Web
The npm package holds the SCSS files of each brand of a web app in dist/web/<app>/<brand>/. Install it in your project:
npm install acme-tokensUse main.scss with @use and read a token as a variable of the module:
@use 'acme-tokens/dist/web/site/acme/main' as tokens;
.card {
padding: tokens.$cx-space-context-medium;
}Sass has to find the packages of node_modules. With the sass command, add --load-path=node_modules.
The SCSS of the web platform is written for Chassis CSS. Some variables hold a custom property that Chassis CSS generates: $cx-color-accordion-item-fg-color is var(--default-fg-main). Without Chassis CSS, build the app with a preset that prints values, such as web-scss.
The web guide covers the other files and the themes.
iOS
The Swift package holds one library per app and brand, such as ChassisTokensMobileAcme for the app mobile and the brand acme. Add the package https://github.com/acme/acme-tokens.git to your app with Swift Package Manager, and add the library of your brand to your target.
Use the constants of the types ChassisTokens and ChassisTokensColor:
import ChassisTokensMobileAcme
import UIKit
enum CardStyle {
static let background: UIColor = ChassisTokensColor.ColorContextDefaultBgMain
static let padding: CGFloat = ChassisTokens.SpaceContextMedium
}The colors of ChassisTokensColor follow the light and dark appearance. The iOS guide covers the other types and the icons.
Android
The Android library holds the resource tree of one brand. Download acme-tokens-android-mobile-acme-<version>.aar from the GitHub release of the version and copy it to the libs/ folder of your module.
Add the file to the dependencies in the build.gradle.kts of the module:
dependencies {
implementation(files("libs/acme-tokens-android-mobile-acme-<version>.aar"))
}Use the resources in a layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_context_default_bg_main"
android:padding="@dimen/space_context_medium" />The library holds the colors of the dark theme in values-night, so a color follows the night mode of the device. The Android guide covers the resource folders and the icons.
Troubleshooting
Each entry gives the message or the symptom, then the cause and the fix.
Stylesheet not found
Sass stops with Error: Can't find stylesheet to import. at the @use rule of the tokens. Sass does not search node_modules by itself. Add --load-path=node_modules to the sass command. For a bundler, see the web guide.
No token sets
The build stops with No token sets for <brand>_<app>_<theme> in source/$themes.json, with the names of the list it looked for. chassis.build lists a brand, theme or app that is not an option of its group in source/$themes.json. Correct the name in chassis.build, or add the option to the group in Tokens Studio.
Next steps
- The web, iOS and Android guides cover the files and themes of each platform.
- The Tokens Studio guide and the Figma Variables guide cover the token sets and their sync with Figma.
- The Style Dictionary guide is the reference of the build: its options, platforms, presets, screens and files.
- The token categories start with the color tokens and the space tokens.