Layout System
Breakpoints, container max-widths, window size classes, grid tokens, density, touch targets, and responsive layout utilities.
The Layout System provides named tokens for responsive design — breakpoints, container widths, grid primitives, semantic layout spacing, and content-aware sizing primitives. These give AI agents (and developers) named constraints instead of guessing pixel values.
Breakpoint & Grid Tokens
Breakpoints
| Key | px | CSS variable |
|---|---|---|
xs | 320 | --fp-bp-xs |
sm | 640 | --fp-bp-sm |
md | 768 | --fp-bp-md |
lg | 1024 | --fp-bp-lg |
xl | 1280 | --fp-bp-xl |
2xl | 1920 | --fp-bp-2xl |
Grid + section defaults
Config key (layout.*) | Engine default |
|---|---|
columns | 12 |
gutter | s-6 |
section.paddingX | s-8 |
section.paddingY | s-10 |
section.paddingX (compact) | s-7 |
section.paddingY (compact) | s-9 |
section.gap | s-9 |
stack.gap | s-4 |
Container Max-Widths (--fp-container-*)
One per breakpoint. By default, containers match their breakpoint width:
| Token | Default |
|---|---|
--fp-container-xs | 320px |
--fp-container-sm | 640px |
--fp-container-md | 768px |
--fp-container-lg | 1024px |
--fp-container-xl | 1280px |
--fp-container-2xl | 1920px |
Window Size Classes (--fp-size-class-*)
Material Design 3 vocabulary for content-based responsive logic. These are threshold values, not breakpoints — use them with @container or in JavaScript to decide layout mode.
| Token | Default | Description |
|---|---|---|
--fp-size-class-compact | 0px | Phones in portrait |
--fp-size-class-medium | 640px | Tablets in portrait, foldables |
--fp-size-class-expanded | 840px | Tablets in landscape, laptops |
--fp-size-class-large | 1200px | Desktops |
--fp-size-class-xl | 1600px | Ultrawide |
Each class starts at its value and runs up to the next one. The values are fixed; they are not part of the config.
Viewport Scale (--fp-viewport-scale)
Layout primitives automatically scale up on ultra-wide screens (≥1920px) to prevent content from feeling cramped.
| Token | Default | Applies At |
|---|---|---|
--fp-viewport-scale | 1 | Default |
--fp-viewport-scale | 1.125 | @media (min-width: 1920px) |
Components like fp-section, fp-hero, fp-cta-strip, and fp-container multiply padding and gap by this scale. Dense UI (forms, tables) does not scale.
.section {
padding: calc(var(--fp-s-8) * var(--fp-viewport-scale, 1))
calc(var(--fp-s-6) * var(--fp-viewport-scale, 1));
}Grid Tokens
| Token | Default | Use |
|---|---|---|
--fp-grid-columns | 12 | Grid column count (full stylesheet only) |
--fp-grid-gutter | var(--fp-s-6) (16px) | Grid gap |
Density Modes (--fp-density-*)
Density is a single axis with three stops. It scales the spacing rhythm only — how tightly things are packed — and is orthogonal to the size axis (data-size, --fp-size-*), which is how big each thing is. Set it on <html>: with the data-density attribute, or with --fp-density on :root. The cortex output has only the --fp-density-* values; the [data-density] rules are in @flexpixels/ui, which is not published yet.
| Token | Value | Description |
|---|---|---|
--fp-density-compact | 0.75 | Dense UI (tables, dashboards) |
--fp-density-default | 1 | Standard spacing |
--fp-density-relaxed | 1.25 | Generous spacing (marketing) |
--fp-density is the master multiplier, and every --fp-s-1…--fp-s-12 step scales by it:
--fp-s-4: round(nearest, calc(0.5rem * var(--fp-density, 1)), 0.0625rem);<html data-density="compact">
<!-- 0.75× spacing on the whole page -->
</html>With cortex alone, the attribute needs these rules next to your theme:
[data-density="compact"] {
--fp-density: var(--fp-density-compact);
}
[data-density="default"] {
--fp-density: var(--fp-density-default);
}
[data-density="relaxed"] {
--fp-density: var(--fp-density-relaxed);
}The --fp-s-* steps are declared on :root and resolved there, so density works only on <html>. A data-density attribute on an inner element changes --fp-density on that element but not the --fp-s-* lengths its children inherit.
Touch Targets (--fp-touch-target-*)
Minimum interactive hit areas for accessibility compliance.
| Token | Default | Description |
|---|---|---|
--fp-touch-target-min | 44px | WCAG 2.5.5 Target Size (Enhanced) |
--fp-touch-target-comfortable | 48px | Material Design recommended |
Components take their hit-area floor from the size axis, --fp-size-min-target, which differs per tier. On a coarse pointer (@media (pointer: coarse)) the theme raises it to at least --fp-touch-target-min in every tier. fp-button, for example, reads:
--_min-touch-target: var(--fp-button-target-min-size, var(--fp-size-min-target));See Size & Density.
Semantic Layout Tokens
| Token | Default | Use |
|---|---|---|
--fp-layout-section-pad-x | 32px | Section horizontal padding (max) |
--fp-layout-section-pad-y | 64px | Section vertical padding (max) |
--fp-layout-section-pad-x-compact | 24px | Compact horizontal padding (min) |
--fp-layout-section-pad-y-compact | 48px | Compact vertical padding (min) |
--fp-layout-fluid-pad-x | clamp(…pad-x-compact, 6cqi, …pad-x) | Container-relative horizontal section pad |
--fp-layout-fluid-pad-y | clamp(…pad-y-compact, 8cqi, …pad-y) | Container-relative vertical section pad |
--fp-layout-section-gap | 48px | Vertical space between sections |
--fp-layout-stack-gap | 8px | Default stack gap |
--fp-layout-gap-{xs…xl} | 2 / 6 / 8 / 16 / 32px | The layout primitives’ gap="…" steps |
Gap steps (--fp-layout-gap-*)
fp-stack, fp-cluster, fp-grid, fp-split and fp-dock take gap="xs" | "sm" | "md" | "lg" | "xl", and each step reads its token. A design with its own rhythm sets it once rather than on every stack: in the config (layout.gaps, as spacing steps) or on a region, where the token inherits like any theme token:
.dashboard {
--fp-layout-gap-lg: 1.125rem; /* every gap="lg" inside: 18px */
}An instance’s own hook (--fp-stack-gap) still wins, and stops at its own box.
Fluid section padding (--fp-layout-fluid-pad-*)
These generated tokens are how layout primitives (fp-section, fp-hero, fp-container, fp-cta-strip) pad themselves. Each wraps clamp() around a cqi (container query inline) middle term:
--fp-layout-fluid-pad-x: clamp(
var(--fp-layout-section-pad-x-compact),
6cqi,
var(--fp-layout-section-pad-x)
);
--fp-layout-fluid-pad-y: clamp(
var(--fp-layout-section-pad-y-compact),
8cqi,
var(--fp-layout-section-pad-y)
);1cqi is 1% of the nearest ancestor query-container’s inline size — not 1vw. So padding responds to the width a component is placed into (a narrow sidebar column gets less padding), not the raw viewport. When there is no query container, cqi falls back to the small-viewport unit (svi), so the padding tracks the viewport instead. Consume them directly instead of hand-writing clamp(…, 6vw, …):
.section {
padding: var(--fp-layout-fluid-pad-y) var(--fp-layout-fluid-pad-x);
}How to Use
Container with max-width
.container {
max-width: var(--fp-container-lg);
margin: 0 auto;
padding: 0 var(--fp-s-6);
}Responsive grid
.grid {
display: grid;
grid-template-columns: repeat(var(--fp-grid-columns, 12), 1fr);
gap: var(--fp-grid-gutter);
}
/* Prefer fluid sizing; fall back to media queries only when needed. */Content-based layout with @container
Reach for @container only for discrete internal layout shifts (an arrangement that fundamentally changes at a threshold), never @media width queries inside shadow DOM — and prefer intrinsic reflow (flex-wrap, auto-fit + minmax()) for anything continuous. Establish the container on an inner part, not :host, so the host still participates in its parent’s flex/grid flow:
/* Inside a component's shadow DOM */
[part="surface"] {
container-type: inline-size;
}
/* --fp-bp-md = 768px */
@container (min-width: 48rem) {
[part="body"] {
flex-direction: row;
}
}Native Popover API (No Z-Index)
Always use the native HTML Popover API or <dialog> for overlays, modals, dropdowns, and toasts. They automatically reside in the browser’s top layer avoiding any stacking context limits.
<!-- Dropdown avoiding z-index -->
<button popovertarget="my-dropdown">Open</button>
<menu id="my-dropdown" popover>
<!-- Content -->
</menu>
<!-- Modal avoiding z-index -->
<dialog id="my-modal">
<!-- Content -->
</dialog>Sticky header
.header {
position: sticky;
top: 0;
}Common Examples
Full page layout with density
.page {
max-width: var(--fp-container-xl);
margin: 0 auto;
padding: var(--fp-s-8);
}
.sidebar {
position: sticky;
top: var(--fp-s-6);
}
.main {
display: grid;
gap: var(--fp-grid-gutter);
}<!-- Dense dashboard variant — density is set on the root element -->
<html data-density="compact">
<body>
<div class="page">...</div>
</body>
</html>Dialog + Popover interaction (guaranteed correct order)
<!-- No z-index required. The browser manages the top layer natively. -->
<dialog open>Modal Content</dialog>
<div popover="manual">Toast</div>Configuration
{
"layout": {
"breakpoints": {
"xs": 320,
"sm": 640,
"md": 768,
"lg": 1024,
"xl": 1280,
"2xl": 1920
},
"containerMaxWidths": { "sm": 600, "md": 720 },
"columns": 12,
"gutter": "s-6",
"section": {
"paddingX": "s-8",
"paddingY": "s-10",
"paddingXCompact": "s-7",
"paddingYCompact": "s-9",
"gap": "s-9"
},
"stack": { "gap": "s-4" },
"gaps": { "xs": "s-1", "sm": "s-3", "md": "s-4", "lg": "s-6", "xl": "s-8" }
}
}All values are fully customizable. breakpoints and containerMaxWidths take pixel numbers, columns is a number, and gutter / section.* / stack.gap / gaps.* take semantic spacing-step strings ("s-1"–"s-12") that alias the spacing scale. containerMaxWidths overrides default to the breakpoint value when omitted. breakpoints replaces the default set (it does not merge with it), and each containerMaxWidths key must name one of your breakpoints.
Best Practices
-
Don’t reach for z-index. The engine emits no z-index tokens on purpose: floating UI goes in the browser’s top layer (see point 3).
-
Use
--fp-container-*for max-width. Don’t hardcodemax-width: 1200px— use the token for consistency and configurability. -
Never use z-index for floating UI. Overlays, dropdowns, tooltips, and modals must use the native HTML Popover API or
<dialog>. -
Customize breakpoints in config, not in CSS. If your design needs
sm: 480px, change it intheme-config.json.layout.breakpointsreplaces the default set, so list every breakpoint you keep ({ "xs": 320, "sm": 480, "md": 768, "lg": 1024, "xl": 1280, "2xl": 1920 }); the tokens, the DTCG export and the MCP tools follow. Your own@media/@containerqueries still hold the pixel value, so update those by hand. -
Use
--fp-grid-gutterfor all grid gaps. This ensures consistent spacing between grid items across the application. -
Prefer intrinsic reflow; use
@containeronly for discrete changes. Letflex-wrap,auto-fit+minmax(), andclamp()handle continuous reflow. Reserve@container(never@mediawidth inside shadow DOM) for arrangements that fundamentally change at a threshold, and putcontainer-typeon an inner part, not:host. Never usevw/vhfor component-internal spacing — usecqi/cqb. -
Set density once, on
<html>. Usedata-density="compact|default|relaxed"on the root element; on a section it does not change the spacing tokens. -
Never disable touch targets. If a design calls for smaller buttons, use
size="sm"(ordata-size="sm"on the region): the visual box shrinks with the tier while, on a coarse pointer, the hit area is still raised to the touch minimum.