UX-DSL
XS0px

Densities

Define responsive spacing once. Keep every connected component in rhythm.

Spacing defines a value; Density defines how spacing responds to the viewport. Prefer density(n) for component spacing using the theme’s responsive mapping. Use space(n) directly when a stable value across breakpoints is intentional. Changing that mapping updates every consumer of the token without changing component code.

  1. Define how a spacing token changes across breakpoints in your theme JSON.
  2. Use that Density token wherever components should share the same responsive spacing.
  3. Edit one mapping below and watch both connected boxes update together.

Density is the recommended default for component spacing. Standard CSS remains available when finer control is needed. The generated media queries belong to the system; they are not removed from CSS.

One token. Responsive spacing everywhere.

UXDSL builds on standard CSS. Spacing defines the base spacing values, and Density makes that spacing responsive. Prefer Density for component spacing, use Spacing when a stable value is intentional, and use CSS directly when finer control is needed. This is the recommended authoring approach, not a compiler restriction.

A Density token maps a level to spacing values at different breakpoints. The 4 in density(4) identifies a token; it does not mean four pixels or a multiplier. You define its progression.

1. Define the behavior in your theme JSON

This example is a theme excerpt. Density reuses the spacing scale instead of introducing a separate set of measurements.

{
  "breakpoints": { "xs": 0, "md": 768, "xl": 1280 },
  "spacing": {
    "4": "0.75rem",
    "5": "1rem",
    "6": "1.5rem"
  },
  "densities": {
    "4": "xs(space(4)) md(space(5)) xl(space(6))"
  }
}
How this example resolves at each viewport width
Viewportdensity(4)space(4)
Below 768pxspace(4) → 0.75rem0.75rem
768–1279pxspace(5) → 1rem0.75rem
1280px and abovespace(6) → 1.5rem0.75rem

A rule remains active until another defined breakpoint overrides it. The progression is configurable: spacing can increase, decrease or stay the same.

2. Use it in your components

UXDSL you write
.card, .panel {
  padding: density(4);
}

The card and panel choose a token. Its responsive behavior lives in the theme.

Equivalent plain CSS
/* Base spacing tokens from the theme */
:root {
  --uxdsl__space__4: 0.75rem;
  --uxdsl__space__5: 1rem;
  --uxdsl__space__6: 1.5rem;
  --uxdsl__density__4: var(--uxdsl__space__4);
}

@media (min-width: 768px) {
  :root { --uxdsl__density__4: var(--uxdsl__space__5); }
}

@media (min-width: 1280px) {
  :root { --uxdsl__density__4: var(--uxdsl__space__6); }
}

.card, .panel {
  padding: var(--uxdsl__density__4);
}

You can build this same behavior in plain CSS using responsive custom properties. UXDSL generates those rules from the theme, so you maintain one mapping instead of repeating breakpoint decisions in each component. Less repeated source code does not necessarily mean less generated CSS.

3. Change one token. Update both boxes.

These live boxes use this page’s current theme and actual browser viewport. The colored area is padding. Edit the active rule for Density 4 to see both responsive boxes change; the fixed box continues to use space(4).

Live density(4): xs(space(4)) md(space(5)) xl(space(6))

Cardpadding: density(4)
Content
Panelpadding: density(4)
Content
Fixed spacingpadding: space(4)
Content

Resize your browser to see the responsive boxes follow the mapping. The JSON and CSS above remain a reference example; the live definition shows your edits. Edits are a local demo and are not saved to your theme file.

Two ways to update the system: change a spacing value to update every reference to that spacing token, or change a Density mapping to update every consumer of that Density token. Component declarations stay the same.

Prefer density() for component spacing. Use space() directly for an intentional stable value, or CSS for finer control. A Spacing value remains editable through the theme. Density coordinates spacing; layout changes such as columns and navigation still need their own responsive decisions.

Russian Doll Visualization

Each ring compares a Density level measured from the same content. The rings are not nested component paddings added together. Click a ring to edit its token. This diagram responds to the main browser viewport.

Content
density(1)
density(2)
density(3)
density(4)
DensityUsage.uxdsl
.any-class {
  padding: density(4);
}

Global Density Tokens

Update the tokens below to reflect changes in the UI.

