---
description: Parent-controlled layout attributes (`[stack]`, `[cluster]`, `[grid]`,
  `[toolbar]`, `[flow]`, `[grow]`), spacing and flex utilities, and `[responsive-layout]`
  container queries.
output-file: layout.html
title: Layout

---
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

Controls have internal padding and no outer margins. Set spacing between children on the parent container with CSS `gap`. The same control then works in a form, a toolbar, or a panel with no trailing margin on the last item.

Apply layout attributes directly to semantic HTML elements such as `section[stack]`, `nav[cluster]`, or `ul[grid]`. Svelte components and Python constructors can emit these attributes directly without wrapper elements or extra CSS rules.

```python
from answerui.preview import preview
```

## Stack, cluster, grid, and toolbar

All rules in `@layer layout` are scoped to `:root` and `[ui]` up to `[unstyle]`:

- `[stack]` arranges children in a vertical flex column stretched to the container width.
- `[cluster]` arranges children in a wrapping horizontal flex row (`flex-wrap: wrap`, `align-items: center`, `justify-content: start`) at their natural widths. Add utility classes such as `.flex-nowrap`, `.items-start`, or `.justify-between` to adjust wrapping or alignment.
- `[grid]` fits as many equal-width columns as possible at `--grid-min` (default `16rem`). In a narrower container, a single column shrinks below `--grid-min`. Direct children have `min-inline-size: 0`.
- `[toolbar]` lays out a single-row, vertically centred flex bar with `min-inline-size: 0` and a `var(--space-2)` gap.

`--gap` is reset to `var(--space)` on every `[stack]`, `[cluster]`, and `[grid]` element. Overriding `--gap` on an outer layout therefore does not change `--gap` inside nested layouts. Applying any of these three attributes to a `ul` or `ol` also clears list padding and markers.

Add `[grow]` to a direct child of `[stack]` or `[cluster]` to fill the remaining height or width (`flex: 1`). Because `[grow]` also sets `min-inline-size: 0` and `min-block-size: 0`, long text in a row wraps instead of crowding sibling controls.

```python
member = '''<li cluster>
  <div stack grow class="gap-1"><strong>Ada Lovelace</strong><small>Workspace owner</small></div>
  <button type="button" btn btn-variant="secondary">Edit</button>
</li>'''
preview(f'''<section card style="max-inline-size:26rem">
  <ul stack>{member}{member.replace('Ada Lovelace','Grace Hopper').replace('Workspace owner','Editor')}</ul>
</section>''', height='12rem')
```

## Flow layout (`[flow]`)

Use `[flow]` for short sections of headings and paragraphs when you want vertical spacing without full `[prose]` typography for lists, code blocks, and tables. `[flow]` sets `display: grid`, `align-content: start`, and `row-gap: var(--flow-space)` (default `.5em`). Any direct child heading (`h1` through `h6`) after the first child has an extra `margin-block-start: .5em`.

`--flow-space` is reset to `.5em` on every `[flow]` element. You can override `--flow-space` on a nested `[flow]` section to tighten its spacing without changing the outer container's row gap.

```python
preview('''
<article card flow>
  <h2>Sharing a workspace</h2>
  <p>Invite your colleagues and decide what they can edit.</p>
  <section flow style="--flow-space:.2em">
    <h3>Permissions</h3>
    <p>Owners can invite others.</p>
    <p>Editors can change documents.</p>
  </section>
  <p>Changes apply immediately.</p>
</article>
''', height='16rem')
```

## Layout and visibility utilities

Prefer `[stack]`, `[cluster]`, `[grid]`, `[toolbar]`, or `[flow]` for standard layouts. Because `@layer utilities` comes last in the cascade, utility classes such as `.gap-2` or `.flex-nowrap` also override layout defaults on `[stack]`, `[cluster]`, and `[grid]` elements without inline styles. For overrides and one-off arrangements such as `class="flex items-center gap-2"`, `@layer utilities` defines spacing, flex, text, visibility, and responsive helpers:

- Spacing: `.p-*` (`padding`), `.px-*` (`padding-inline`), and `.py-*` (`padding-block`) for steps `0`, `1` through `4`, and `6`, plus `.gap-*` (`gap`) for steps `0`, `1` through `4`, `6`, `8`, and `12`. Step `0` is `0`; steps `1`, `2`, `3`, `4`, `6`, `8`, and `12` map to `--space-3`, `--space-2`, `--space-1`, `--space`, `--space1`, `--space2`, and `--space3`. `.mx-auto` centres a block horizontally (`margin-inline: auto`).
- Flex: `.flex`, `.flex-col`, `.flex-wrap`, `.flex-nowrap`, `.items-start`, `.items-center`, `.justify-center`, `.justify-between`, `.justify-end`, `.flex-1`, `.flex-none`, and `.min-w-0` (`min-inline-size: 0`).
- Text: `.text-center` (`text-align: center`), `.text-muted` (`color: var(--color-muted)`), `.truncate` (single-line ellipsis with `min-inline-size: 0`), and `.tabular-nums` (`font-variant-numeric: tabular-nums`).
- Visibility: `.ui-visually-hidden` hides an element visually while keeping it accessible to screen readers. `.ui-hidden` and `[hidden]:not([hidden=until-found])` set `display: none !important`.

Add `[responsive-layout]` to a container to declare the `ui-layout` container (`container: ui-layout / inline-size`). Below `48rem`, `.ui-wide-only` is hidden with `display: none !important`. At `48rem` and above, `.ui-compact-only` is hidden instead. Neither class sets `display` when the element is visible.
