UX-DSL
XS0px

Colors

Define reusable color values. Connect them to palette roles in your theme.

Define your colors once. Build palettes from them.

UXDSL builds on standard CSS. Colors define the available color values; Palette assigns colors to interface roles. Both are configured in the theme JSON. Prefer palette() when a component expresses a role such as primary action or surface. Use color() when a specific color token is intentional, and standard CSS when finer control is needed.

Colors are a collection of reusable color values. You can organize them into families and shades, or define individual named entries. The shade number is a key, not a computed brightness or a guarantee of contrast.

1. Define Colors and Palette in the theme JSON

This reference excerpt defines a color collection and connects palette roles to it using CSS variable references:

{
  "colors": {
    "blue": { "500": "#3b82f6", "700": "#1d4ed8" },
    "white": "#ffffff",
    "ink": "#0f172a"
  },
  "palette": {
    "primary": {
      "main": "var(--uxdsl__color__blue-700)",
      "contrast": "var(--uxdsl__color__white)"
    },
    "surface": {
      "main": "var(--uxdsl__color__white)",
      "contrast": "var(--uxdsl__color__ink)"
    }
  }
}

The nested entry colors.blue["700"] produces --uxdsl__color__blue-700. The nested role palette.primary.main produces --uxdsl__palette__primary-main.

References preserve the connection. In this JSON, primary.main references blue-700. Changing that color updates the role once the theme is compiled or applied. A literal hex value in a palette is also valid, but copying a color’s hex value does not create a reference to that color token.

2. Express the intended role in components

UXDSL you write

.primary-action {
  background: palette(primary.main);
  color: palette(primary.contrast);
}

/* Deliberately use a specific color token */
.blue-swatch {
  background: color(blue-700);
}

Equivalent plain CSS

:root {
  --uxdsl__color__blue-700: #1d4ed8;
  --uxdsl__color__white: #ffffff;
  --uxdsl__palette__primary-main: var(--uxdsl__color__blue-700);
  --uxdsl__palette__primary-contrast: var(--uxdsl__color__white);
}

.primary-action {
  background: var(--uxdsl__palette__primary-main);
  color: var(--uxdsl__palette__primary-contrast);
}
.blue-swatch {
  background: var(--uxdsl__color__blue-700);
}

The CSS shows only the variables used by these two selectors. Plain CSS custom properties provide the same reference mechanism; UXDSL connects component syntax to the theme’s shared definitions.

3. Choose the scope of the change

  • Update a color value: change colors.blue["700"] to update direct consumers and palette roles that reference it.
  • Reassign a role: change palette.primary.main to reference blue-500. Primary actions follow that role; direct color(blue-700) consumers keep their token.
  • Change one component: choose another appropriate existing role or color token in that component, without changing shared definitions.

Apply changes through the theme build or supported runtime API. Existing overrides and active modes can affect the final value. A variant named contrast is a configured foreground color, not proof of accessible contrast; check the actual foreground/background pair in each relevant state and theme.

Explore the live color collection

The swatches and examples below show the playground’s color collection. Edit a color to inspect its direct consumers and any explicitly linked palette roles. The reference JSON above stays unchanged. Editor changes update the playground’s theme/runtime state; some controls persist browser overrides. They do not write to your source JSON file.

Continue to Palette to assign colors to UI roles.

Full spectrum of generated color scales. Click any swatch to adjust the global theme variable.
Usage example: background: color(blue-500)

Interactive Playground

Live Color Preview
ColorUsage.uxdsl
.my-element {
  background-color: color(blue-600);
  color: color(gray-50);
}

Global Palette

Click on any color swatch to update the UX-DSL token.

blue

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

indigo

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

purple

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

pink

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

red

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

orange

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

yellow

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

green

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

teal

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

cyan

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

gray

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

AI implementation guide

How an AI agent should use Colors

UXDSL builds on standard CSS. Colors define the available color values; Palette assigns colors to interface roles. Both are configured in the theme JSON. Prefer palette() when a component expresses a role such as primary action or surface. Use color() when a specific color token is intentional, and standard CSS when finer control is needed.

Responsibility: maintain the foundational color collection. Colors supply values to direct consumers and linked palette roles. Normally, semantic UI components consume Palette rather than selecting Colors directly.

  • Inspect colors and its families, shades and named entries. Treat shade numbers as keys, not calculated brightness or contrast guarantees.
  • Use color(token) directly only when a specific color identity is intentional, such as a swatch representing that token.
  • Before changing a Color value, trace direct color() consumers, CSS variable references and runtime links from Palette. Equal hex values alone do not establish a dependency.
  • Update the base Color only when all its direct and linked consumers are intended to receive the change. If the request concerns a UI role, reassign that Palette role instead.
  • Preserve explicit references from Palette to Colors. Do not replace them with copied hex values when the link should remain active.
  • Reuse existing Color tokens and define any required new token before referencing it. Do not create a duplicate merely to reproduce an existing value.
  • Edit the source JSON or use the supported Color runtime API. Do not hand-edit generated CSS as a second source of truth.
  • Verify direct swatches and linked roles after applying the change. Check active overrides, unrelated tokens and foreground/background pairs affected by the new base value.

Decision rule: Prefer Palette for semantic component styling. Use Colors directly only when a specific color identity is intentional. Modify a Color token only when its direct and linked consumers are intended to receive the change.

Preserve intent, not just the current computed value. A Palette role and a Color token can look identical today while responding differently to tomorrow’s theme changes.

Configuration and usage example

{
  "colors": {
    "blue": { "500": "#3b82f6", "700": "#1d4ed8" },
    "white": "#ffffff",
    "ink": "#0f172a"
  },
  "palette": {
    "primary": {
      "main": "var(--uxdsl__color__blue-700)",
      "contrast": "var(--uxdsl__color__white)"
    },
    "surface": {
      "main": "var(--uxdsl__color__white)",
      "contrast": "var(--uxdsl__color__ink)"
    }
  }
}
/* A swatch intentionally represents this Color token */
.blue-swatch {
  background: color(blue-700);
}

The swatch intentionally consumes blue-700 directly. In the JSON, primary.main also references that Color. Updating the Color changes both; reassigning the Palette role changes its consumers while the swatch keeps representing blue-700.

Agent reasoning example

Update blue-700 across the theme, including palette roles linked to it.
  1. Locate colors.blue["700"], its direct consumers, and palette references to it.
  2. Update the color value in the source JSON, preserving palette references rather than replacing them with copied hex values.
  3. Apply or compile the theme. Confirm that direct swatches and linked roles receive the new value.
  4. Check unrelated color tokens, literal palette values, relevant modes and foreground/background contrast.

Colors define the values. Palette defines their roles. Components express the intended use.