Search documentation

Search pages, components, blocks, styles and colours.

Get started
Skip to content

Density

PreviousNext

Compact for dashboards, default for apps, spacious for websites. Set it on any container and everything inside follows.

Installation

The density tokens, switches and utilities ship with the foundations, which every Fabricator component installs. DensityProvider is its own item:

bunx --bun fabricator-ui@latest add density

Three densities

Fabricator UI builds dashboards and websites from the same components, and those want different room. Every component sizes itself from the density, so changing it resizes all of them together: controls, menu rows, text, icons, padding and gaps.

Compact28px controls, 12px text
Default36px controls, 13px text
Spacious44px controls, 15px text
Each column is a DensityProvider. The plan menus open at their column's density.
CompactDefaultSpacious
ForDashboards, toolbars, dense tablesAppsWebsites and landing pages
Controls and menu rows28px36px44px
Body text12px13px15px
Icons14px16px18px
Padding: controls / rows10 / 6px12 / 8px14 / 10px
Segmented item / track padding24 / 2px28 / 4px36 / 4px
Card spacing12px16px20px

Spacious controls are 44px, the touch target size WCAG 2.5.5 asks for; compact stays above the 24px minimum. Tracks keep their items concentric at every density: a 28px tab in a 36px list with 4px of padding becomes a 24px tab in a 28px list with 2px.

Set it on a container

data-density on any element sets the density for everything inside it. It needs no JavaScript and works in Server Components:

<main data-density="spacious">{/* hero, features, pricing, … */}</main>

Densities nest, so a compact toolbar can sit inside a spacious page, and data-density="default" sets one region back.

With popups

Menus, selects, popovers, tooltips, dialogs and sheets render in a portal at the end of <body>, outside the container, so the attribute alone doesn't reach them: they follow <html>. DensityProvider sets the attribute and passes the density through React context, which portals keep, so everything a component opens matches the region it opened from:

import { DensityProvider } from "@/components/ui/density"
 
export default function MarketingLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return <DensityProvider density="spacious">{children}</DensityProvider>
}

DensityProvider renders a display: contents wrapper, so it doesn't change your layout. Give it a className to make it a real box.

Booking projects for May

Launch your new site in two weeks

Design, copy and build in one fixed-price sprint. You get the code, and Fabricator UI underneath it.

One DensityProvider density="spacious" around the section. Nothing inside sets a size, and the team size menu opens spacious too.

The same works the other way round. A dashboard keeps the default density and makes its header compact:

<DensityProvider density="compact">
  <header className="flex items-center gap-2 border-b px-3 py-2">
    {/* breadcrumb, search, notifications, workspace menu */}
  </header>
</DensityProvider>
PagesThe page keeps the default density.
Only the header is compact (DensityProvider density="compact"); the page under it stays default. Open the workspace menu: it is compact too.

Toasts render once for the whole app, so they follow <html>.

Set it on one component

A size prop pins a component to a density, whatever its container says: size="sm" is compact and size="lg" is spacious. Without one, the component follows its container. Button, Toggle, Toggle Group, Select, Switch and Search take size. Icon buttons have the same pair: icon-sm and icon-lg.

Every other component takes data-density directly:

<Button size="sm">Filter</Button>
<Input data-density="compact" placeholder="Search" />
This frame is spacious. size="sm" pins a button to compact; data-density pins any component, here an input.

Containers keep their own size for their own job: a small Card, Item or Attachment is a smaller layout, and an Avatar's size is the picture's. They follow the density too, so a small card in a compact region is smaller still.

For the whole project

To use one density everywhere, set it on <html>:

<html data-density="spacious"></html>

Or choose it on Get started: the install command writes that density into your stylesheet's :root, and data-density still switches any part of the page. The settings menu in this site's header sets the density for every preview here.

The density-compact, density-default and density-spacious utilities do the same as the attribute from a class, so they take breakpoints:

<main className="md:density-spacious">
  {/* default on phones, spacious from md */}
</main>

Density pairs well with motion: spacious with smooth for websites, compact with snappy or instant for dashboards. The two are set separately.

Tokens

Components size themselves with CSS variables, never fixed pixels, and your own components can use the same ones. Each variable is named after its default value:

TokenCompactDefaultSpaciousUsed for
--density-3628px36px44pxControls, menu and table rows
--density-3228px32px40pxSidebar rows, avatars
--density-2824px28px36pxTabs and segmented items
--density-2420px24px28pxBadges, chips, row actions
--density-1612px16px20pxButton padding, card spacing
--density-1210px12px14pxControl padding
--density-86px8px10pxRow padding, gaps
--density-text-1312px13px15pxBody and control text
--density-text-1212px12px13pxCaptions, labels, errors
--density-text-14 / -1613 / 1514 / 1616 / 18Card and dialog titles
--density-icon-16 / -1414 / 1216 / 1418 / 16Icons

The full set runs from --density-4 to --density-48. Use them with Tailwind's variable syntax:

<div className="flex h-(--density-36) items-center gap-(--density-8) px-(--density-12) text-(length:--density-text-13)">
  <SparklesIcon className="size-(--density-icon-16)" />
  Upgrade
</div>

They are variables rather than theme keys like h-control so that class merging recognises them: a className="h-12" you pass to a component still replaces its h-(--density-36).

Shape

Items, buttons, inputs and highlights are rounded-lg (8px). Containers such as popups, cards, dialogs and tab tracks are rounded-xl (12px). A container holds its items with 4px of padding (p-1), so the inner and outer corners are concentric.

Rounded large8px
Inside rounded extra large12px
Containers are rounded-xl (12px) with 4px of padding, so the rounded-lg (8px) items inside them share the same curve.

Checkboxes use rounded-[6px]. Switches, badge dots and avatars are fully round.

Rounded or pill

Every corner comes from the --radius token: items and controls use rounded-lg (--radius) and containers rounded-xl (--radius × 1.4). Two values are supported:

Radius--radiusControls (36px)Containers
Rounded0.5rem (default)8px12px
Pill1.25rem20px, a full pill28px

Pill keeps containers concentric with their items, so menus, selects and tab tracks round out along with their rows. To switch a project to pill, add the radius item:

bunx --bun fabricator-ui@latest add radius-pill

It sets --radius: 1.25rem in your stylesheet. To go back, set --radius to 0.5rem. Try both from the settings menu in the header of this site.