In Uno.Themes, spacing and density are orthogonal axes that compose to determine the effective base spacing unit. Instead of density being a fixed value, it acts as a multiplier (mode) applied to a base spacing value.
The Composition Formula
Effective Base = DefaultSpacing × Density factor
1. DefaultSpacing
DefaultSpacing is a Dependency Property (DP) on BaseTheme. It defines the base unit for the Space* scale.
- Default value:
4. - Validation: Non-finite (NaN, Infinity) or negative values automatically degrade to the default base of
4 to prevent poisoning the scale.
2. Density (Mode)
Density is a mode that scales the DefaultSpacing. It does not have its own underlying base-unit values.
- Compact: Multiplier of
0.75 - Regular: Multiplier of
1 - Comfy: Multiplier of
1.25 - Undefined/Other: Multiplier of
1
Example Composition
If DefaultSpacing is set to 6:
- Compact: $6 imes 0.75 = 4.5$
- Regular: $6 imes 1 = 6$
- Comfy: $6 imes 1.25 = 7.5$
Invariant Tokens
Certain tokens are fixed and do not change regardless of DefaultSpacing or Density settings:
ControlHeight*IconSize*TouchTargetMinSize- Shape tokens (e.g.,
CornerRadius) are also unaffected by DefaultSpacing.