Grid and placement

Placing fields in the grid

A form's grid sets its layout (columns, gap, responsive), and each element's own grid places it. There are four levels, from the most to the least readable:

  1. width and offset for fields that flow in rows.
  2. span for fields sized in tracks of a grid with columns.
  3. areas for a layout you draw as rows of names.
  4. Raw grid lines (column, row) as the escape hatch.

A grid uses either width/offset, areas or columns; span goes with columns, and raw lines can sit next to widths or areas.

Rows of fields: width and offset

For the common layouts, name the width:

export const fields = [
	{ $type: 'input', id: 'first', name: 'first', grid: { width: 'half' } },
	{ $type: 'input', id: 'last', name: 'last', grid: { width: 'half' } },
	{ $type: 'input', id: 'bio', name: 'bio', grid: { width: 'half', offset: 'quarter' } },
];

width is full, three-quarters, two-thirds, half, third, or quarter. offset leaves empty space before the field and takes the same names except full, so half with a quarter offset is centred in its row. A width on its own is the share of the row the field takes; the grid decides where it lands, so two half fields share a row. Leave the width out for a field that fills the row.

Both change by breakpoint through the element's grid.responsive, like every other placement key. A slot that sets only the width keeps the offset of the slot before it, and the other way round:

export const field = { grid: { width: 'full', responsive: { md: { width: 'third' } } } };

A grid whose fields use width or offset is laid out on 12 tracks, so each name is a whole number of tracks (half is 6, third is 4, quarter is 3), and a field in that grid that sets no width fills the row. Fieldsets and array rows lay out their children on their own grid, so width and offset work on a container's children the same way, and the enclosing grid's columns do not conflict with them.

export const address = {
	$type: 'fieldSet',
	id: 'address',
	name: 'address',
	legend: 'Address',
	elements: [
		{ $type: 'input', id: 'street', name: 'street', label: 'Street' },
		{ $type: 'input', id: 'city', name: 'city', label: 'City', grid: { width: 'two-thirds' } },
		{ $type: 'input', id: 'zip', name: 'zip', label: 'ZIP code', grid: { width: 'third' } },
		{ $type: 'input', id: 'region', name: 'region', label: 'Region', grid: { width: 'half' } },
		{ $type: 'input', id: 'country', name: 'country', label: 'Country', grid: { width: 'half' } },
	],
};

The street fills its row, the city and the ZIP code share the next one, and the region and the country share the last.

Validation enforces these rules for named widths:

  • A form grid that sets columns or minColumnWidth (at any breakpoint) cannot contain a top-level field that uses width or offset, nor one inside a subgrid fieldset: a grid uses areas, widths or columns.
  • A field that sets width or offset cannot also set a raw column.
  • A field's offset plus width must fit in 12 tracks, counting the value each carries from a narrower breakpoint: two-thirds after a half offset is rejected.

Drawn layouts: areas

When a field spans several rows or columns next to stacked fields, width and offset cannot say it. Draw the layout instead: the grid's areas is a list of rows, each row lists area names separated by spaces, and . is an empty cell. A field claims a name with grid.area.

grid:
    areas:
        default: ['a', 'b', 'c', 'd', 'e']
        md:
            - 'a a a b b b'
            - 'a a a c c c'
            - 'd d e e e e'
elements:
    - { $type: input, id: a, name: a, grid: { area: a } }
    - { $type: input, id: b, name: b, grid: { area: b } }
    # c, d and e claim their own area the same way

Below md the five fields stack. From md, a spans three columns and two rows, b and c stack beside it, and d and e share the last row. The column count comes from the rows, so a grid with areas sets no columns. areas is an array for one layout at every width, or a record keyed default, sm, md, lg, xl and 2xl (a slot you leave out keeps the layout of the slot before it). A responsive record must include default. A field's area is also responsive through grid.responsive, so a field can claim a different area when the template changes.

A few things the template does not police:

  • A field with no area in an areas grid is auto-placed: it fills a . cell if one is free, otherwise it opens an implicit row after the drawn ones. A raw column or row on such a field works as it does anywhere else.
  • Two fields may claim the same area. That is meant for fields that are never shown together (constraints, or hidden at a breakpoint); if both show, they are drawn over the same cells.
  • A field hidden at a breakpoint (grid.responsive.<slot>.hidden) need not be in that breakpoint's template, and the hidden state carries to wider breakpoints until a slot shows it again.
  • A step with no fields under a form-level areas needs grid: {} from the author: an empty grid of its own that replaces the form's. Without it, every template area counts as unclaimed on that step and validation rejects it.

A step takes its own grid, which replaces the form's grid for that step. An areas template names specific fields, so each wizard step draws its own: the address step below has its own template, and the payment step keeps the form's two columns. A form-level areas would apply to every step without a grid of its own, and each of those steps would then have to claim every area in it:

