---
title: 'Overview'
description: 'Domain-neutral layout: a grid with named placement, named appearance, themes and the recipe protocol. Install it, compile a theme and place items in a container with no forms.'
order: 1
---

# Layout

`@schema-engine/layout` places items in a container and styles them by name, and it knows nothing about forms. It has a 12-track grid with named widths and drawn areas, named appearance axes such as `size` and `surface`, a compiler that turns both into one theme and one stylesheet, and a recipe protocol a domain uses to declare the frame around its content. Forms is the first domain built on it. Any host that puts items in a container can use the same rules: a marketing page, a dashboard, a document type.

Layout splits styling in two. The theme owns a **vocabulary** of names (`half`, `compact`, `elevated`, a gap token). A document owns the **intent**, written with those names in plain data. A renderer turns the intent into one DOM contract: `data-se-*` attributes and CSS custom properties.

## Install

```bash
pnpm add @schema-engine/layout zod
```

The quick start also uses `react` and `react-dom` to write the markup. The grid and axis schemas use `zod/mini`, so `zod` is a peer dependency. A recipe's slot schemas take any Standard Schema that validates synchronously (see [Recipe protocol](/docs/layout/recipe-protocol)). A form package installs this package for you: `@schema-engine/forms` depends on it, and the React and Radiant renderers declare it as a peer.

## Quick start

A theme compiles the grid and the appearance into one stylesheet. A host emits that stylesheet, puts the hooks on its container and its items, and writes their custom properties. This needs no renderer and no forms; the host below is a React component, and the custom properties go straight into `style` because they are assignable to React's `CSSProperties`:

```ts title="theme.ts"
import { createLayoutTheme } from '@schema-engine/layout';

export const theme = createLayoutTheme();
```

```tsx title="section.react.tsx"
import {
	GRID_CLASS,
	GRID_ITEM_CLASS,
	getAppearanceAttributes,
	getGridItemVariables,
	getGridVariables,
	type ElementGridConfig,
} from '@schema-engine/layout';
import { theme } from './theme';

interface Item {
	label: string;
	grid?: ElementGridConfig;
}

const items: Item[] = [
	{ label: 'First name', grid: { width: 'half' } },
	{ label: 'Last name', grid: { width: 'half' } },
	{ label: 'Email' },
];

export function renderSection() {
	return (
		<section
			className={GRID_CLASS}
			data-se-theme={theme.id}
			{...getAppearanceAttributes({ size: 'compact' })}
			style={getGridVariables(undefined, theme.grid, items)}
		>
			{items.map((item) => (
				<div
					key={item.label}
					className={GRID_ITEM_CLASS}
					data-se-theme={theme.id}
					style={getGridItemVariables(item.grid)}
				>
					{item.label}
				</div>
			))}
		</section>
	);
}
```

```ts title="page.ts"
import { renderToStaticMarkup } from 'react-dom/server';
import { renderSection } from './section.react';

console.log(renderToStaticMarkup(renderSection()));
```

{/* prettier-ignore */}
```html
<section
	class="se-grid"
	data-se-theme="l1tvu4rv"
	data-se-size="compact"
	style="
		--se-grid-template: repeat(12, minmax(0, 1fr));
		--se-grid-tracks: 12;
		--se-grid-default-column: 1 / -1;
	"
>
	<div class="se-grid-item" data-se-theme="l1tvu4rv" style="--se-item-grid-column: span 6">
		First name
	</div>
	<div class="se-grid-item" data-se-theme="l1tvu4rv" style="--se-item-grid-column: span 6">
		Last name
	</div>
	<div class="se-grid-item" data-se-theme="l1tvu4rv">Email</div>
</section>
```

The theme id (`l1tvu4rv` here) is derived from the compiled vocabulary, so it changes when the vocabulary does.

`createLayoutTheme()` compiles the default vocabulary. `theme.css` is the stylesheet, scoped by `[data-se-theme="<id>"]`: add it to the page once. `getGridVariables(grid, theme.grid, items)` gives the container its tracks and, for items with named widths, a `1 / -1` default placement. `getGridItemVariables(item.grid)` gives each item its placement. Appearance travels the same way: `size: 'compact'` becomes `data-se-size="compact"` and the theme's token rules read it. [Layout themes](/docs/layout/layout-themes) explains the theme, and [Grid and placement](/docs/layout/grid-and-placement) the placement names.

## Which tool do I use

The table names forms as the example consumer: its `grid`, `appearance` and `view` keys are the config of a form. Another domain reads the same keys from its own documents.

