: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: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:
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
260 in oklch is indigo. To shift to violet, move the hue to 290.2
Apply the new brand palette
var(--brand-primary) updates immediately in the canvas iframe.3
Verify visually with a screenshot
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 thevar() expression as a CSS value in update_styles:
var() inside arbitrary value brackets in the HTML you pass to add_components:
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: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 isoklch(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 undercssVariables in .designjs.json:
.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.