Skip to main content
Design tokens — shared values for color, spacing, typography, and shadow — are the connective tissue that keeps a design system coherent. In DesignJS, tokens live as CSS custom properties on the canvas iframe’s :root element. The get_variables tool reads the current token map, and set_variables writes or merges new values into it. Changes persist to .designjs.json under cssVariables and are re-applied every time the canvas reloads, so your token definitions survive across sessions and travel with the file in version control.

How tokens work in the canvas

Every CSS custom property you define on :root is available to any component on the canvas via var(--token-name). Because the canvas iframe runs Tailwind v4, you can also reference tokens inside arbitrary Tailwind values: bg-[var(--brand-primary)] or text-[var(--text-muted)] resolve at render time. The full token lifecycle:

Read the current token map

Before adding or changing tokens, read what’s already defined:
The response is a flat Record<string, string> — every key is a CSS custom property name (including the -- prefix) and every value is the raw CSS value string.
If the canvas has no variables set yet, get_variables returns an empty object {}. You’re starting with a clean slate.

Write or update tokens

set_variables merges the variables you provide into the existing set. Existing keys are overwritten; keys you don’t mention are preserved:
The response always returns the full updated map, so you can verify what’s in effect after the call.
There is no delete_variables tool. To remove a token, you currently need to edit .designjs.json directly and reload the canvas. Alternatively, set the variable to unset or an empty string to neutralize its effect in components.

Complete workflow: rebrand a design

This example shows a full token-driven rebrand — switching a design from an indigo palette to a violet one without touching any individual component.
1

Read the current token map

Hue 260 in oklch is indigo. To shift to violet, move the hue to 290.
2

Apply the new brand palette

Every component that references var(--brand-primary) updates immediately in the canvas iframe.
3

Verify visually with a screenshot

If the rebrand looks correct, press Cmd+S to persist the new token values to .designjs.json.

Referencing tokens in components

There are two ways to use a token in a canvas component: 1. Direct CSS custom property reference Pass the var() expression as a CSS value in update_styles:
2. Tailwind arbitrary value syntax Because the canvas iframe runs Tailwind v4, you can use var() inside arbitrary value brackets in the HTML you pass to add_components:
This keeps your HTML declarative and means a single set_variables call repaints every element that uses the token.

Token naming conventions

Consistent naming makes tokens easier to use across components and easier to reference in agent prompts. A recommended pattern:
When prompting an agent to add components, mention tokens by name: “Use var(--brand-primary) for the button background.” The agent will use the token reference rather than hard-coding a hex value, so the component automatically participates in any future rebrands.

About oklch values

The canvas uses oklch as its preferred color format. oklch is perceptually uniform — equal changes in lightness or chroma look visually equal across the spectrum — which makes it well-suited for generating palette variants programmatically. The format is oklch(lightness chroma hue): To generate a full tonal scale for a brand color, vary lightness while holding chroma and hue constant:

Persistence and version control

Token values are stored under cssVariables in .designjs.json:
Because .designjs.json is plain JSON, token changes produce clean, readable git diffs — the exact keys that changed are visible line by line. This makes design-token changes reviewable in a pull request alongside the component changes that use them.

Next steps

Design with an agent

Use tokens in a full agent-driven design session — add components that reference your token names from the start.

Export to React

Export canvas components to .tsx files. Tailwind arbitrary values using var() tokens carry over directly.