Design token system
Panda's design token system gives themes one shared vocabulary for values such as color, space, type, size, and motion. It turns that vocabulary into condition-aware CSS variables and typed access points so utilities, style compositions, generated APIs, and presets can use the same design decisions.
Token model
The token model separates a value's meaning from the styles that consume it. A token has a path, a value, and optional metadata; its category gives Panda enough context to expose the value to matching style properties.
Primitive tokens
Primitive tokens are named values that form the stable base of a theme. They live under categories such as colors, spacing, sizes, fonts, fontSizes, fontWeights, lineHeights, radii, shadows, durations, and gradients; each category describes a kind of value that utilities can accept. The shared Token contract also carries descriptions, types, deprecation data, and extensions for consumers that need more context. packages/…/tokens.ts• L3-10 packages/…/tokens.ts• L69-103
Primitive tokens can refer to other tokens. This lets a theme define a value once and reuse it through a token path rather than copy its raw value. The dictionary keeps both the source value and its resolved form so downstream consumers can use a CSS variable or a raw value when the context requires it. packages/…/token.ts• L49-66 packages/…/token.ts• L101-138
References: packages/…/tokens.ts• L3-10 packages/…/tokens.ts• L69-103 packages/…/token.ts• L49-66 packages/…/token.ts• L101-138
Semantic tokens
Semantic tokens name a role rather than a raw value, such as a surface or text color. Their value can change for a condition while the style that uses the semantic name stays the same. This makes a theme change possible at the token layer instead of requiring each component style to know every visual mode. packages/…/tokens.ts• L19-20 packages/…/dictionary.ts• L140-165
Panda treats a plain semantic value as a base condition and preserves a condition map when a token has several values. The result is one semantic token contract for style authors and a set of condition-specific values for the generated theme output. packages/…/dictionary.ts• L148-165 packages/…/token.ts• L167-188
References: packages/…/tokens.ts• L19-20 packages/…/dictionary.ts• L140-165 packages/…/token.ts• L167-188
Theme inputs
Themes are the product-facing home for tokens and the other style resources that depend on them. A project can define its own theme, extend a preset, or combine several sources before Panda builds one token vocabulary for the project. packages/…/theme.ts• L24-73 packages/…/merge-config.ts• L73-100
Theme configuration
The theme.tokens and theme.semanticTokens sections hold primitive and semantic values. The same theme also names text styles, layer styles, animation styles, recipes, and slot recipes. These composition resources can therefore use the token names established by the theme instead of creating a separate value system. packages/…/theme.ts• L34-61
Theme data accepts nested token paths and a DEFAULT value for a path that also has nested values. Configuration merging normalizes these forms so presets and project configuration can contribute to one consistent theme without losing the base value. packages/…/merge-config.ts• L102-149
References: packages/…/theme.ts• L34-61 packages/…/merge-config.ts• L102-149
Preset foundations
Presets package reusable design foundations for projects. They can provide tokens, semantic tokens, breakpoints, conditions, utilities, patterns, and composition styles; a project then combines those foundations with its own theme choices. The preset library explains the supported preset packages and their roles.
The preset boundary keeps token data portable across packages. For example, the Panda preset supplies a general token set, while Open Props and Atlaskit supply their own token and semantic-token systems. The project receives these values through the same theme contract. packages/…/index.ts• L10-19 packages/…/index.ts• L10-24 packages/…/index.ts• L19-40
References: packages/…/theme.ts• L24-73 packages/…/index.ts• L10-19 packages/…/index.ts• L10-24 packages/…/index.ts• L19-40
Conditions and theme variants
Conditions connect token values to the contexts in which styles apply. They cover project-defined selectors and media-like queries as well as built-in breakpoint, container, and theme conditions. The condition system gives both style rules and semantic tokens a common way to describe alternate output. packages/…/config.ts• L163-204 packages/…/conditions.ts• L53-75
Conditional values
A condition is a named query that can represent an at-rule, a selector, or a composed query. Semantic token values use the same condition names, so a token can provide a base value and alternate values for contexts such as dark mode or a responsive range. packages/…/conditions.ts• L43-64 packages/…/tokens.ts• L19-20
When Panda emits conditional token values, it turns each condition path into the selector or at-rule defined by the condition system. Missing condition definitions prevent a conditional token rule from being emitted because Panda cannot safely map the token value to CSS. packages/…/token-css.ts• L50-101
References: packages/…/conditions.ts• L43-64 packages/…/tokens.ts• L19-20 packages/…/token-css.ts• L50-101
Theme variants
Theme variants are named groups of token or semantic-token overrides. Panda represents each variant as a theme condition and applies it through a theme selector, which lets one generated stylesheet support multiple visual themes without changing component styles. packages/…/config.ts• L152-160 packages/…/conditions.ts• L99-120 packages/…/dictionary.ts• L193-218
Theme variant CSS is an opt-in output when static CSS theme selection is configured. A project must include the needed variants in that selection if it expects their variables in the generated stylesheet. packages/…/token-css.ts• L15-35
References: packages/…/config.ts• L152-160 packages/…/conditions.ts• L99-120 packages/…/dictionary.ts• L193-218 packages/…/token-css.ts• L15-35
Token processing and consumers
Panda builds one token dictionary and shares its views with the compiler's main consumers. The dictionary resolves references, creates condition-specific entries, applies value transforms, and exposes category, variable, raw-value, and condition views. packages/…/dictionary.ts• L68-81 packages/…/dictionary.ts• L463-485 The token dictionary processing page describes that lifecycle in more detail.
The main relationship is shown below.
flowchart LR
A[Theme and presets] --> B[Token dictionary]
B --> C[Resolved token views]
C --> D[CSS variables]
C --> E[Typed token and token APIs]
C --> F[Utilities and compositions]
G[Conditions and theme variants] --> B
G --> D
F --> H[Generated styles]
Style value resolution
Utilities use the token dictionary to map a style property value to the matching token variable or transformed CSS value. This keeps property validation, generated class styles, and token references aligned with the theme categories. packages/…/utility.ts• L36-40 packages/…/utility.ts• L261-267 packages/…/utility.ts• L502-518
Token references can appear in curly-brace form or through the token() value form. Nested references and CSS fallbacks are expanded against the same dictionary, so style composition can use a token without hard-coding its generated CSS variable. packages/…/expand-token-references.ts• L3-8 packages/…/dictionary.ts• L403-424
References: packages/…/utility.ts• L36-40 packages/…/utility.ts• L261-267 packages/…/utility.ts• L502-518 packages/…/expand-token-references.ts• L3-8 packages/…/dictionary.ts• L403-424
CSS and generated APIs
The token layer becomes CSS variables grouped by base or condition. It also becomes generated JavaScript and TypeScript APIs that provide token values, variable references, and constrained token paths for application code. packages/…/token-css.ts• L7-47 packages/…/token.ts• L4-38 packages/…/token-types.ts• L32-72
The generated token documentation uses the same dictionary view as the runtime consumers. It separates ordinary tokens from semantic and conditional values while retaining descriptions, deprecation data, and CSS variable references. packages/…/tokens.ts• L13-57 packages/…/tokens.ts• L59-107
References: packages/…/token-css.ts• L7-47 packages/…/token.ts• L4-38 packages/…/token-types.ts• L32-72 packages/…/tokens.ts• L13-107
Style composition
Style composition gives named text, layer, and animation styles a shared way to describe reusable groups of CSS properties. Because these resources are part of the theme and use the same style property value model, they can consume the token vocabulary that utilities use. packages/…/composition.ts• L90-92 packages/…/composition.ts• L193-220 packages/…/theme.ts• L42-52
The compiler creates the token dictionary before it creates utilities, conditions, recipes, and composition resources. This order gives those consumers one shared source for token names and values rather than separate lookups for each styling feature. packages/…/context.ts• L87-127 packages/…/context.ts• L145-166
References: packages/…/composition.ts• L90-92 packages/…/composition.ts• L193-220 packages/…/theme.ts• L42-52 packages/…/context.ts• L87-127 packages/…/context.ts• L145-166
Change checklist
When these files or sections are changed, remember to consider these:
- When token categories or value types change, check the utility property types and the generated token path types. These consumers must expose the same category names.
- When semantic token condition names or theme variant names change, check the condition definitions and the CSS variable emission rules. A name that is valid in theme data must resolve to a CSS selector or at-rule.
- When token reference syntax changes, check config validation, dictionary expansion, utility value resolution, and the generated
token()API together. - When preset theme data changes, check merge behavior for
extendandDEFAULT. Flat and nested token forms must still produce one stable token path. - When composition style contracts change, check that the token dictionary is still created before utilities, recipes, and composition consumers.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A token or semantic token has no valid value shape. | Configuration validation reports an invalid token and downstream consumers do not receive a reliable value. | Validate the token at its theme path before dictionary processing. |
| A token refers to a missing token. | The project reports a missing or unknown token reference instead of silently generating a broken value. | Keep referenced paths in the same merged theme and run token reference validation. |
| A reference points to itself or forms a cycle. | Reference resolution cannot reach a final value. | Reject self references and circular reference chains during validation. |
| A semantic token uses a condition that is not defined. | Its conditional CSS variable rule is skipped because no selector or at-rule can be built. | Define the condition before using it in semantic values. |
| A theme variant is absent from static CSS theme selection. | Its theme variables are omitted from the generated stylesheet. | Include the variant in staticCss.themes when static output is required. |
Key files
| File | Why to read it |
|---|---|
| packages/…/tokens.ts | Defines primitive token categories, semantic token values, and token metadata. |
| packages/…/theme.ts | Defines the theme boundary for tokens, semantic tokens, and style composition. |
| packages/…/conditions.ts | Defines condition names and the conditional value shape shared by styles and tokens. |
| packages/…/dictionary.ts | Shows how theme inputs become shared token views for compiler consumers. |
| packages/…/token.ts | Shows the common token model, references, and condition-specific values. |
| packages/…/merge-config.ts | Explains how project configuration and presets become one theme input. |
| packages/…/validate-tokens.ts | Shows the contract checks applied to primitive and semantic token data. |
| packages/…/validate-token-references.ts | Shows how missing, unknown, self, and circular references are rejected. |
| packages/…/conditions.ts | Defines the condition and theme-variant vocabulary used for generated styles. |
| packages/…/utility.ts | Shows how style property values resolve through the token dictionary. |
| packages/…/context.ts | Shows how the token dictionary is shared with utilities, conditions, recipes, and compositions. |
| packages/…/token-css.ts | Shows how base and conditional token variables become CSS. |
| packages/…/token.ts | Shows the generated runtime token and variable access API. |