Skip to content

RFC: Density System — Theme-level + Nestable Density Provider #839

Closed

Description

@rubyycheung

Summary

XDS needs a density system that controls component heights and spacing across three levels: compact, balanced (default), and spacious. Density should be:

  1. Nestable — via an <XDSDensity> provider using CSS custom properties
  2. 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)

  1. Button — keeps sm | md | lg size prop; density shifts what they resolve to
  2. TextInput — standard height, internal clear button at internal height
  3. List / ListItem — standard row height, internal action buttons
  4. Token — same height as internal buttons
  5. Tokenizer — container with 4px padding/gap (all densities), contains tokens + clear button
  6. Internal buttons — clear button in tokenizer, action buttons in list items
  7. Nav items (TopNav, SideNav, MobileNav) — follows list item pattern
  8. 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)
  • balanced is 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 size prop 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-inline and --density-token-gap be density tokens if they don't change across densities?

Activity

  1. added
    enhancement
    on Mar 24, 2026
  2. rubyycheung commented on Mar 24, 2026

    @rubyycheung
    ContributorAuthor

    Design Review Notes

    What works well

    • Two-tier height system (standard / internal with consistent −8px) is elegant and easy to reason about
    • ±4px density shift is perfectly systematic — easy to explain, implement, and extend
    • Density × size matrix preserves flexibility — consumers can still pick sm/md/lg within a density
    • Fixed elements (icons, fonts, radio/checkbox indicator) cleanly separate what scales from what doesn't
    • Nestable provider is the right architecture — theme-level is just the degenerate case

    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?

    • Compact has an obvious use case: data-dense UIs, admin panels, power-user tools
    • Balanced is the default
    • Spacious — when would someone choose this over balanced? If the answer is "forms" or "marketing pages," those might be better served by size="lg" within balanced density

    Worth 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:

    • Below the 24×24 WCAG recommended minimum touch target
    • Hard to tap on mobile, hard to click precisely on desktop
    • The smallest interactive element in the entire system

    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.base to override padding, and density also controls padding via CSS custom properties — which wins? The specificity/cascade order needs to be explicitly defined.

    Options:

    • Density tokens are lower priority (theme overrides win)
    • Density tokens are higher priority (density always controls spacing)
    • Density tokens are the default and theme overrides use !important or higher specificity

    This needs a clear answer before implementation.

  3. rubyycheung commented on Mar 24, 2026

    @rubyycheung
    ContributorAuthor

    Competitive Analysis: How Other Design Systems Handle Density

    Caveat: This analysis is based on knowledge of these systems as of early 2026. Exact pixel values and recent updates should be verified against current docs. Links to source material included where possible for verification.

    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)

    • Approach: Two sizes — default (48px) and small (32px)
    • Levels: 2
    • Global provider: No — size prop per component
    • Note: Their default (48px) is much larger than most systems — accessibility-first

    Why 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)

    • Approach: Three sizes — small, medium, large — per component prop
    • Levels: 3
    • Global provider: No — per-component prop
    • Note: Size values vary per component (not a universal scale)

    Why this way: Microsoft's product range (Teams, Office, Azure Portal) is so broad that a global density would be too opinionated.

    ⚠️ Verify: Fluent ships fast — they may have added provider-based density recently.

    Ant Design (Alibaba)

    Why 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

    • Approach: size prop per component (xs | sm | md | lg)
    • Levels: 4
    • Global provider: No
    • Note: General-purpose library, not enterprise-focused

    Atlassian Design System

    • Approach: Spacing tokens + isCompact boolean on specific components (tables, lists)
    • Levels: 2 (boolean)
    • Global provider: No — ad-hoc per component
    • Note: Density is inconsistent across their ecosystem (Jira vs Confluence)

    ⚠️ Verify: Atlassian may have formalized this since. Also worth checking Radix Themes and Shadcn for newer approaches.


    Comparison Matrix

    System Levels Global Provider Nestable Size × Density Goes Spacious
    Material 4 No No No No (denser only)
    Carbon 2 No No No No
    Fluent 3 No No No No
    Ant Design 3 Yes Yes No Yes (large)
    Chakra 4 No No No Yes (lg/xl)
    Atlassian 2 No No No No
    XDS (proposed) 3 Yes Yes Yes Yes

    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:

    1. Complexity — 3×3 = 9 possible height values to test/maintain per component
    2. Diminishing returns — most teams find 2-3 fixed sizes sufficient
    3. Cognitive overhead — developers learn two concepts instead of one
    4. Testing surface — every component needs testing at each density × size combination

    Why XDS might be right to do this:

    1. XDS serves multiple deployment contexts (OSS, Nest, WWW) with different density needs
    2. The ±4px / −8px rules are derivable — the matrix is a formula, not 9 memorized values
    3. Real use case: compact sidebar with a large primary action button — size-only or density-only can't solve this cleanly
    4. The system is genuinely simple to explain: "density shifts everything ±4px, internal is always −8px"

    Honest Assessment of Bias in This Analysis

    A few things to flag:

    1. 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.

    2. 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.

    3. 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."

    4. Missing voices. This analysis would benefit from:

      • Verified sources for each system's current state
      • Input from teams who've built density systems about what they regret
      • Real XDS consumer research to validate whether the matrix solves actual problems

    Questions This Raises

    • Is the density × size matrix solving a real problem our consumers have, or is it theoretical?
    • Should we look at how Radix Themes, Shadcn, or other newer systems handle this?
    • Would shipping density-only first (3 levels, single default size) and adding the size axis later be a safer path?
    • Can we talk to any teams using Ant's ConfigProvider density to learn what works/doesn't at scale?
  4. cixzhang commented on Mar 24, 2026

    @cixzhang
    Contributor

    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 size props + 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 need border-radius: 12px - gap to 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:

    • The ±4px height rule is elegant and derivable — that's good design
    • Table/List density props are already shipping and working
    • Density as a theme-level concern (not a new provider) aligns with our architecture

    — drafted with Navi

  5. cixzhang commented on Mar 24, 2026

    @cixzhang
    Contributor

    Follow-up thought on the architecture:

    What if density is just a prop on <XDSTheme> instead of a new provider?

    // App-wide: neutral theme, compact density
    <XDSTheme theme={neutralTheme} density="compact">
      <App />
    </XDSTheme>
    
    // Zone-level: inherit parent theme, just tighten spacing
    <XDSTheme density="compact">
      <Sidebar />
    </XDSTheme>

    The idea: <XDSTheme density="compact"> without a theme prop 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:

    • No new provider to learn — density lives where theme decisions already live
    • Composes with any theme — default but denser, neutral but more spacious
    • Nests naturally — same nesting behavior XDSTheme already has
    • Per-component size still works — size="sm" for surgical overrides

    Under 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

  6. cixzhang commented on Mar 24, 2026

    @cixzhang
    Contributor

    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:

    compact:  paddingBlock=spacing-1 (4px), paddingInline=spacing-2 (8px),  font=text-xsm
    balanced: paddingBlock=spacing-2 (8px), paddingInline=spacing-3 (12px), font=text-sm
    spacious: paddingBlock=spacing-3 (12px), paddingInline=spacing-4 (16px), font=text-base
    

    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 a size="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:

    // XDSTokenizer.tsx — the comment explains the geometry:
    // inner-radius sits concentric with outer-radius when
    // inset = radius-element - radius-content - border = 8 - 4 - 1 = 3px
    paddingBlock: `calc(${spacingVars['--spacing-1']} - 1px)`,  // hardcoded to 3px

    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:

    // neutralTheme.ts — reaches into implementation details
    card: {
      base: {
        '--layout-padding-inner-x': 'var(--spacing-3)',
        '--layout-padding-inner-y': 'var(--spacing-3)',
        // ...4 more internal variables
      },
    },

    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-container token that themes can override without knowing implementation details.

    What this means for the density proposal

    1. Density tokens should be spacing tokens — something like --density-padding-block defaulting to --spacing-2 (balanced). density="compact" on XDSTheme shifts down 1 step.
    2. Size stays independent — component size props don't change with density.
    3. Concentric radius needs a derived token — radius and spacing relationships should be encoded, not hardcoded.
    4. Container padding needs a formal token — themes shouldn't override internal variable names.
    5. The +1 step pattern is clean and systematic — worth encoding formally.

    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

  7. rubyycheung commented on Mar 26, 2026

    @rubyycheung
    ContributorAuthor

    Worth noting: XDSSpinner sizes are aligned with XDSIcon sizes, not button/input sizes.

    Spinner Total rendered Icon size match
    sm 16px sm = 16px ✅
    md 20px md = 20px ✅
    lg 24px lg = 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).

  8. rubyycheung commented on Mar 26, 2026

    @rubyycheung
    ContributorAuthor

    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. The md (24px) size should be removed.

    This is a design decision, not a density system concern — the control size is fixed regardless of density tier.

  9. rubyycheung commented on Mar 26, 2026

    @rubyycheung
    ContributorAuthor

    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 with xstyle for 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 xstyle rather than a named size.

    Recommendation: single default size (8px) + xstyle escape hatch. Remove sm and lg named sizes to simplify the API.

  10. rubyycheung commented on Mar 26, 2026

    @rubyycheung
    ContributorAuthor

    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.

  11. cixzhang commented on Sep 2, 2026

    @cixzhang
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions