Layout
Build an app layout outside-in: scaffold the regions, structure the content, tune the spacing, then adapt across widths.Overview
Build a layout outside-in. Settle the shell and its region budgets before any content exists, then work inward. Content-first layouts drift into a padded column of cards, because every section ends up inventing its own container.
- Scaffold: pick the shell, budget each region, and choose navigation
- Structure: rank the content in each region, then pick the weakest container that groups it
- Spacing: hold one content line per region, then tune gaps and density
- Breakpoints: decide what each region does as width changes
This guide decides layout, not component APIs. Run npx astryx build "<idea>" to start from the closest template for your app type, and npx astryx component <Name> for a component's props.
Scaffold
Shell
Pick the shell and budget its regions before any content exists. Structural widths are the one place raw px belongs; everything inside them uses the spacing scale.
- Pick the frame:
AppShellfor nav apps,LayoutwithLayoutPanelin a start or end slot for multi-pane tools, or a plain content column for documents and forms - Give every fixed region a width budget, so no region has to negotiate for space at render time
- Read the content to set fill or capped: tables, charts, and boards fill their region; prose, forms, and lists cap with
LayoutcontentWidth so lines never over-stretch - Set each region container policy, rows or card grid, before writing content
tsx// Recommended budgets: SideNav 240–280, icon rail 64–72,// side panel 340–420, filter rail 220–260.<AppShell sideNav={<SideNav>{/* nav items */}</SideNav>}><Layoutcontent={<LayoutContent>{/* table fills its region */}</LayoutContent>}end={<LayoutPanel width={380} hasDivider>{/* detail */}</LayoutPanel>}/></AppShell>// Capped instead: 640 suits text and forms, 960 mixed content.// Dividers stay full-bleed.<LayoutcontentWidth={640}content={<LayoutContent>{/* settings form */}</LayoutContent>}/>
Verify: every region has a width budget, a fill-or-capped decision, and a container policy written down before any content exists.
When the frame leaves navigation open, default to SideNav: it absorbs destinations you have not planned yet. App type and destination count are guiding indicators, not determining rules.
SideNav, the default: grouping needed, customizable nav, items with secondary actions, or nav that collapses. Trackers, consoles, and settings usually start hereTopNav: a shallow nav you expect to stay shallow, context that must stay visible, or a control- and filter-heavy page; add aTabListfor a second level. Media libraries often sit here, over grid content- Both: a genuine suite, where
TopNavcarries ecosystem-wide concerns (context switcher, global search) andSideNavcarries product nav - Neither: messaging and feeds use a column frame of rail, nav, stream, and panel
tsx// Default: product nav on the side.<AppShell sideNav={<SideNav>{/* items */}</SideNav>} />// Shallow, stable nav on a control-heavy page.<AppShell topNav={<TopNav>{/* items */}</TopNav>} />// Suite: ecosystem concerns on top, product nav on the side.<AppShell topNav={<TopNav />} sideNav={<SideNav />} />
Verify: you can state the reason in one sentence, and the choice still holds if the nav doubles in size. npx astryx build "<idea>" names the closest template, and its --skeleton shows the pairing already wired up.
Best practices
| Guidance | Practices |
|---|---|
| Do | Decide the frame, region width budgets, and fill or capped before any content exists |
| Do | State the reason for the navigation choice, or inherit the template pairing |
| Do | Reserve raw px for structural widths; interior spacing uses tokens |
| Don't | Build content-first and wrap each section in a |
| Don't | Stretch prose, forms, or lists across a wide region instead of capping with contentWidth |
| Don't |
|
| Don't |
|
| Don't | Both bars when the ecosystem layer is thin, so the second only wastes space |
| Don't | Deviate from the template navigation pairing without a stated reason |
Structure
Type hierarchy
Give every region one lead, then rank the rest with weight and color rather than size. Content uses two text colors, primary and secondary, and nothing dimmer: body copy needs no props at all.
- Body, the default: plain
Textwith no type, color, or size prop - Lead:
Headingat the level matching page depth, or bodyTextat a heavier weight - Support: step to the secondary color, not to a smaller size
- Metadata: the supporting type, or a
StatusDotorTokeninstead of prose
tsx// Body copy takes no props. Text already defaults to body// size in the primary color.<Text>Credentials rotate every 90 days</Text><HStack gap={2}><Text weight="semibold">Payments API</Text><StatusDot variant="success" label="Healthy" /><Text color="secondary">v2.14</Text><Text type="supporting">edited 3h ago</Text></HStack>
Squint test: blurred, you read lead, then support, then groups, in that order. If everything reads at once, raise contrast with weight and color, not borders and not smaller text.
Containers
Reach for the weakest container that reads as a group, and escalate only when it fails. Weakest to strongest:
- spacing and gap: related items inside one group. The default rhythm
Divider: peers in a dense list or toolbar, or fencing a header from a scrollable bodySection: the default page-structure unit, related content under a heading. No borderCard: a self-contained widget (KPI tile, chart, gallery entry), or a hard boundary around critical content
tsx// Records are rows in one Section, not one Card each.// Recommended row height: 32–40px.<Section padding={0}><List header={<Heading level={3}>Members</Heading>} hasDividers>{/* ListItem per member */}</List></Section>
Decision test: records render as rows, Table for columnar and List for single-line; a self-contained widget or hard boundary is a Card; everything else is a Section.
A region can pin a header or footer while its body scrolls. Both are Layout slots, and padding set once on Layout reaches all three, so header, body, and footer share one content line.
LayoutHeaderin the header slot: the region title and its primary actionToolbarinstead ofLayoutHeaderwhen the header carries interactive controlsLayoutFooterin the footer slot: actions that commit the work and must stay reachable- defaultHasDividers on
Layoutfences both at once, rather than hasDivider per slot
tsx// padding on Layout reaches every slot, so all three align.<Layoutpadding={4}defaultHasDividersheader={<LayoutHeader>{/* title + primary action */}</LayoutHeader>}content={<LayoutContent>{/* rows */}</LayoutContent>}footer={<LayoutFooter>{/* Save and Cancel */}</LayoutFooter>}/>
Verify: scroll the body. The header and footer stay put, their dividers run full-bleed, and all three still share one left content line.
Side panels
Master-detail: selecting a row opens a fixed-width side panel instead of navigating away.
LayoutPanelin the start or end slot ofLayout, holding a fixed width budget- hasDivider to fence it from the content region; isScrollable so long detail scrolls on its own
- For user-adjustable width, pair
useResizable() with aResizeHandleon the panel inner edge: after the panel in a start slot, before it in an end slot with isReversed - The handle then owns the divider, so the panel sets hasDivider={false}
- Render an
EmptyStatewhen nothing is selected, so the region never collapses
tsx// Recommended panel width: 340–420.<Layoutcontent={<LayoutContent>{/* rows */}</LayoutContent>}end={<LayoutPanel width={380} hasDivider isScrollable label="Details">{/* detail fields, or EmptyState when nothing is selected */}</LayoutPanel>}/>// Resizable: handle first in an end slot, and isReversed so// dragging left widens the panel.end={<><ResizeHandle isReversed hasDivider resizable={panel.props}label="Resize details" /><LayoutPanel width={panel.size} hasDivider={false} /></>}
Verify: at narrow widths the panel yields width instead of squeezing content (see Breakpoints), and only one element between the regions draws a border.
Best practices
| Guidance | Practices |
|---|---|
| Do | One lead per region; rank with weight and color; one primary action |
| Do | Leave body copy at its defaults; demote by weight and color, not size |
| Do | Default to |
| Do | Render collections as rows ( |
| Do | Open a fixed-width side panel on select; let it yield width at narrow sizes |
| Don't | Grey and shrink body copy, so a whole region reads as secondary metadata |
| Don't | The disabled color for content; it fails contrast and is for disabled controls |
| Don't |
|
| Don't | Cards inside Cards, or full-width Cards stacked as page structure |
| Don't | A header or footer rebuilt inside the body, where it scrolls away with the rows |
| Don't | Flexbox soup: nested ad-hoc flexboxes instead of |
| Don't | Two competing primary actions in one region |
| Don't |
|
Spacing
Alignment
The container owns padding and child gaps; children zero their margins, and interior spacing is always a token. Pick one content line per region and hold it constant, not the padding: container_inset = content_line - component_intrinsic_inset.
TextandHeadingcarry no inset, so the container takes the full paddingList,Tab, Menu, and nav items carry a small inset, so the container gives up its padding and the component owns the lineTablecells carry a larger inset, so the container gives up its padding and the cell owns the line
tsx// Target content line = 16px.// Heading has 0 inset, so the Section takes the full padding.<Section padding={4}><Heading level={3}>Members</Heading></Section>// List has ~8px built in, Table cells 12–16px, so the Section// gives up its padding and the component owns the inset.<Section padding={0}><List>{/* items */}</List></Section>
Verify: draw one vertical line down the left of the region. Every label touches it; only hover and selected backgrounds cross it.
Rhythm
Grouping comes from contrast between tight and generous gaps, not one repeated value. If every gap is the same step, proximity does no work.
- Tight gaps bind: the smallest steps, used inside an item or field
- Generous gaps separate: several steps up, used between sections
- Reach for the in-between steps to tune cadence, rather than rounding everything to the same two values
tsx// Tight binds at gap={1}–{2}, generous separates at gap={4}–{6}.// In-between steps tune cadence: gap={3} = 12px, gap={5} = 20px.<VStack gap={6}><VStack gap={1}><Text weight="semibold">Retention</Text><Text color="secondary">Logs are kept for 30 days</Text></VStack><VStack gap={1}>{/* next label and value */}</VStack></VStack>
Verify: with every border removed, you can still name the groups from spacing alone. If you cannot, the intervals are too uniform. Form fields are the exception: FormLayout owns their spacing.
Density and size
Match density to how often a region is used, and give every control in a row the same size so heights share a baseline.
- Compact: high-volume regions scanned fast, like logs, monitors, and large datasets
- Balanced: most
TableandListsurfaces - Spacious: low-frequency or high-stakes rows, like settings or a short selection list
tsx// Pair density with one control size: compact with sm,// balanced with sm or md, spacious with md or lg.<Table data={rows} columns={columns} density="compact" hasHover /><Button label="Retry" size="sm" variant="ghost" />
Verify: every interactive element in a row shares one size, and that size is paired with the density of the region it sits in.
Best practices
| Guidance | Practices |
|---|---|
| Do | Let the container own padding; children zero their own margins |
| Do | Hold one content line per region: text on the line, hover backgrounds bleed to the edge |
| Do | Hold one padding token across a region header, body, and footer |
| Do | Contrast tight and generous gaps so grouping reads without borders |
| Do | One control size per row; match density to use frequency |
| Don't | Double padding: a component indented past its |
| Don't | Raw px for interior spacing; tokens only, px is for structural widths |
| Don't | One repeated gap everywhere, which flattens grouping |
| Don't | Mixed control sizes in a single row |
Breakpoints
Responsive contract
Lock what each region does as width changes, and pair every line of the contract with the prop or hook that enforces it.
- Divide: how many regions survive at each width
- Reveal: which regions earn their width only when there is room, and open on demand below that
- Resize: content flexes while fixed regions hold their budgets, and text stays capped by contentWidth so line length holds
- Swap: navigation becomes
MobileNavat theAppShellmobileNav breakpoint; the side panel becomes aDialogorBottomSheet, driven byuseMediaQuery
tsx// Recommended thresholds: 3 regions above 1024, 2 from 768,// 1 below. Text reads best at 40–60 characters per line.// >1024 SideNav 256 | content | side panel 380// <=1024 panel moves to a Dialog (useMediaQuery)// <=768 nav collapses to MobileNav (mobileNav "md")const isNarrow = useMediaQuery('(max-width: 1024px)');<AppShell sideNav={<SideNav />} mobileNav={{breakpoint: 'md'}}><Layoutcontent={<LayoutContent>{/* rows */}</LayoutContent>}end={isNarrow ? undefined : <LayoutPanel width={380} hasDivider />}/></AppShell>
Verify: every contract line names a mechanism, so the comment cannot drift from the behavior.
Best practices
| Guidance | Practices |
|---|---|
| Do | Write the contract down for every region before you call the layout done |
| Do | Decide per region whether it is revealed, resized, or swapped at each width |
| Do | Drop a region rather than let it compete for width it does not have |
| Don't | Hold three regions at a width where none of them has usable space |
| Don't | Shrink every region uniformly instead of swapping or dropping one |
| Don't | Wire a breakpoint in CSS that the contract comment never mentions |