import { engine } from './engine';

export const checkout = engine.defineForm({
	id: 'checkout',
	grid: { columns: 2 },
	steps: [
		{
			id: 'address',
			title: 'Address',
			grid: { areas: ['street street', 'city zip'] },
			elements: [
				{ $type: 'input', id: 'street', name: 'street', grid: { area: 'street' } },
				{ $type: 'input', id: 'city', name: 'city', grid: { area: 'city' } },
				{ $type: 'input', id: 'zip', name: 'zip', grid: { area: 'zip' } },
			],
		},
		{ id: 'payment', title: 'Payment', elements: [] },
	],
});

Validation names the path of whatever it rejects:

  • Rows of one template must have the same number of cells, and each name's cells must form a rectangle. CSS drops a whole template that breaks either rule.
  • Every field area must be in the template at each breakpoint where the grid draws one, and every area in the template must be claimed by a field.
  • areas cannot be mixed with columns or minColumnWidth, or with width or offset on the grid's fields: a grid uses areas, widths or columns.
  • A field cannot set area together with width, offset, column or row.
  • Names are ASCII CSS identifiers (street, side-2) and cannot be auto, span, none, default, inherit, initial, unset, revert or revert-layer. A name is written into a CSS custom property, so anything that is not an identifier is rejected.
  • Fieldsets and array rows lay their children out without areas, so area is rejected on a container's children. Use width and offset there.

Raw grid lines

Raw column, row and placeSelf stay available as the escape hatch for anything the names do not cover. column: 2 is a CSS grid line, not a span: it starts the field at line 2. Use column: 'span 2' to span two columns, or column: '4 / 10' for explicit lines. A raw column field may sit next to width fields, but it counts tracks of the 12 the widths use there, so column: 'span 2' is two of twelve, a sixth of the row.

Sizes in tracks: span and autoFlow

When a field's size is a number of the grid's columns rather than a share of the row, say how many tracks it takes. span: 3 takes three tracks of the grid it sits in, and never more than the grid has, so a span wider than the grid is the whole row instead of an implicit column that overflows:

export const grid = { columns: 4, responsive: { md: { columns: 12 } } };

export const fields = [
	{ $type: 'input', id: 'osc', name: 'osc', grid: { span: 2 } },
	{ $type: 'input', id: 'filter', name: 'filter', grid: { span: 7 } },
	{ $type: 'input', id: 'amp', name: 'amp', grid: { span: 3, responsive: { lg: { span: 4 } } } },
];

Below md the grid has four tracks, so the span: 7 field is the full row; from md it covers seven of twelve. The clamp reads the grid's track count at the same width the template switches, so a span and its tracks never disagree, in a media theme and in a container theme (query: 'container', so a card narrower than md inside a wide window gets four tracks and a clamp of four). span also changes in responsive, and it takes the tracks of the grid you wrote: columns: n gives n, named widths give 12 and areas give the width of their rows. A subgrid fieldset passes its parent's count on, so a span inside it clamps to the parent's tracks.

autoFlow on the grid sets how fields without a position fill it. 'row' (the default) places them in source order; 'dense' backfills gaps earlier in the grid with later, smaller fields, so a span: 1 field after two span: 3 fields in four tracks sits beside the first one instead of leaving a hole. It is part of the grid's structure, so it is not allowed in responsive. Dense packing changes the visual order, not the DOM, reading or focus order: a keyboard or screen reader user still meets the fields in source order, so a field that jumps up the page is reached after the fields it now sits above (WCAG 2.4.3, Focus Order). Use it for tiles whose order carries no meaning, and keep 'row' for fields a person fills in top to bottom. If a dense layout moves a field that has to come in sequence, change the source order to match what you see.

Validation enforces these rules:

  • span is a positive whole number; 0 and 1.5 are rejected.
  • A field cannot set span together with width, offset, column or area in the same slot. Different slots may differ, such as a width below md and a span from md.
  • A subgrid takes no span, because it spans its parent's full row.
  • columns: 'auto' cannot clamp a span. The number of tracks auto makes depends on the width and the minimum column width, and CSS cannot compute it, so a span there falls back to one track and validation rejects it at the span key, naming the breakpoint where the columns are auto. Give the grid a track count instead, per breakpoint, and measure the breakpoints against the card with a container theme: columns: 4 with responsive: { sm: { columns: 8 }, md: { columns: 12 } } grows with the room the card has, which is what auto was for.
  • A container's own children (a fieldset or array row that is not a subgrid) sit on a grid of their own with one track unless they use width, so a span there is the whole row. Put subgrid: true on the container to size its children against the parent's tracks.

There is no width: 'auto'. A field that takes the room its content needs is a track-sizing question, and columns: 'auto' with minColumnWidth already answers it for the grid.

Subgrid: line up the fields of a fieldset

