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
columns12
gutters-6
section.paddingXs-8
section.paddingYs-10
section.paddingX (compact)s-7
section.paddingY (compact)s-9
section.gaps-9
stack.gaps-4

Container Max-Widths (--fp-container-*)

One per breakpoint. By default, containers match their breakpoint width:

TokenDefault
--fp-container-xs320px
--fp-container-sm640px
--fp-container-md768px
--fp-container-lg1024px
--fp-container-xl1280px
--fp-container-2xl1920px

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.

TokenDefaultDescription
--fp-size-class-compact0pxPhones in portrait
--fp-size-class-medium640pxTablets in portrait, foldables
--fp-size-class-expanded840pxTablets in landscape, laptops
--fp-size-class-large1200pxDesktops
--fp-size-class-xl1600pxUltrawide

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.

TokenDefaultApplies At
--fp-viewport-scale1Default
--fp-viewport-scale1.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.

css
.section {
  padding: calc(var(--fp-s-8) * var(--fp-viewport-scale, 1))
    calc(var(--fp-s-6) * var(--fp-viewport-scale, 1));
}

Grid Tokens

TokenDefaultUse
--fp-grid-columns12Grid column count (full stylesheet only)
--fp-grid-guttervar(--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.

TokenValueDescription
--fp-density-compact0.75Dense UI (tables, dashboards)
--fp-density-default1Standard spacing
--fp-density-relaxed1.25Generous spacing (marketing)

--fp-density is the master multiplier, and every --fp-s-1…--fp-s-12 step scales by it:

css
--fp-s-4: round(nearest, calc(0.5rem * var(--fp-density, 1)), 0.0625rem);
html
<html data-density="compact">
  <!-- 0.75× spacing on the whole page -->
</html>

With cortex alone, the attribute needs these rules next to your theme:

css
[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.

TokenDefaultDescription
--fp-touch-target-min44pxWCAG 2.5.5 Target Size (Enhanced)
--fp-touch-target-comfortable48pxMaterial 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:

css
--_min-touch-target: var(--fp-button-target-min-size, var(--fp-size-min-target));

See Size & Density.

Semantic Layout Tokens

TokenDefaultUse
--fp-layout-section-pad-x32pxSection horizontal padding (max)
--fp-layout-section-pad-y64pxSection vertical padding (max)
--fp-layout-section-pad-x-compact24pxCompact horizontal padding (min)
--fp-layout-section-pad-y-compact48pxCompact vertical padding (min)
--fp-layout-fluid-pad-xclamp(…pad-x-compact, 6cqi, …pad-x)Container-relative horizontal section pad
--fp-layout-fluid-pad-yclamp(…pad-y-compact, 8cqi, …pad-y)Container-relative vertical section pad
--fp-layout-section-gap48pxVertical space between sections
--fp-layout-stack-gap8pxDefault stack gap
--fp-layout-gap-{xs…xl}2 / 6 / 8 / 16 / 32pxThe 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:

css
.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:

css
--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, …):

css
.section {
  padding: var(--fp-layout-fluid-pad-y) var(--fp-layout-fluid-pad-x);
}

How to Use

Container with max-width

css
.container {
  max-width: var(--fp-container-lg);
  margin: 0 auto;
  padding: 0 var(--fp-s-6);
}

Responsive grid

css
.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:

css
/* 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.

html
<!-- 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>
css
.header {
  position: sticky;
  top: 0;
}

Common Examples

Full page layout with density

css
.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);
}
html
<!-- 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)

html
<!-- No z-index required. The browser manages the top layer natively. -->
<dialog open>Modal Content</dialog>
<div popover="manual">Toast</div>

Configuration

json
{
  "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

  1. 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).

  2. Use --fp-container-* for max-width. Don’t hardcode max-width: 1200px — use the token for consistency and configurability.

  3. Never use z-index for floating UI. Overlays, dropdowns, tooltips, and modals must use the native HTML Popover API or <dialog>.

  4. Customize breakpoints in config, not in CSS. If your design needs sm: 480px, change it in theme-config.json. layout.breakpoints replaces 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 / @container queries still hold the pixel value, so update those by hand.

  5. Use --fp-grid-gutter for all grid gaps. This ensures consistent spacing between grid items across the application.

  6. Prefer intrinsic reflow; use @container only for discrete changes. Let flex-wrap, auto-fit + minmax(), and clamp() handle continuous reflow. Reserve @container (never @media width inside shadow DOM) for arrangements that fundamentally change at a threshold, and put container-type on an inner part, not :host. Never use vw/vh for component-internal spacing — use cqi/cqb.

  7. Set density once, on <html>. Use data-density="compact|default|relaxed" on the root element; on a section it does not change the spacing tokens.

  8. Never disable touch targets. If a design calls for smaller buttons, use size="sm" (or data-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.