density(1)
xs:space(1)
md:space(2)
xl:space(3)
xs
md
xl
density(2)
xs:space(2)
md:space(3)
xl:space(4)
xs
md
xl
density(3)
xs:space(3)
md:space(4)
xl:space(5)
xs
md
xl
density(4)
xs:space(4)
md:space(5)
xl:space(6)
xs
md
xl
density(5)
xs:space(5)
md:space(6)
xl:space(7)
xs
md
xl
density(6)
xs:space(6)
md:space(7)
xl:space(8)
xs
md
xl
density(7)
xs:space(7)
md:space(8)
xl:space(9)
xs
md
xl
density(8)
xs:space(8)
md:space(9)
xl:space(10)
xs
md
xl
density(9)
xs:space(9)
md:space(10)
xl:space(11)
xs
md
xl
density(10)
xs:space(10)
md:space(11)
xl:space(12)
xs
md
xl
density(11)
xs:space(11)
md:space(12)
xl:space(13)
xs
md
xl
density(12)
xs:space(12)
md:space(13)
xl:space(14)
xs
md
xl
density(13)
xs:space(13)
md:space(14)
xl:space(15)
xs
md
xl
density(14)
xs:space(14)
md:space(15)
xl:space(16)
xs
md
xl

AI implementation guide

How an AI agent should use Density

UXDSL builds on standard CSS. Spacing defines the base spacing values, and Density makes that spacing responsive. Prefer Density for component spacing, use Spacing when a stable value is intentional, and use CSS directly when finer control is needed. This is the recommended authoring approach, not a compiler restriction.

When generating or modifying UI with UXDSL:

  • Read the theme's spacing, densities, and breakpoints definitions before selecting spacing tokens.
  • Prefer existing design-system tokens over introducing new values, tokens, or responsive rules.
  • Prefer an appropriate density(n) token by default for component spacing.
  • Use space(n) directly when a stable value across breakpoints is intentional. Use CSS directly when finer control outside the configured Density behavior is required.
  • Do not replace Density with Spacing merely because their values match at one breakpoint. That would discard the intended responsive progression.
  • If no Density token fits, inspect the theme and requested scope before creating a system-level token or choosing a deliberate local exception. Never reference an undefined token.
  • Treat density(n) as a reference to a configured responsive spacing token. Never assume density(4) equals space(4) at every breakpoint.
  • Reuse existing Density tokens when their configured progression matches the intended behavior.
  • Do not reference undefined Density or Spacing tokens. When a new token is needed, define it in the theme before using it.
  • Do not reproduce a Density mapping locally with explicit breakpoint rules when an existing Density token already represents the intended behavior.
  • Change a Density mapping in the theme when the intended change should affect all consumers of that token.
  • Use a local component rule when the behavior is an intentional exception that should not affect the Density token or its other consumers.
  • Before creating a new Density token, check whether an existing token already provides the required responsive progression.
  • Verify the result just below, at, and just above each configured breakpoint where those widths are valid, and check other components consuming the same Density token.

Decision rule: Prefer Density for component spacing. Use Spacing for intentional stable values and CSS for finer control. Change shared Spacing or Density definitions only for intentional system-level changes.

Choose the token in the component. Define its responsive behavior in the theme.

Example

Given this example theme excerpt:

{
  "breakpoints": {
    "xs": 0,
    "md": 768,
    "xl": 1280
  },
  "spacing": {
    "4": "0.75rem",
    "5": "1rem",
    "6": "1.5rem"
  },
  "densities": {
    "4": "xs(space(4)) md(space(5)) xl(space(6))"
  }
}

When a component should follow that configured responsive progression, prefer:

.card {
  padding: density(4);
}

This resolves according to the theme:

  • Below 768px → space(4) → 0.75rem.
  • From 768px up to, but not including, 1280px → space(5) → 1rem.
  • 1280px and above → space(6) → 1.5rem.

Avoid recreating the same system behavior locally:

.card {
  padding: xs(space(4)) md(space(5)) xl(space(6));
}

The local form duplicates behavior already represented by density(4) and disconnects the component from future changes to that Density mapping. It still references the spacing scale.

Explicit local responsive spacing is valid when the component intentionally requires behavior that should remain independent from the configured Density mapping.

Agent reasoning example

If asked:

Make this card's padding follow the application's responsive spacing.

The agent should:

  1. Inspect the theme's available Density tokens.
  2. Find an existing Density progression that matches the requested behavior.
  3. Use that token in the component, for example padding: density(4).
  4. Avoid generating local breakpoint rules that duplicate the token's progression.
  5. Only create or modify a Density token when the requested behavior belongs at the design-system level.
  6. Verify the resulting behavior around every configured breakpoint and check affected consumers when the Density mapping changes.

The component declares which responsive spacing token it uses.

The theme defines how that token behaves across breakpoints.