A fieldset lays its children out on tracks of its own, so its fields do not share column lines with the fields around it. subgrid: true on the fieldset makes it span its parent's full row and lay its children on the parent's column tracks and column gap, with CSS subgrid and no script:

export const step = [
	{ $type: 'input', id: 'first', name: 'first', grid: { width: 'half' } },
	{ $type: 'input', id: 'last', name: 'last', grid: { width: 'half' } },
	{
		$type: 'fieldSet',
		id: 'address',
		name: 'address',
		legend: 'Address',
		grid: { subgrid: true },
		elements: [
			{ $type: 'input', id: 'street', name: 'street', grid: { width: 'half' } },
			{ $type: 'input', id: 'city', name: 'city', grid: { width: 'half' } },
		],
	},
];

The street sits under first and the city under last, and half inside the fieldset still means half of the row. The rules:

  • It spans the full row. A subgrid takes no width, offset, column, area, span, justifySelf or placeSelf, and validation rejects them at the key. hidden and the block margins in responsive, and row and alignSelf, work as on any element.
  • Widths count the parent's tracks. A grid whose fields, or the fields of a subgrid in it, use width or offset is laid out on 12 tracks, so the parent takes 12 when only the fieldset's children set a width. Under a parent with columns: 3, the children place on its three columns by flow, and a width inside is rejected like a direct one. With columns: 'auto' the fieldset spans every track the grid draws, so the children flow across them as in auto-fill.
  • The edge columns are inset. Interior column lines match the parent exactly, but the fieldset's own border and padding are added to the fields in its first and last columns. The Radiant fieldset has 1rem of padding and a 1px border, so those fields start calc(1rem + 1px) in from the lines above and below them; the forms-react fieldset has none.
  • Subgrids nest. Every level spans its parent's row and passes the tracks on.
  • It is structure, not a breakpoint. subgrid is not allowed in responsive. The tracks it takes still change with the parent's columns and width at each breakpoint, and the children keep their own responsive placement.
  • Not supported. A parent that draws areas rejects a subgrid. An array rejects subgrid, since subgrid rows are not supported yet. Rows are never subgridded: each field is one grid item.

Both renderers draw a subgrid fieldset as a div with role="group", labelled by its legend through aria-labelledby, instead of a <fieldset>: Chromium lays a fieldset's content out in an anonymous box that does not take the parent's tracks. Assistive technology gets the same named group, and the legend is a heading row at the top of the box rather than a gap in its border. Browsers have supported subgrid since 2023 (Chrome and Edge 117, Safari 16, Firefox 71). Under a layout theme that queries the container, a subgrid has no wrapper of its own and its breakpoints follow the container of the grid it sits in; Layout themes has the markup rules for hand-written containers.

Breakpoints: the window or the container

Every responsive map, areas record and gap ramp names breakpoints (sm to 2xl), and the layout theme decides what they measure. By default it is the width of the window. For a form or a grid that lives in a card, a sidebar or a panel, the theme can measure the grid's own wrapper instead, with grid: { query: 'container' }. The config you write here does not change: md still means "from the md threshold up", only the width it is compared with differs.

import { createLayoutTheme } from '@schema-engine/layout';

export const panelTheme = createLayoutTheme({ grid: { query: 'container' } });

The forms renderers wrap each grid for you; markup of your own needs the wrapper and has a few containment caveats. Layout themes has both.

The layout theme and appearance

The grid vocabulary (breakpoint thresholds, gap tokens, the default minimum column width) and the appearance axes (size and surface built in, plus any you define) belong to one layout theme, compiled by @schema-engine/layout and passed to the engine as layout, either compiled once or as inline { grid, appearance } options:

import { createFormEngine } from '@schema-engine/forms';
import { createLayoutTheme } from '@schema-engine/layout';
import { elements } from './registrations';

const theme = createLayoutTheme({ grid: { breakpoints: { md: '50rem' } } });

const checkout = createFormEngine({ elements, layout: theme });
const profile = createFormEngine({ elements, layout: theme });

Engines built on one compiled theme carry the same data-se-theme and the same stylesheet content; Layout themes says how each renderer emits it. A form of one engine can sit inside a grid item of another: the nearest theme's token rules apply.

A form, a step, a field or a recipe slot picks a named value per axis with appearance: { size: 'compact' }, and the renderer writes data-se-size="compact". A registration declares the axes it responds to with appearanceAxes, and validateForm rejects a pick on any other axis, an unknown axis and an unknown value.

The full guides are in Layout:

  • Layout themes: the options, sharing a theme, querying the container instead of the window, the neutral .se-grid, .se-grid-item and [data-se-theme] hooks, the --se-item-* properties and nested themes.
  • Appearance axes: the definition, what makes a good axis, size and surface, defineAxis and host axes.
  • Theming: the custom properties a host overrides.
  • A themed form: a form config with its theme and CSS, rendered live.