Skip to main content
Nexus Design System
GitHub

Tokens

Tokens are the named values every nxds component uses for color, spacing, radius, shadows, borders and motion.

Open the Token lab to browse every token in the current theme.

Token layers

LayerWhat it isExample
PrimitiveA raw value--nx-color-blue-500, a spacing step
SemanticA role that points at a value--nx-color-primary-background
UtilityThe class a component usesnx:bg-primary-background

Components use semantic tokens through utilities. A component that uses a primitive color fails the nxds lint rules.

The nx: prefix

Every nxds class starts with nx:, and every nxds variable starts with --nx-. nxds CSS defines nothing else, so it fits beside your own styles.

The prefix comes before every modifier:

WriteNot
nx:hover:bg-primary-background-hoverhover:nx:bg-primary-background-hover
nx:md:flexmd:nx:flex
nx:[&>svg]:text-foreground[&>svg]:nx:text-foreground

Semantic names

A semantic name is a family, then a role, then an optional state:

PartValues
Familyprimary, secondary, error, success, warning, information
Rolebackground, foreground, border, subtle, subtle-foreground, disabled
Statehover, active

Not every family has every role. The Token lab lists the ones that exist.

The primary button reads nx:bg-primary-background, then nx:hover:bg-primary-background-hover and nx:active:bg-primary-background-active. Every state has its own token, so there are no opacity modifiers like bg-primary/90.

Surfaces follow the same pattern:

SurfaceTokenHover token
Pagebackgroundbackground-hover
Card, panel, rowcontainercontainer-hover
Popover, menupopoverpopover-hover

The name always ends in a role. nx:bg-primary resolves to nothing.

One engine, two moments

deriveTheme() in @nxds/core produces every color token. It runs once at build time to write the default colors into nxds.css. It runs again in the browser whenever the appearance changes.

Same function, same inputs, same output. The page looks right with JavaScript off, and a live theme change needs no rebuild.

Spacing, radius, shadow, border and motion come straight from DTCG JSON (the W3C design token format). nxds.css holds every density, corner, shadow and border option, and the provider picks one with a data attribute. The appearance state is the object described in Appearance.

  1. Token sources. DTCG JSON for color, spacing, radius, shadow, border and motion.

    Appearance state. Brand color, surface tone, mode, density and the other fields.

  2. deriveTheme() in @nxds/core. Builds the color palettes, picks each surface shade and checks contrast. No DOM, no framework.

  3. Build time. Default colors and every spacing, radius, shadow and border option written into nxds.css.

    Runtime. Color variables and data attributes the provider writes when the appearance changes.

  4. nx: utilities. One set of classes that reads whichever value is present.

  5. React components. Copy-and-own source built on the utilities.

Light and dark come from the same call, so dark mode can't drift from light.

Other frameworks

The engine has no framework or DOM code. Another framework needs three functions:

  • createNxdsThemeContract() turns the appearance state into the engine's input.
  • deriveTheme() returns the light and dark color token maps.
  • themeToCss() turns those maps into CSS.

An app that styles itself without CSS, like a React Native app, reads the color token map and the DTCG files directly. Every framework gets the same values, so a React app and a Vue app in one product render the same gray.

ConcernShared by every frameworkBuilt per framework
Token valuesEvery axis: color, spacing, radius, shadow, border, motionNothing
ContrastThe CI checks prove the values, not the componentsNothing
Appearance modelState shape, validation, snapshots, first-paint scriptNothing
Token sourceDTCG JSON, readable by Style Dictionary, Swift and Kotlin toolsA build target
State bindingNoneA provider or store in the framework's own style
ComponentsVariants, data attributes, sizing and focus rulesComponents built on the framework's headless primitives

The nxds components are React.

Next steps

  • Color: how the palette is built and checked.
  • Appearance: every field the engine reads.
  • Token lab: every token in the current theme.