Repository navigation
Description
Summary
XDS needs a density system that controls component heights and spacing across three levels: compact, balanced (default), and spacious. Density should be:
- Nestable — via an
<XDSDensity>provider using CSS custom properties - Theme-level — configurable via
defineTheme(future phase)
Design Principles
- Density shifts heights and spacing, not typography or icons
- Each density has 3 sizes (
sm | md | lg) — density shifts the entire scale ±4px - Internal components (buttons inside inputs, action buttons) are always standard height − 8px
- Radio/checkbox indicators stay fixed at 20px across all densities
Height Matrix
Standard Heights (Buttons, Inputs, List Items, Token Chips, Nav Items)
| sm | md | lg | |
|---|---|---|---|
| Compact | 24px | 28px | 32px |
| Balanced | 28px | 32px | 36px |
| Spacious | 32px | 36px | 40px |
Internal Heights (Tokenizer Clear Btn, List Item Action Btns)
Standard − 8px.
| sm | md | lg | |
|---|---|---|---|
| Compact | 16px | 20px | 24px |
| Balanced | 20px | 24px | 28px |
| Spacious | 24px | 28px | 32px |
Components in Scope
Tier 1 — Core (confirmed)
- Button — keeps
sm | md | lgsize prop; density shifts what they resolve to - TextInput — standard height, internal clear button at internal height
- List / ListItem — standard row height, internal action buttons
- Token — same height as internal buttons
- Tokenizer — container with 4px padding/gap (all densities), contains tokens + clear button
- Internal buttons — clear button in tokenizer, action buttons in list items
- Nav items (TopNav, SideNav, MobileNav) — follows list item pattern
- Radio / Checkbox — row height from density, indicator fixed at 20px
Tier 2 — Should follow (composites of Tier 1 patterns)
These are built from inputs and list items, so they should inherit density naturally:
- Selector — dropdown trigger = input height
- DropdownMenu — menu items = list item pattern
- Typeahead — input + dropdown list
- DateInput / TimeInput / NumberInput — input variants
- TextArea — min-height may follow density
- TabList — tab items have a height
- Breadcrumbs — clickable items with a height
- Table — already has density concept (
compact | balanced | spacious) - PowerSearch — input-like component
- Pagination — button-like controls
- Banner — has close button, padding
Not affected
AspectRatio, Card, Center, Collapsible, Dialog, Divider, EmptyState, Field, FormLayout, Grid, HoverCard, Icon, Kbd, Layer, Layout, Link, Popover, ProgressBar, Section, Skeleton, Slider, Spinner, Stack, StatusDot, Text, Tooltip, Avatar, Badge
Spacing Tokens (balanced / md baseline)
| Token | Compact | Balanced | Spacious |
|---|---|---|---|
--density-padding-block |
4px | 6px | 8px |
--density-padding-inline |
8px | 8px | 8px |
--density-token-padding-inline |
4px | 8px | 8px |
--density-token-padding-block |
4px | 2px | 4px |
--density-token-gap |
4px | 4px | 4px |
Note: Spacing values need further refinement for how they scale across sizes within a density.
What Changes with Density
- Heights (two tiers, ±4px per density level)
- Padding / gap values
What Does NOT Change
- Icon sizes (16px dismiss icon stays 16px)
- Font sizes
- Line heights
- Radio/checkbox indicator size (20px)
Architecture
Provider (Phase 1)
// Nestable — set at root or per-section
<XDSDensity density="compact">
<Sidebar />
</XDSDensity>
<XDSDensity density="spacious">
<MainContent />
</XDSDensity>The provider sets CSS custom properties on a wrapper element. Components read density tokens via StyleX. No React context needed for the values — CSS cascade handles nesting.
Theme Integration (Phase 2)
const myTheme = defineTheme({
name: "my-app",
density: "compact", // sets default density for the theme
tokens: { ... },
});Naming
- Density levels:
compact | balanced | spacious(matches existing List/Table naming) balancedis the default- Size prop:
sm | md | lg(unchanged)
Migration Notes
- Existing List density prop (
compact | balanced | spacious) should migrate to use the global density system - Existing Table density should migrate similarly
- Button
sizeprop stays but resolves to different pixel values based on density context
Open Questions
- Should spacing values also scale per size within a density, or only per density level?
- Token chip padding: balanced has 2px vertical (lower than compact's 4px) — intentional visual tradeoff?
- Should
--density-padding-inlineand--density-token-gapbe density tokens if they don't change across densities?
Activity
rubyycheung commentedon Mar 24, 2026
Design Review Notes
What works well
Concerns to address
1. Spacing tokens lack the same rigor as heights
The height system is perfectly systematic (±4px, −8px for internal). But spacing values are ad-hoc:
--density-padding-block: 4 → 6 → 8 (2px steps ✓)--density-token-padding-inline: 4 → 8 → 8 (jumps, then flat)--density-token-padding-block: 4 → 2 → 4 (goes down from compact to balanced)There's no single rule governing spacing the way there is for heights. This means every new component needs a bespoke spacing spec rather than deriving values from a formula. Should we find a systematic rule for spacing too?
2. Is spacious density earning its keep?
size="lg"within balanced densityWorth pressure-testing with real use cases before committing to three levels. Two levels (compact + balanced) with a size prop might cover 95% of needs.
3. Compact/sm internal button may be too small
The compact/sm internal button is 16×16px — a 16px icon with zero padding. That's:
Recommendation: Consider a minimum internal size of 20px, or accept that compact/sm is a desktop-only density.
4. Cascade order with theme component overrides
If a theme uses
components.button.baseto override padding, and density also controls padding via CSS custom properties — which wins? The specificity/cascade order needs to be explicitly defined.Options:
!importantor higher specificityThis needs a clear answer before implementation.
rubyycheung commentedon Mar 24, 2026
Competitive Analysis: How Other Design Systems Handle Density
Material Design (Google)
Why this way: Optimized for data-dense enterprise UIs (Gmail, Sheets, Cloud Console). Default is already generous enough that "spacious" wasn't needed.
Carbon (IBM)
sizeprop per componentWhy this way: IBM prioritizes accessibility and large touch targets. Two sizes keeps decision-making simple. They decided three levels wasn't worth the complexity.
Fluent UI (Microsoft)
Why this way: Microsoft's product range (Teams, Office, Azure Portal) is so broad that a global density would be too opinionated.
Ant Design (Alibaba)
componentSizeviaConfigProvider—small | middle | largeWhy this way: Heavily used in Chinese enterprise apps where data density varies between admin panels and public forms. Global + nestable was necessary.
This is the closest existing system to what we're proposing.
Chakra UI
sizeprop per component (xs | sm | md | lg)Atlassian Design System
isCompactboolean on specific components (tables, lists)Comparison Matrix
What XDS Does Differently
The density × size matrix is unique. No major design system treats density and size as independent axes. Everyone else has sizes OR density, but not both.
Why other systems don't do this:
Why XDS might be right to do this:
Honest Assessment of Bias in This Analysis
A few things to flag:
Memory-based, not verified. These comparisons are from knowledge of the systems, not freshly checked against current docs. Pixel values and recent feature additions should be verified.
Survivorship bias. Saying "no one does density × size" could be misleading — systems that tried it successfully might not talk about it because it just works. Less visible design systems may have solved this.
Framing bias. The matrix can be framed as "the risk" (complexity) or "the innovation" (expressiveness). The ±4px derivability genuinely makes it simpler than a 9-value lookup table, which tilts toward "innovation."
Missing voices. This analysis would benefit from:
Questions This Raises
cixzhang commentedon Mar 24, 2026
Great RFC and really thorough review, Ruby. The competitive analysis especially — having that honest comparison matrix with bias flags is exactly the kind of rigor we need before committing to new abstractions.
We're not ready for a DensityProvider. Your own research confirms it: no major system combines density × size as independent axes. Our current architecture — component
sizeprops + theme tokens + nested<XDSTheme>— already covers the use cases people actually have. Table and List already ship density props and they work. Adding a new provider increases API surface and cognitive load for uncertain gain.The real problem is semantic spacing relationships. Here's a concrete example: concentric radius. When a container has
border-radius: 12px, nested elements needborder-radius: 12px - gapto maintain visual harmony. This means radius and spacing tokens need shared semantics — they need to be paired and computed together. Generic "compact/balanced/spacious" presets don't solve this because they don't encode the relationships between values, just the values themselves.@rubyycheung — next step: Before we design a spacing system, we need the problem space mapped. Can you research concrete cases where spacing variables need to relate to other variables (radius, padding, margins, line-height, etc.)? Outline specific visual problems and how semantic tokens would solve them. The density RFC might be one chapter in a larger spacing semantics story, but we need to understand what we're actually solving first.
What we're keeping from this RFC:
— drafted with Navi
cixzhang commentedon Mar 24, 2026
Follow-up thought on the architecture:
What if density is just a prop on
<XDSTheme>instead of a new provider?The idea:
<XDSTheme density="compact">without athemeprop doesn't create a new theme — it adjusts the size/spacing tokens of whatever theme is already active above it. A modifier layer, not a new context.This gets us:
size="sm"for surgical overridesUnder the hood,
density="compact"maps to tighter--size-*and--spacing-*token values applied on top of the inherited theme. The ±4px rule from your RFC could be the basis for those adjustments.This avoids the 3×3 matrix complexity while still solving the core use case: "same theme, different density" at any scope level.
Still interested in the semantic spacing research (concentric radius etc.) as a separate thread — that might inform what tokens density actually adjusts.
— drafted with Navi
cixzhang commentedon Mar 24, 2026
Spacing audit findings — sharing what we found searching the codebase for semantic spacing relationships.
The density pattern already exists
List and Table have identical density styles. The step is exactly +1 on the spacing scale:
And the "balanced" row matches what Button, Selector, TopNavItem, and TopNavMenu already use as their defaults. So our current default spacing IS balanced density — we just don't name it.
TextInput's tighter padding (block=spacing-1, inline=spacing-2) is effectively "compact" already.
Size and spacing are independent
size(sm/md/lg) controls component height via--size-sm: 28px,--size-md: 32px,--size-lg: 36px. Spacing (padding/gap) is a separate axis. You could have asize="lg"button with compact padding. The codebase already treats them independently — no component derives its padding from its height.This means the 3×3 density×size matrix from the RFC conflates two independent axes. Density should adjust spacing tokens; size props stay as-is.
Concentric radius — real fragility found
Tokenizer (line 163) and Typeahead (line 133) both have hardcoded concentric-radius math:
This breaks when themes change radii. The brutalist theme sets all radii to 0px but this padding stays at 3px — the tokens should sit flush with sharp corners but they don't.
Proposal: A derived token like
--spacing-concentric-inset: calc(var(--radius-element) - var(--radius-content))would make this respond to theme changes automatically.Theme override fragility
The neutral theme overrides internal CSS variable names to adjust container padding:
These internal variable names (
--layout-padding-inner-x, etc.) aren't part of the token system. If core renames them, themes break silently. We need a formal--spacing-containertoken that themes can override without knowing implementation details.What this means for the density proposal
--density-padding-blockdefaulting to--spacing-2(balanced).density="compact"on XDSTheme shifts down 1 step.sizeprops don't change with density.Open question: should density tokens be universal (all components shift the same) or component-aware (each component has its own baseline that shifts)?
— drafted with Navi
rubyycheung commentedon Mar 26, 2026
Worth noting: XDSSpinner sizes are aligned with XDSIcon sizes, not button/input sizes.
smsm= 16px ✅mdmd= 20px ✅lglg= 24px ✅This makes sense — spinners typically replace icons inline (e.g. inside a button's icon slot during loading). When thinking about density tiers, spinner sizes should scale with icon sizes rather than component sizes (buttons at 28/32/36px, inputs at 28/32/36px).
rubyycheung commentedon Mar 26, 2026
Checkbox and Radio controls should be a single size: 20×20px.
Currently OSS has two sizes for checkbox (
sm: 20px,md: 24px) and radio may have similar. We're standardizing to a single 20×20px control size for both checkbox and radio. Themd(24px) size should be removed.This is a design decision, not a density system concern — the control size is fixed regardless of density tier.
rubyycheung commentedon Mar 26, 2026
ProgressBar: consider reducing to a single default size.
Currently OSS has 3 named sizes (
sm: 4px,md: 8px,lg: 12px). WWW's XDSMeter has no named sizes — just a default withxstylefor overrides.After reviewing use cases (file imports, dashboards, tables, onboarding, quota indicators), nearly all of them use the default size. The only case for a thinner bar is inside table cells, which is rare enough to handle via
xstylerather than a named size.Recommendation: single default size (8px) +
xstyleescape hatch. Removesmandlgnamed sizes to simplify the API.rubyycheung commentedon Mar 26, 2026
Banner content padding should align with inputs/list items for visual alignment.
When a banner sits above or between form fields or list items, the banner text should start at the same horizontal position as the input/list content. This means the banner's left/right content padding should match the container's content padding so text sits on the same visual line.
Example: in a card with a banner above form fields, the banner title "Get $20 for completing a survey" and the input labels below it should left-align. Currently the banner has its own padding (16px inline) which may not match the parent container's content alignment.
This is a density/layout concern — the banner's inner padding should be aware of the context it sits in, or use a shared content padding token.
test(ui): pin the DOM half of the rhythm contract
test(ui): pin the DOM half of the rhythm contract
fix(ui): restore the transcript's markdown rhythm (#2348)
cixzhang commentedon Sep 2, 2026
Thank you for this RFC and the competitive analysis—the careful caveats helped settle the question. Closing because the direction in this thread was not to add a density provider, but to pursue semantic spacing relationships instead; that follow-up landed through #846 and is now recorded in the repository architecture. Component size props plus the existing List and Table density props remain the supported path. A provider can be reconsidered through a newly scoped proposal if new evidence changes that tradeoff.