Designing Dense UIs Without the Enterprise Ugly: A Spacing System That Scales
Dense doesn't have to mean ugly. Here's the spacing, density, and token strategy we use to ship data-heavy UIs that still breathe — without rebuilding the design system every quarter.
Dense UIs have a bad reputation, and most of it is earned. Admin panels, trading dashboards, and healthcare consoles tend to look like someone compressed a spreadsheet until the pixels screamed. But density itself isn't the problem — unprincipled density is. The teams that get this right treat spacing as a token system with modes, not a free-for-all of px-2 sprinkled by whoever shipped last.
This is the approach we use when a client says "we need to show more on screen" and we don't want to end up with a UI that looks like SAP circa 2008.
Why density breaks most design systems
Most design systems are built for one density: comfortable. Marketing sites, consumer apps, SaaS onboarding — they all breathe. Then the product team gets a request from a power user: "I can only see 6 rows. I need 20." The engineer shrinks padding on one component. A designer tightens line-height on another. Six months later, nothing matches.
The root cause is that spacing tokens are usually defined as a single scale — space-1 through space-12 — with no concept of context. A table row and a marketing hero shouldn't pull from the same cognitive bucket, even if they occasionally land on the same pixel value.
The three-axis mental model
We think about spacing on three axes:
- Scale: the raw ramp (4, 8, 12, 16, 24...)
- Role: what the space does (gutter, inset, stack, inline)
- Density: the mode the surface is in (comfortable, compact, dense)
Most systems only have scale. Adding role and density is what lets you build a legitimately dense UI without pretending it's a different product.
Build a role-based token layer
Start with a primitive scale — keep it short. More than 10 steps and nobody remembers which one to use.
:root {
--space-0: 0;
--space-1: 2px;
--space-2: 4px;
--space-3: 8px;
--space-4: 12px;
--space-5: 16px;
--space-6: 24px;
--space-7: 32px;
--space-8: 48px;
--space-9: 64px;
}
Then build semantic tokens on top. These are the ones designers and engineers actually reference day-to-day:
:root {
/* Inset = padding inside a container */
--inset-surface: var(--space-6);
--inset-control: var(--space-4) var(--space-5);
--inset-cell: var(--space-3) var(--space-4);
/* Stack = vertical rhythm between siblings */
--stack-tight: var(--space-3);
--stack-default: var(--space-5);
--stack-loose: var(--space-7);
/* Inline = horizontal gap between siblings */
--inline-tight: var(--space-2);
--inline-default: var(--space-4);
}
Now when someone asks "what padding does a table cell use?", the answer isn't px-3 py-2, it's --inset-cell. The pixel value can change later without hunting through every component.
Add density modes, not density components
Here's the key move: density is a mode applied to a subtree, not a prop on every component. A table isn't dense — the surface it lives on is dense, and everything inside inherits.
[data-density='compact'] {
--inset-surface: var(--space-5);
--inset-control: var(--space-3) var(--space-4);
--inset-cell: var(--space-2) var(--space-3);
--stack-default: var(--space-4);
}
[data-density='dense'] {
--inset-surface: var(--space-4);
--inset-control: var(--space-2) var(--space-3);
--inset-cell: var(--space-1) var(--space-3);
--stack-default: var(--space-3);
}
Apply it where it makes sense:
<section data-density="dense">
<DataTable />
<FilterBar />
</section>
Every component underneath — buttons, inputs, menus, the table itself — automatically adopts the tighter rhythm. No prop drilling. No size="sm" scattered across 40 files. And importantly: a <Dialog> that opens out of that subtree starts fresh at comfortable density, because modals portal to the root.
Wiring this into Tailwind
If you're on Tailwind v4, the arbitrary variable syntax makes this clean:
<button className="px-[--inset-control] bg-brand text-white rounded-md">
Save
</button>
Or extend your theme so the tokens become first-class utilities:
// tailwind.config.js
export default {
theme: {
extend: {
padding: {
control: 'var(--inset-control)',
cell: 'var(--inset-cell)',
},
gap: {
stack: 'var(--stack-default)',
inline: 'var(--inline-default)',
},
},
},
};
Now p-control and gap-stack are legitimate utilities that respond to density modes. Designers can keep working in Figma with named spacing variables, and the handoff stops being a translation layer.
Density is not just about padding
This is where most teams go wrong. They shrink padding and call it dense. Then it feels cramped because they forgot four other things:
Type scale
Dense surfaces usually need a one-step-down type scale, but not a smaller minimum. We cap body text at 13px in dense mode, never lower. Below that, accessibility conformance gets shaky and your 45-year-old PM starts squinting.
Line height
Line height matters more than font size for perceived density. A 14px font at 1.5 line-height feels airier than 16px at 1.25. In dense mode we drop to 1.35 for body and 1.2 for table cells. Headings stay at 1.2 regardless.
Hit targets
This is the accessibility trap. WCAG 2.2 target size (minimum) wants 24×24 CSS pixels. Our dense buttons can visually shrink, but we pad the click area with pseudo-elements so the target stays at least 32×32. Looks tight, behaves generous.
.btn-icon::before {
content: '';
position: absolute;
inset: -6px;
}
Border and divider weight
At dense sizes, 1px borders start looking heavy. Switch to rgba dividers at around 8–12% opacity on light surfaces, or use inset shadows instead of borders for subtle separation. Zebra striping on tables beats borders for row scanning — trial both with real users before committing.
The accessibility tradeoffs you can't skip
Dense UIs push against three accessibility ceilings. Pretend you don't care and you'll fail a contract audit later.
Contrast: tighter type usually needs higher contrast, not lower. If your comfortable mode uses #64748b on white (around 4.6:1), dense mode should bump to #475569 (closer to 7:1). Smaller text is harder to read; compensate.
Focus rings: in a dense grid, a 2px focus ring with 2px offset eats visual budget. Don't remove it — switch to an inset ring or a high-contrast outline that doesn't shift layout. We've written about this in our focus-ring breakdown if you want the long version.
User preference: let people choose. Store the density preference per user, not per device. Someone on a 4K monitor at the office and a laptop at home will want different defaults, but respect the explicit choice above viewport heuristics.
type Density = 'comfortable' | 'compact' | 'dense';
function applyDensity(d: Density) {
document.documentElement.dataset.density = d;
localStorage.setItem('ui.density', d);
}
A war story about getting this wrong
On one logistics dashboard we shipped, we started with a single size prop on every component: sm, md, lg. Eighteen months in, there were 340 instances of size="sm" across the app, and about 60 of them were there because somebody wanted slightly tighter spacing on one specific screen but didn't want to touch anything else. The sizes had drifted. sm on a Button no longer matched sm on an Input. Fixing it took two engineers a sprint.
When we rebuilt it with density modes on surfaces, the component API got simpler (no size prop at all on most things), and density changes became one attribute on one wrapper. The visual regression tests caught drift automatically because everything inherited from the same tokens.
The lesson: don't give every component a density knob. Give the surface a density mode and let components ask the surface what to do.
Where we'd start
If you're staring at an existing design system and wondering how to retrofit this, don't rewrite anything on day one. Do this instead:
- Audit your current spacing. How many unique padding values exist across your top 10 components? If it's more than 8, you have a scale problem before you have a density problem.
- Introduce semantic tokens (
--inset-cell,--stack-default) as aliases over your existing scale. Change nothing visually. This is the refactor that unlocks everything else. - Pick one surface — usually a table-heavy page — and add a
data-densitytoggle. Ship it to internal users for two weeks. - Only then roll density out to the rest of the product, and only after you've measured whether anyone actually uses the dense mode. In our experience, roughly a third of power users switch to it immediately, most people never touch it, and that's a fine outcome.
Density isn't a visual style. It's an architectural choice about who controls spacing — the component, the surface, or the user. Pick the surface, and most of the other problems get easier.
Want a team like ours?
72Technologies builds production software for the kind of teams who actually read this blog.
Start a projectKeep reading
Optical Alignment: Why Your Perfectly Centered UI Still Looks Off
Mathematical centering is a lie your layout engine tells you. Here's how to fix the tiny visual misalignments that make polished UIs feel cheap — with concrete CSS, token, and Figma tactics.
Disabled Buttons Are a UX Smell: Design Patterns That Respect the User
Grayed-out submit buttons feel polite but punish users. Here's a breakdown of why disabled states fail, when to keep them, and the patterns we reach for instead.
Designing Error Messages That Don't Blame the User
Most error copy is written by backend exceptions and shipped unchanged. Here's a working framework for error messages that tell users what happened, what to do next, and whose fault it actually is.