| I want to                                                            | Use                                                                     | Read                                                                                          |
| -------------------------------------------------------------------- | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| Put two fields on one row                                            | `grid.width: half` on each field                                        | [Placing fields in the grid](/docs/layout/grid-and-placement#rows-of-fields-width-and-offset) |
| Centre or indent a field                                             | `grid.offset`                                                           | same                                                                                          |
| Size a field in tracks and pack small ones into gaps                 | `grid.span: n` on the field, `autoFlow: 'dense'` on the grid            | [Sizes in tracks](/docs/layout/grid-and-placement#sizes-in-tracks-span-and-autoflow)          |
| Draw a layout where one field spans rows                             | `grid.areas` on the form or step, `grid.area` on each field             | [Drawn layouts](/docs/layout/grid-and-placement#drawn-layouts-areas)                          |
| Change the layout at a breakpoint                                    | `grid.responsive`, or an `areas` record                                 | same                                                                                          |
| Change the layout by the width of a card or panel, not the window    | `createLayoutTheme({ grid: { query: 'container' } })`                   | [Layout themes](/docs/layout/layout-themes#follow-the-container-not-the-window)               |
| Place one field exactly                                              | Raw `column`, `row`, `placeSelf`                                        | [Raw grid lines](/docs/layout/grid-and-placement#raw-grid-lines)                              |
| Make a form denser or roomier                                        | `appearance: { size: 'compact' }`                                       | [Appearance axes](/docs/layout/appearance-axes)                                               |
| Change border, shadow or surface                                     | `appearance: { surface: 'outlined' }`                                   | same                                                                                          |
| Add a brand colour that every form can pick by name                  | A host axis with `defineAxis`                                           | [Appearance axes](/docs/layout/appearance-axes#add-a-host-axis)                               |
| Give each of many entities its own colour (17 machines, every brand) | Your own `data-<domain>` attribute and CSS that sets the tokens         | [Identity tokens](/docs/layout/appearance-axes#identity-tokens-when-not-to-use-an-axis)       |
| Change the rhythm between fields everywhere                          | The `--se-grid-gap-*` tokens, or `createLayoutTheme({ grid: { gap } })` | [Theming](/docs/layout/theming)                                                               |
| Set a size, a width or a gap for one form                            | A class in `className` that sets the token                              | [Theming](/docs/layout/theming#where-to-set-a-token)                                          |
| Style one form, step or field once                                   | `className`, or `style` with custom properties                          | [Escape hatches](#escape-hatches)                                                             |
| Show or hide a part of a recipe (descriptions, labels, orientation)  | Slot config on `view`, for example `view.header.showDescription`        | [View recipes](/docs/forms-react/layouts)                                                     |
| Use a different frame around the fields                              | A recipe, built in or your own                                          | [Custom recipes](/docs/forms-react/layouts#custom-recipes)                                    |
| Make two engines or two renderers look the same                      | One compiled layout theme passed to both                                | [Layout themes](/docs/layout/layout-themes#share-a-theme-between-engines)                     |
| Copy a working setup                                                 | An example                                                              | [A themed form](/docs/examples/theming)                                                       |

When two tools fit, prefer them in this order: a named width before a raw line, an axis value before a token override, a token override before a class, a class before inline `style`.

## Four levels of layout

A form's `grid` and each element's own `grid` lay fields out. The levels run from the most to the least readable:

1. `width` and `offset` for fields that flow in rows. Names are shares of 12 tracks: `full`, `three-quarters`, `two-thirds`, `half`, `third`, `quarter`.
2. `span` for fields sized in tracks of a grid with `columns`, clamped to the tracks the grid has, with `autoFlow: 'dense'` on the grid to backfill gaps.
3. `areas` for a layout you draw as rows of names, with `area` on each field.
4. Raw grid lines (`column`, `row`, `placeSelf`) as the escape hatch.

Fieldsets and array rows lay their children out on a grid of their own, so the same names work inside a container. A fieldset with `grid: { subgrid: true }` lays them on its parent's tracks instead, so its fields line up with the fields around it. A step's `grid` replaces the form's grid for that step. The rules, the validation errors and the limits are on [Placing fields in the grid](/docs/layout/grid-and-placement#placing-fields-in-the-grid).

## Appearance

An **appearance axis** is one independent dimension of appearance with 2 to 5 named values, such as `size` or `surface`. Each value stands for a set of CSS tokens that components read. A form, a step, a field or a recipe slot picks a value by name, and the renderer writes it as `data-se-<axis>="<value>"`. The engine ships `size` and `surface`; a host adds its own, such as `tone`. A value that every entity of a domain has for itself (a colour per machine) is not an axis: see [Identity tokens](/docs/layout/appearance-axes#identity-tokens-when-not-to-use-an-axis). See [Appearance axes](/docs/layout/appearance-axes).

## Escape hatches

Names cover the common cases. Three hatches stay open for the rest, and they work the same in every renderer:

- `className` on the form, a step or a field. The theme's token rules sit inside `:where()`, so a class of yours always wins over them on the same element. Its grid and item rules do not, so change placement with `grid` config or the `--se-grid-*` and `--se-item-*` properties.
- `style` on the form, a step or a field. It accepts only CSS custom properties (keys starting with `--`, string or number values), because that is the one style shape that means the same in React, Radiant, JSON and YAML. A value cannot contain `;`, `{` or `}`.
- Raw `column`, `row` and `placeSelf` on a field.

```ts
{
	id: 'checkout',
	className: 'checkout-form',
	style: { '--se-grid-gap-default': '0.75rem' },
	steps: [/* ... */],
}
```

## Where next

- [Layout themes](/docs/layout/layout-themes): compile a theme, share it, the neutral hooks and nested themes.
- [Appearance axes](/docs/layout/appearance-axes): the definition, the rules, built-in axes and your own.
- [Grid and placement](/docs/layout/grid-and-placement): widths, offsets, areas and breakpoints.
- [Theming](/docs/layout/theming): the custom properties a host overrides, with a complete theme file.
- [Recipe protocol](/docs/layout/recipe-protocol): declare the slots and kinds of a domain's view recipes.
- [Recipes outside forms](/docs/layout/recipes-outside-forms): a card recipe, bound for React and for Radiant.
- [A layout page](/docs/examples/layout-page): a page with no form, laid out by this package alone.
- [A themed form](/docs/examples/theming): a form config with its theme and CSS, rendered live.
- [YAML forms](/docs/forms/yaml): author any of these in a `.form.yaml` file.
