Repository navigation
Description
What's the problem?
Material UI components ship the comfortable Material Design spacing. Teams building data-dense, professional UIs (dashboards, admin consoles, design tools) routinely need denser layouts — and some need roomier ones.
There's an existing Density page, but it's a per-component workaround, not a density system:
- No single mechanism. It's a grab-bag of
defaultProps—size: 'small'on Button,dense: trueon ListItem,variant: 'dense'on Toolbar,margin: 'dense'on inputs — a different prop per component. - Only 13 components. Button, Fab, FilledInput, FormControl, FormHelperText, IconButton, InputBase, InputLabel, ListItem, OutlinedInput, Table, TextField, Toolbar — nothing else.
- One step, one direction. A single "denser" toggle; no tunable scale, no roomier direction.
- Not holistic — by its own warning. The page states "you should not apply this theme to your whole application," so it can't be the app-wide density dial teams actually want.
Beyond that page, the only levers are styleOverrides and sx calc — re-deriving every component's internal pixel math by hand, per size. There is no single, predictable knob.
Even at the defaults, control sizes don't line up. A "medium" form row mixes a 36.5px Button, a 56px outlined TextField, a 40px IconButton and a 42px Checkbox hit area; the same control shifts height across variants (a standard-variant input box is ~32px vs 56px outlined/filled). The defaults are per-component pixel math, not a shared scale — nothing a theme can turn aligns them.
Material 3 itself documents spacing as a deliberate, adjustable system — compact vs. comfortable off one consistent scale (Applying spacing). A Material UI app can't express that today without forking component source.
This RFC proposes one built-in, opt-in enhancer — enhanceDensity(theme, scale?). The library ships one canonical scale; denser and roomier are userland recipes. An unconfigured app renders today's exact pixels (Argos zero-diff) and ships no extra CSS variables.
What are the requirements?
- Non-breaking, minimal cost when unused. An unconfigured theme is pixel-identical to today (Argos zero-diff) for every
(variant, size)cell, and emits no extra vars. - Theme configurable. Density is set at the theme level — no per-component editing, no
calcfor the consumer — and rides the existing theme tokens (theme.spacing,shape.borderRadius,theme.typography) instead of minting parallel ones. - Coherent size. Spacing, sizing and (for components with a size-carrying prop) font/icon size reflow together — denser padding never pairs with full-size text — and control heights align across components.
Proposed solution
One public entry. enhanceDensity re-authors the whole component library onto one shared scale so sizing stays consistent across components. This is not proportional shrinking: each component maps its own dimensions to the scale's steps, and anchor controls converge on a dedicated touchTarget value, icon size via iconSize, so the misaligned defaults above line up by construction.
import { createTheme, enhanceDensity } from '@mui/material/styles';
// Pixel-identical to today — nothing applied.
const theme = createTheme({ cssVariables: true });
// enhancer standardize every components with a dedicated scale
const enhanced = enhanceDensity(createTheme({ cssVariables: true }));There are deliberately no built-in density modes. An earlier draft of this RFC proposed a 'high' | 'medium' | 'low' mode argument. That was dropped: the modes shared all their code, and a mode enum forces the library to own three sets of design values that properly belong to a product. Denser and roomier ship as documented copy-paste recipes instead.
The scale
| Key | Default | Kind |
|---|---|---|
xxSmall … xxLarge |
4 / 8 / 12 / 16 / 24 / 32 / 48 px | spacing steps |
touchTarget |
32px | sizing constant |
iconSize |
16px | sizing constant |
The seven steps space things: they ship as --mui-spacing-* CSS variables and theme.spacing('small') resolves them. The two constants size things: they ship as --mui-touchTarget / --mui-iconSize — their own namespace, deliberately not under --mui-spacing-* — and because they are not spacing keys, theme.spacing() does not resolve them. The override object mirrors that split: the seven steps nest under spacing, the two constants sit beside it.
enhanceDensity(theme, {
spacing: { small: 10 },
touchTarget: 28,
});Per-size ramps derive from the constants — small = calc(touchTarget − $token), large = calc(touchTarget + $token) — so moving one constant carries all three sizes rather than only the middle one.
The scale is closed. The override object is strictly typed; a misspelled key is a compile error, and new step names cannot be added. Registering user-defined steps was spiked and declined — the steps line components up precisely because there are few of them. For a value the ladder doesn't carry, apps use a multiple of the spacing unit, which theme.spacing() has always accepted.
Use the scale
The scale reads back off the theme, so app-level customization sits on the same ladder the components reflow on — no second set of numbers to keep in sync.
// Spacing steps — in any CSS property, a `styleOverrides` callback, or `styled`.
theme.spacing('medium'); // '16px' (static) / 'var(--mui-spacing-medium, …)' (cssVariables)
theme.spacing('-xSmall'); // a leading dash negates
<Box sx={{ p: 'small', gap: 'xSmall' }} />;
// Sizing constants — not spacing keys, so read them off the theme instead.
const Control = styled('div')(({ theme }) => ({
height: (theme.vars || theme).touchTarget,
'& svg': { fontSize: (theme.vars || theme).iconSize },
}));theme.vars carries the variable reference, so the value keeps following a --mui-touchTarget override scoped to a region; the plain theme carries the resolved length. The theme.vars || guard is what makes one customization work on both theme shapes. Both constants are undefined until enhanceDensity has run — density is opt-in, and the types say so.
How it ships
- the scale append to
theme.spacing() sxtakes the same names —<Box sx={{ p: 'small', gap: 'xSmall' }} />- Emitted theme overrides — zero component-source changes. The enhancer computes each component's values off the scale and emits them as
styleOverridesagainst selectors the components already ship. Nothing applied → nothing emitted → today's exact pixels. - Private CSS variables (
--_*) are used for components with multiple slots that needs to be in synced without breaking apart, e.g. Inputs, Autocomplete, Switch - Overrides land where the element renders —
rootby default, the portal slot when the styled element renders through a portal. - Gaps replace sibling margins wherever the layout allows, so there's one value to override instead of a margin pair.
- Three theme channels are written:
components.Mui*.styleOverrides,components.Mui*.defaultProps(for JS-gated dimensions), andtheme.mixins.toolbar.createThemealways fills the toolbar mixin with the stock 56/48/64px heights, so the enhancer overrides it with the same heights as the regular Toolbar (touchTarget + 2·xSmall,touchTarget + 2·xxSmallin landscape). Without that, an app that offsets a fixed AppBar with the mixin spacer gets a gap or an overlap. Only the height keys are replaced; other keys in a custom mixin are kept.
Decision
Agreed on how this lands:
- It ships as an experimental API. The enhancer is exported as
unstable_enhanceDensityand imported aliased —import { unstable_enhanceDensity as enhanceDensity } from '@mui/material/styles'— the same shape asunstable_ClassNameGenerator. - The docs live under Experimental APIs, not Customization. The existing
customization/densitypage keeps itssize/denseguidance unchanged. - No release-note entry, no announcement. The API stays deliberately unadvertised while it is unstable, so the surface can still change without a breaking-change cycle.
- Coverage is the component set mapped today. Components outside that mapping are not covered, and extending it is not committed.
Need Decisions
Scale naming — decided: camelCase
Keeps existing size naming small medium large, using x* as tails for expanding the scale. Options considered:
- plain:
xsmallxxsmallxlargeetc - hyphen:
x-smallxx-smallx-largeetc - camel:
xSmallxxSmallxLargeetc — decided
Camel gets the same quote-free object as plain (enhanceDensity(…, { spacing: { xxSmall: 2 }, touchTarget: 24 })) while keeping the xx tails readable, and it matches how the theme already names multi-word keys in CSS variables (--mui-shape-borderRadius, --mui-opacity-inputPlaceholder) — so the steps emit as --mui-spacing-xxSmall. The two sizing constants follow the same rule: touchTarget, iconSize.
Sx typings
- should sx handle scale autocompletion? when type
sx={{ p: <show scale> }}. I lean toward skipping this as it requires changes on MUI System on the type level
Extensibility
- should the scale be extensible? meaning user can add more keys to the scale. I lean toward skipping this too.
Search keywords: density, compact, comfortable, spacing scale, touch target
Activity
mj12albert commentedon Jul 1, 2026
Could we consider an API surface similar to breakpoints:
I know we have the
responsiveFontSizes/enhanceHighContrastprecedent, but if these grow it starts to look awkward:Makes you wonder does the order of these matter? and whether at some point there could be conflicts if these were applied out of order
As far as I can tell, the only technical benefit of the "enhancer function" API seems to be bundle size 🤔
siriwatknp commentedon Jul 2, 2026
That's the main benefit, the other crucial one is that I don't want the default scale to be opinionated.
[-][RFC] enhanceDensity — opt-in component density[/-][+][RFC] enhance*Density — opt-in component density presets[/+]LukasTy commentedon Jul 10, 2026
Overall it looks very nice.
Great direction and the solution looks super clean, especially compared to the initial explorations. 👌
Product asks
enhanceNormalDensityis a naming hazard. "Normal" reads as a no-op, but it reflows onto the normalized scale and can diff against the unconfigured render. Either make it pixel-identical or rename it. Related: the X Data Grid already shipsdensity: 'compact' | 'standard' | 'comfortable'-- aligning the vocabulary (Standard,Comfortable) keeps the product family coherent.In general, do we need the 3 densities besides the default one?
responsiveFontSizes/enhanceHighContrast. A compose helper can come later without breaking anything.I assume we'll need similar helper styling functions (possibly per package?) to handle it there.
Or do you have other ideas?
Prototype spot-check (#48749) against the RFC text
I went through the prototype diff claim by claim. The architecture holds up: the
--mui-density-*scale rides the theme's own vars channel exactly as described (including the no-CssBaseline and static-theme paths, unit-tested), slot/portal emission rules are followed (Tooltip tooltip/popper/arrow, Autocomplete listbox), base inheritance works as written (input padding onMuiInputBase, noMuiButtonBaseemissions anywhere), the--_*var inventory matches the named set exactly, and the public surface is the three presets with no options. Since "the emitted overrides + per-component mapping are what this RFC signs off", the remaining text-vs-code mismatches are worth fixing (in the RFC or in the emissions) before sign-off:typography.buttontoken 14px -> 13px, which collapses small == medium (comfort collapses medium == large at 15px) -- "Button small != large, ToggleButton 13/15" never moves per size. (b) The "no size-carrying prop -> type frozen" rule is deliberately broken by compact: Tooltip 11px -> 10px, Tab base 14px -> 13px, AccordionDetails pinned at 0.875rem (all marked "compact-only type" in code comments). (c) Icons aren't fed by the typography config: SvgIcon 18/20/30 are inline literals (compact-only), Chip icons calc off--_height, and the "Rating star 18/24/30" example has no implementation. The prototype's behavior looks like a defensible design -- it's just not the one requirement 5 describes, so I'd rewrite that paragraph around what the code actually does.MuiIconButtonandMuiRatingappear nowhere in the diff despite both being listed as "draft emissions staged in the presets". And SvgIcon -- one of the 10 verified families -- reflows only under compact (normal/comfort intentionally emit nothing); the coverage claim should say so.registeredFieldIds, with function-matcher rows skipped except one Tab case) -- staged rows in the ~220-row table are never checked against the presets. The generated table header says "CI diffs this file" but no CI job re-runsdensity:codegen. The PR body's "compact/comfort reflow captures" fordensity:shotis off twice: the actual levels are dense/loose (review-only), and they set per-component tokens from the [material-ui] CSS-var density adapter experiment #48624 architecture that nothing in this emission-based PR consumes, so they cannot show reflow. Before the rollout leans on these guards, I'd wire the codegen freshness check into CI, extend parity to the full table, and refresh the harness -- ideally making the generated table the canonical mapping dataset (presets verified against it in full, coverage reports derived from it).formControlLabelClasses.tsgains alabelPlacementEndkey the presets need for a:has()selector. It's behavior-neutral (the DOM class was already emitted at runtime), but the absolute claim and its checked box should disclose it.--_shrinkY, but shrink is never density-driven for outlined (hardcoded master literal, per the code's own comment);--_height/--_arrowSize/--_restY/--_shrinkYaren't component-prefixed despite decision 3; tag values ride thetagslot, not root; a few spacing seeds are tuned raw px (--_filledInputPadTop: 20px, frozen--_inputMarginTop: 16px) against requirement 5's absolute "spacing off the shared scale".<CssBaseline />"so the density variables materialise", contradicting the mechanism, the exported file's own header, and the tests;buttons.a11y.jsonlooks like an unrelated stray change; the publicDensityScaletype export contradicts densityScale.ts's own "not re-exported from the barrel" comment -- align one or the other.[-][RFC] enhance*Density — opt-in component density presets[/-][+][RFC] enhanceDensity — normalize components into a consistent scale[/+]mnajdova commentedon Sep 2, 2026
One small question/note.
Are x-small and small used as a step here just an example (e.g. component logic), or is it something we prescribe? Will people need to learn how these affects different component sizes?
github-actions commentedon Nov 23, 2026
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.