Repository navigation
Description
Context
PR #555 introduced an exploration for a ratio-based type scale system with an interactive prototype. The key insight: instead of maintaining separate type scale systems (default vs editorial), XDS should offer a configurable type scale where products pick their position on the density spectrum via { base, ratio }.
This issue covers the concrete implementation work to bring that exploration into the theme system.
Goals
- Add optional
typeScaletodefineTheme— a single{ base, ratio }that generates all heading and text sizes for the theme - Remove
variantfromXDSHeading— density is a theme-level decision, not a per-component one - Simplify
XDSFontWrapper— becomes a pure prose/typography wrapper, no variant prop
Decisions
No named variants (functional / default / editorial)
Decided after evaluating the API surface trade-off. See #632 for the vibe test that first established density as a region concern, not a component concern.
The original spec proposed three named variants (functional, default, editorial) as a first-class concept — a shared XDSTypeScaleVariant type, variant props on components, and three { base, ratio } configs per theme. After evaluation, we're removing named variants entirely:
- 67% fewer tokens — 33 CSS custom properties instead of 99
- 67% fewer theme override rules — 11 instead of 33
- Zero new component props — we're actually removing
variantfromXDSHeading - Zero new types — no
XDSTypeScaleVariant - One concept instead of five —
typeScalehasbaseandratio, that's it
The named values live in docs as suggested starting points, not as API surface:
- Dense/functional:
{ base: 12, ratio: 1.125 } - Default:
{ base: 14, ratio: 1.2 } - Airy/editorial:
{ base: 16, ratio: 1.25 }
Mixed density via theme nesting, not variant props
For pages that need different density regions (e.g. dense sidebar + airy main content), nest <XDSTheme>:
<XDSTheme theme={adminTheme}>
<XDSTheme theme={denseSidebarTheme}>
<Sidebar />
</XDSTheme>
<MainContent />
</XDSTheme>This uses the same mechanism as brand theming and dark mode — one pattern to learn instead of two.
Remove variant from XDSHeading
variant on XDSHeading (currently supports 'default' | 'editorial') is removed. Since this hasn't shipped to external consumers, there's no migration cost. Density is controlled by the theme's typeScale, scoped via <XDSTheme> nesting.
XDSText never gets variant
Per #632 — density is not a per-component concern. XDSText stays focused on semantic text types (body, large, label, supporting, code).
Default type scale
base: 14, ratio: 1.2, with h4 anchored to base (14px). Headings scale up from h4, h5/h6 scale down.
The formula: size = base × ratio^step, where h4 is step 0.
Headings
| Level | Step | Formula | Size | Line-H | Previous |
|---|---|---|---|---|---|
| h1 | +3 | 14 × 1.2³ | 24px | 32px | 20px |
| h2 | +2 | 14 × 1.2² | 20px | 28px | 18px |
| h3 | +1 | 14 × 1.2¹ | 17px | 24px | 16px |
| h4 | 0 | 14 | 14px | 20px | 14px |
| h5 | −1 | 14 × 1.2⁻¹ | 12px | 16px | 14px |
| h6 | −2 | 14 × 1.2⁻² | 10px | 16px | 12px |
Text types
| Type | Step | Size | Line-H | Previous |
|---|---|---|---|---|
| large | +1 | 17px | 28px | 16px |
| body | 0 | 14px | 24px | 14px |
| label | 0 | 14px | 24px | 14px |
| code | 0 | 14px | 24px | 14px |
| supporting | −1 | 12px | 20px | 12px |
Scale spectrum
24px ← h1
20px ← h2
17px ← h3, large
14px ← h4, body, label, code
12px ← h5, supporting
10px ← h6
Line heights snapped to 4px grid. Heading line-height ratio ~1.3, text line-height ratio ~1.5.
typeScale in defineTheme
API design
const myTheme = defineTheme({
name: 'admin-panel',
typeScale: { base: 14, ratio: 1.2 },
tokens: { ... },
components: { ... }, // explicit overrides still merge on top
});When typeScale is omitted, themes use the hardcoded default values (computed from { base: 14, ratio: 1.2 }). Fully backward compatible.
How it works
defineThemetakes the optionaltypeScaleobject ({ base: number, ratio: number })- h4 is anchored to
base. Headings h1–h3 scale up (base × ratio^1..3), h5–h6 scale down (base × ratio^-1..-2) - Text types: body/label/code at
base, large atbase × ratio, supporting atbase / ratio - Line heights snapped to 4px grid (headings ~1.3× ratio, text ~1.5× ratio)
- Explicit
componentsoverrides deep-merge on top for fine-tuning
Generated tokens
Naming convention:
--heading-{level}-{size|weight|leading}
--text-{type}-{size|weight|leading}
Example output from { base: 14, ratio: 1.2 }:
{
'--heading-1-size': '24px', // 14 × 1.2³
'--heading-1-leading': '32px',
'--heading-2-size': '20px', // 14 × 1.2²
'--heading-2-leading': '28px',
'--heading-3-size': '17px', // 14 × 1.2¹
'--heading-4-size': '14px', // base (anchor)
'--heading-5-size': '12px', // 14 × 1.2⁻¹
'--heading-6-size': '10px', // 14 × 1.2⁻²
// ... weights and leading for each
'--text-body-size': '14px', // base
'--text-large-size': '17px', // 14 × 1.2¹
'--text-supporting-size': '12px', // 14 × 1.2⁻¹
// ... weights and leading for each
}Total: 33 tokens (11 entries × 3 properties).
Prose / FontWrapper coverage
Components and typography.css both reference the same tokens:
/* typography.css */
.xds-typography h1 {
font-size: var(--heading-1-size);
font-weight: var(--heading-1-weight);
line-height: var(--heading-1-leading);
}This guarantees XDSHeading, XDSText, and XDSFontWrapper prose all read from the same source of truth. A theme's typeScale setting flows through to all three automatically.
Implementation notes
typeScaleis syntactic sugar — it generates token overrides, not component CSS (avoids the CSS layer specificity problem)- The computation (
base × ratio^n, rounding, line-height snapping) should be a pureexpandTypeScale()function that's easy to test - Collision handling: enforce 1px minimum step between adjacent sizes (from PR Exploration: Ratio-based type scale system #555's exploration)
- Follows the same pattern as color tokens — theme sets token values, components consume via
var()
Tasks
Type scale computation
- Implement
expandTypeScale({ base, ratio })pure function — h4 anchored to base, sizes + line heights - Add optional
typeScalefield toXDSDefineThemeInput - Implement
typeScaleexpansion indefineTheme(merges into token overrides) - Ensure explicit
componentsoverrides deep-merge on top of generated tokens
Tokens
- Add 33 typography tokens to
tokens.stylex.tswith defaults from{ base: 14, ratio: 1.2 } - Component overrides in default theme reference new tokens (
var(--heading-1-size), etc.) - Component overrides in neutral theme reference new tokens
Component changes
- Remove
variantprop fromXDSHeading(currently'default' | 'editorial') - Remove
variantprop fromXDSFontWrapper(simplify to prose wrapper) - Remove
XDSHeadingVarianttype - Update
XDSHeadingto read sizing from tokens instead of variant-keyed overrides - Update
XDSFontWrapper— remove variant classes (xds-typography--editorial, etc.), single prose class only
typography.css
- Refactor prose rules to reference new tokens (
var(--heading-1-size), etc.) - Remove variant-specific classes (
xds-typography--editorial,xds-typography--default)
Stories & Docs
- Add Storybook story showing
typeScaletheme switching (dense → default → airy) - Add Storybook story showing mixed density via nested
<XDSTheme> - Update docs (Heading.doc.mjs, FontWrapper.doc.mjs, CLI docs)
- Document suggested
{ base, ratio }starting points in theme docs
Tests
- Tests for
expandTypeScale()computation function - Tests for
defineThemetypeScale expansion - Tests for heading rendering with token-based sizing
- Tests for text rendering with token-based sizing
- Tests for FontWrapper prose rendering with token-based sizing
- Tests for mixed density via nested themes
References
- PR Exploration: Ratio-based type scale system #555: Exploration — ratio-based type scale system
- decision: Deprecate variant prop on typography components in favor of region-scoped FontWrapper #632: Vibe test — variant prop vs region-scoped control (established density as a region concern)
- API proposal comment: Token-based approach (proposed named variants, since simplified to single scale)
- CSS layer specificity problem: Why typeScale generates token overrides, not component CSS
- typescale.com — interactive type scale calculator
Activity
cixzhang commentedon Mar 12, 2026
Yeah let's add variant to XDSText, too.
cixzhang commentedon Mar 12, 2026
Typescale API needs to be like this:
All 3 variants are available always. We're defining how each one translates into CSS class overrides.
cixzhang commentedon Mar 12, 2026
Updated the spec based on your feedback:
Text gets
varianttoo — addedvariant?: 'functional' | 'default' | 'editorial'toXDSText, mirroring headings. Included a proposed text scale table and the component changes needed (XDSTextVarianttype, class emission, theme overrides).typeScaleis an object with all 3 variants — changed from a string selector to:All three are always available in every theme. The config just controls what values each one maps to. Explicit
componentsstill deep-merge on top.cixzhang commentedon Mar 12, 2026
Looks good in the latest spec iteration. Make sure that things like
components.headingalso preserves updating the prose HTML elements like h1, etc even with this shortcut form of typescale configuration.cixzhang commentedon Mar 12, 2026
Good catch — added a dedicated section on prose/FontWrapper coverage.
Currently
typography.csshardcodes the heading styles for each variant (.xds-typography--default h1, etc.). ThetypeScaleexpansion needs to generate overrides for these too, not just theXDSHeading/XDSTextcomponent classes.Three options sketched out in the spec (Option A: fontwrapper component key, Option B: refactor to CSS custom properties, Option C: extra rules in
generateThemeCSS). Also added tasks forXDSFontWrapperVariantgetting'functional'and the newxds-typography--functionalclass + styles.cixzhang commentedon Mar 15, 2026
CSS Layer Specificity Problem for Typography Theming
While testing the example apps as external consumers, we discovered a fundamental specificity conflict between theme overrides and component prop overrides that's especially relevant to this issue's design.
The problem
XDS has three levels of styling that need to cascade correctly:
stylex.create) — the defaults@scopeCSS in@layer xds.theme) — theme-level customization<XDSText color="secondary">) — explicit user intent, should always winThe conflict: both #1 and #3 come from StyleX (same CSS priority layers), while #2 is in a separate
@layer xds.theme. For the theme layer to override base styles, it needs higher priority than the StyleX layers. But then prop overrides (also in StyleX layers) can't beat the theme.Example of the bug
A theme defines heading styles in
@layer xds.theme:A consumer uses
<XDSText color="secondary">which applies a StyleX class forcolor: var(--color-text-secondary). But ifxds.themehas higher layer priority than the StyleX priority layers, the theme'snavywins over the prop'ssecondary— the prop has no effect.Which components are affected?
We analyzed which components have props that conflict with theme-overridable properties:
color,weight,typecolorcolorComponents like Button, Badge, Card, Divider use discrete variants where the theme maps 1:1 to the variant — no cross-cutting prop conflicts.
How this affects typeScale design
The
typeScalefeature in this issue would generate theme CSS for all heading levels and text types across three variants (functional, default, editorial). This significantly expands the surface area of the conflict. If the theme definesfont-sizefor.xds-text.body, and a consumer uses<XDSText type="large">, which font-size wins?Possible approaches
A. Higher-level typography tokens instead of component overrides
Instead of themes overriding individual component styles (font-size on
.xds-text.body), themes define typography as a token system — the type scale ratios, base sizes, and weight mappings become tokens. Components reference these tokens via StyleX, so there's no layer conflict. ThetypeScaleshortcut indefineThemewould generate token overrides, not component CSS.This aligns naturally with the ratio-based approach from PR #555 — the theme picks a base size and ratio, and all text/heading sizes derive from tokens.
B. Emit prop-override rules in the theme layer
When a theme overrides
coloron.xds-text.body, the builder also emits.xds-text.secondary { color: var(--color-text-secondary) }in the same theme layer so prop variants still win by specificity/source order. Downside: theme CSS grows, and old themes need rebuilding when new variants are added.C. Restrict what themes can override on typography
Only allow themes to customize typography through tokens (font family, scale, weights) — not through component-level property overrides. If a theme can't set
coloron.xds-text.body, the conflict doesn't exist. Thecolorprop in StyleX always wins because there's nothing in the theme layer competing with it.Recommendation
Option A feels right for typography — the
typeScaledesign in this issue is already heading in that direction. Themes should define the type system at the token level (base, ratio, weight mappings), and the build-theme command translates that into token overrides. Component-level@scopeoverrides would be reserved for truly component-specific visuals (button backgrounds, card borders) where there's no prop-level conflict.cixzhang commentedon Mar 15, 2026
Correction to my previous comment
The recommendation isn't to replace component overrides with raw tokens. The idea is a structured type system definition in
defineThemethat the builder expands into the correct CSS — including prop-level override rules.Example:
The
build-themecommand would then generate the full cascade:The theme author thinks at the type system level — base size, scale ratio, semantic colors. The builder knows the full set of prop variants (primary, secondary, disabled, etc.) and generates the override rules needed for correct specificity. When a new color variant is added to XDSText, the builder automatically includes it in the output.
This solves the layer specificity problem because the prop-level rules live in the same
@layer xds.themeas the base theme overrides, and the builder ensures they're complete. The theme author doesn't manually manage which CSS rules are needed — the structured input guarantees correctness.cixzhang commentedon Mar 15, 2026
Correction on the example
The typeScale values are the actual design values, not CSS variable references:
The builder generates the CSS from these values:
The theme defines the actual colors. The builder expands them into the complete set of component rules with correct specificity.
ernestt commentedon Mar 16, 2026
I think of scale ratio as a early stage guidance value instead of a build time component level overrides. So I think my mental model aligned more with:
ernestt commentedon Mar 16, 2026
API Proposal: Token-Based
typeScaleBuilding on @ernestt's comment about the token-based approach (Option A) — here's a concrete API proposal. The core idea:
typeScalegenerates token overrides, not component CSS. This follows the same pattern XDS already uses for colors (--color-text-primaryis a semantic token over raw color values).Where should
variantlive?The issue spec proposes adding
variantto bothXDSTextandXDSHeading. I'd argue against putting it onXDSText:Density is a product/region decision, not a text decision. A product picks its position on the functional → default → editorial spectrum, and the theme enforces consistency. If individual text components can opt into different variants inline, you get inconsistency by default — developers mixing
functionalheadings andeditorialbody text on the same page with no guardrail. The theme becomes advisory rather than authoritative.It's the wrong abstraction level.
variantcontrols density, which is a layout/region concern. It belongs on something that scopes a subtree —XDSFontWrapperorXDSTheme— not on leaf text components. Putting it on every<XDSText>and<XDSHeading>buries a region-level decision inside individual elements.Prop surface area for a rare use case. Most consumers will never touch
variant— they'll use whatever their theme defines. Adding it toXDSTextmeans every instance carries an option most people shouldn't use.The alternative for mixed density:
XDSFontWrapperalready hasvariantand scopes a region. For the case where a dashboard needs a dense sidebar alongside default-density main content, nesting<XDSFontWrapper variant="functional">around that section is explicit and visible. It says "this region is denser" at the layout level.Backwards compat note:
XDSHeadingalready hasvarianttoday for editorial. We could deprecate it in favor of the region-based approach, but that's a separate migration. The important thing is not extending the pattern toXDSText.New semantic typography tokens
Add a
typeScaleDefaultstoken group totokens.stylex.tswith the naming convention:For example:
This gives us ~90 tokens (3 variants × {6 heading levels + 5 text types} × 3 properties). The defaults reference the existing
--text-*size palette, so out of the box everything resolves to the same values we have today.Components, theme overrides, and
typography.cssreference the new tokensTheme component overrides become thin wrappers over token references:
And
typography.cssdoes the same:This guarantees
XDSHeading,XDSText, andXDSFontWrapperprose all read from the same source of truth.typeScaleindefineTheme— syntactic sugar for token overridesThe
typeScaleshortcut computes concrete values from{ base, ratio }and writes them as token overrides — no component CSS generated:Internally,
defineThemecalls a pureexpandTypeScale()function that generates token overrides:These land in the
:scope {}block alongside color and spacing overrides. Explicitcomponentsoverrides still deep-merge on top for things outside the type scale system (e.g.letterSpacing, custom weight on a single level).Why this solves the specificity problem
The cascade becomes:
--heading-default-1-size: 1.5remvia:scope.xds-heading.level-1 { font-size: var(--heading-default-1-size) }— reads the token<XDSHeading color="secondary">appliescolor: var(--color-text-secondary)No conflict: the theme's type scale influence flows through custom properties. StyleX props control orthogonal properties (color, weight overrides) directly. They never compete over the same declaration in different layers.
This is the same pattern as colors: a theme overrides
--color-accent(token), components referencevar(--color-accent)(consumption), and StyleX handles prop-driven overrides (color="secondary") without specificity fights.Summary of changes
tokens.stylex.tstypeScaleDefaultstokensdefineTheme.tstypeScalefield;expandTypeScale()merges intotokensdefaultTheme.tsvar(--heading-*-*-*)tokenstypography.css--functionalvariant rulesXDSFontWrapper.tsxXDSTypeScaleVariant, addxds-typography--functionalclassXDSHeading.tsx'functional'to existingvariantprop (already has variant for backwards compat)XDSText.tsxvariantprop — density controlled at region level viaXDSFontWrapperXDSTypeScaleVariant = 'functional' | 'default' | 'editorial'XDSTextstays focused on semantic text types (body,label,supporting, etc.) and doesn't take on density variant responsibility. That's the theme andXDSFontWrapper's job.Tradeoffs
Pros:
typography.cssand component overrides read the same tokens — guaranteed consistencytypeScaleis pure syntactic sugar over the existing token system — no new CSS mechanismexpandTypeScale()is a pure, testable functionCons:
--text-base→--heading-default-1-size→ component) — same as colors though (#0064E0→--color-accent→ component)— via Navi on behalf of @ernestt
feat: ratio-based type scale system with typeScale in defineTheme
feat: ratio-based type scale system with typeScale in defineTheme (#638)
feat: ratio-based type scale system with typeScale in defineTheme (#638)
feat: ratio-based type scale system with typeScale in defineTheme (#638)
feat: ratio-based type scale system with typeScale in defineTheme (#638)