Skip to main content
xriptxr

Grid

Info:Layout
9

A two-dimensional CSS grid: fixed columns, responsive auto-fit, or a content-plus-rail shell.

columns layout grid auto-fit gallery masonry sidebar rail

Live demo

live · @xtyle/astro

Grid

Fixed columns

columns=4 lays out four equal-width tracks; cells flow into the next row automatically.

12345678

Responsive auto-fit

minColWidth="14rem" fits as many tracks as the container allows — resize the page to watch the column count change.

components

33

categories

8

tokens produced

216

coverage

100%

Content beside a rail

sidebar="16rem" fixes the last child at that width and gives the rest to the first; minColWidth="20rem" is the floor the content will not go under, so the pair stacks instead of squeezing.

The document. It takes whatever the rail leaves, and keeps taking it until it would drop under its floor — narrow the page and watch the outline drop below instead of crushing this column.

outline

Anchors

Knobs

Derivation

Emit

side="start"

The rail first in source order.

Same shell, rail on the leading edge. Source order still matches reading order, so nothing has to be re-tabbed to make it look right.

Real content grid

The same primitive composes cards into a gallery — every cell shares one token-driven gutter.

xtyle-default

algorithm

A blessed derivation pack — anchors and knobs in, a full token set out.

xtyle-hc

algorithm

A blessed derivation pack — anchors and knobs in, a full token set out.

xtyle-quiet

algorithm

A blessed derivation pack — anchors and knobs in, a full token set out.

Grid arranges its children with a token-driven gap (0–8). Three sizing modes cover most needs: pass columns (1–12) for a fixed equal-width column count, minColWidth for a responsive auto-fit track that packs as many columns as fit at or above that minimum, or sidebar for the asymmetric two-track shell — content beside a fixed-width rail, the layout behind a document with an outline, an editor with an inspector, or a list with a detail pane.

sidebar takes precedence over both, and minColWidth reads as the main column's floor under it: the pair stacks when the main column would be forced narrower, and never stacks if it is omitted. Otherwise minColWidth wins over columns. align and justify control how items sit within their cells. Like the other layout primitives it adds spacing and structure but no color or chrome of its own.

When to use

How this component composes with the rest of the set.

The two-dimensional layout primitive; reach for Stack or Cluster when one axis is enough.
Use fixed columns for known layouts (a 3-up card row) and minColWidth for responsive galleries that reflow on resize.
Use sidebar for the application shell — a document beside its outline, a canvas beside its inspector — and reach for Splitter instead only when the divider should be draggable, since that trades a static track for a gesture surface and its persistence.
Resist the reflex to write min-width: 0 on a sidebar child: that is the property carrying the main column's floor, so cancelling it replaces the stack with a squeeze, and a column crushed to a few dozen pixels reads as a broken layout rather than a missing one.
Drop Cards, media, or any content into the cells; Grid imposes structure, not chrome.

Props

8 props, straight from the manifest.

PropTypeDefaultBindingsDescription
gap number
0 1 2 3 4 5 6 7 8
4
html svelte astro
Spacing between grid cells, as a step on the --space scale (0–8).
columns number
1 2 3 4 5 6 7 8 9 10 11 12
html svelte astro
Fixed number of equal-width columns (1–12). Ignored when minColWidth is set.
minColWidth html: min-col-width string
html svelte astro
Responsive mode: minimum track width (e.g. 16rem) for an auto-fit column count. Takes precedence over columns. Under sidebar it reads as the main column's floor instead, below which the pair stacks; the floor is carried as the child's own min-inline-size, so a stylesheet setting min-width: 0 on that child cancels it and the pair squeezes instead of stacking.
sidebar string
html svelte astro
Sidebar mode: the rail's fixed track width (e.g. 18rem), with the other child taking the remainder. Takes precedence over columns and minColWidth.
side GridSide
start end
end
html svelte astro
Which child is the rail in sidebar mode: end reads it as the last child, start as the first.
align GridAlign
start center end stretch
html svelte astro
How items align within their cells on the block axis (align-items).
justify GridAlign
start center end stretch
html svelte astro
How items align within their cells on the inline axis (justify-items). No effect in sidebar mode, where the two tracks are sized to fill the row.
inline boolean false
html svelte astro
Renders as an inline-grid instead of a block-level one.

Anatomy

The named parts that make up the component. A ::part() handle is reachable from your own stylesheet; the class beside it is the component's internal selector, which a shadow boundary keeps to itself.

root

internal .xtyle-grid

The CSS grid container carrying the gap, column, align, and justify classes.

--space-4

Tokens & coverage

What the component consumes, checked live against what the algorithm produces.

Success:fully covered 9/9 consumed tokens produced default register: 310 tokens

Live coverage check against the xtyle-default register (derive(xtyleDefault, { anchors })coverComponent(manifest, register)). Every token this component consumes must be a key the algorithm produces.

--space-0 --space-1 --space-2 --space-3 --space-4 --space-5 --space-6 --space-7 --space-8

Slots

default
html svelte astro

The children to lay out in grid cells.

Accessibility

A generic presentational container with no implicit semantics; it adds no roles and announces nothing.
CSS grid does not change DOM order, so keyboard and reading order follow source order; keep source order meaningful.
side moves the rail between the first and last track without reordering the DOM, so the visual and tab orders stay in agreement whichever one you pick.

Code

Fixed and responsive columns

A fixed three-column grid, then a responsive auto-fit grid driven by a minimum track width.

<xtyle-grid columns="3" gap="4">
	<xtyle-card>One</xtyle-card>
	<xtyle-card>Two</xtyle-card>
	<xtyle-card>Three</xtyle-card>
</xtyle-grid>

<xtyle-grid min-col-width="16rem" gap="3">
	<xtyle-card>Auto-fit</xtyle-card>
	<xtyle-card>responsive</xtyle-card>
	<xtyle-card>columns</xtyle-card>
</xtyle-grid>

Content beside a fixed rail

A rail at a fixed width with the content taking the remainder, stacking once the content would be squeezed under its floor, then the same shell with the rail first.

<xtyle-grid sidebar="18rem" min-col-width="22rem" gap="4">
	<xtyle-card>The document</xtyle-card>
	<xtyle-card>The outline</xtyle-card>
</xtyle-grid>

<xtyle-grid sidebar="14rem" side="start" gap="4">
	<xtyle-card>The rail, first in source order</xtyle-card>
	<xtyle-card>The content beside it</xtyle-card>
</xtyle-grid>