Layout

Parent-controlled layout attributes ([stack], [cluster], [grid], [toolbar], [flow], [grow]), spacing and flex utilities, and [responsive-layout] container queries.

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.

from answerui.preview import preview

Stack, cluster, grid, and toolbar

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

--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.

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.

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:

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.