Skip to content

Build UI / Layout / Stack

Stack ​

A flex container with a token-based gap: it arranges whatever is slotted into it in one row or one column, aligned and spaced by attribute. A layout primitive with no surface of its own — no background, no padding, no border — so it never looks like anything on its own.

preview
Code
html
<kb-stack direction="row" spacing="xs">
  <kb-button>Save</kb-button>
  <kb-button variant="naked">Cancel</kb-button>
</kb-stack>

Usage ​

html
<kb-stack direction="column" align="stretch" spacing="nano">…</kb-stack>

When to use ​

  • Spacing a group of siblings consistently — a row of buttons, a column of fields, a toolbar — without a one-off flex rule per group.
  • Anchoring content to opposite ends with justify="space-between".
  • Grouping content inside another component's slot, where the parent gives you one region and you need several elements arranged in it.

When not to use ​

  • A page header or footer bar — <kb-header> and <kb-footer> are the landmark versions of the same centered-row idea, with a fixed height and a max width. A stack has neither and exposes no landmark.
  • A visible surface — a grouping that needs a background, padding or border is a <kb-card>.
  • A two-dimensional grid — this is a single flex line; children never wrap. Use CSS Grid when rows and columns matter.
  • Spacing text inside a paragraph — <kb-text> carries its own rhythm.

Composition ​

  • Can contain: anything. The shadow root is a single unnamed <slot>, so every child renders in source order as a flex item. One or more <kb-on> also work as children, for extra arcs beyond the single on attribute — they wire to the stack directly and render nothing, so they don't count as flex items either.
  • Can be a child of: anything, including another kb-stack. Nesting a column of rows is the normal way to build a two-dimensional layout out of this primitive, since a single stack never wraps.
preview
Code
html
<kb-stack direction="column" spacing="nano" align="stretch">
  <kb-stack direction="row" justify="space-between">
    <kb-text size="xxs" weight="bold">Total</kb-text>
    <kb-text size="xxs">R$ 240,00</kb-text>
  </kb-stack>
  <kb-button width="fill">Checkout</kb-button>
</kb-stack>

Because the host is the flex container, children stretch or shrink by the usual flex rules — a child with flex: 1 fills the leftover space.

Direction, alignment and spacing ​

direction, align, justify and spacing all accept a closed set of values. An unknown value is ignored and the property keeps its last valid value — it never reaches the stylesheet unchecked. The attribute in the DOM still shows whatever was written; read the property, not getAttribute(), to see what's actually applied.

AttributeActs alongAccepted values
justifythe direction of the stack (main axis)normal, start, end, center, stretch, left, right, space-between, space-around, space-evenly, flex-start, flex-end
alignacross it (cross axis)normal, start, end, center, stretch, baseline, flex-start, flex-end, self-start, self-end

start/end are the preferred spelling for both attributes; flex-start/ flex-end are accepted as legacy aliases.

In a row, align="center" vertically centers items of different heights; in a column, align="stretch" makes children fill the width. Switching direction swaps which attribute does what — check both when a stack changes orientation.

preview
Code
html
<kb-stack direction="row" justify="space-between" align="center" style="width: 100%">
  <kb-text size="xxs">Pinned left</kb-text>
  <kb-button variant="link">Pinned right</kb-button>
</kb-stack>

spacing selects a step of the inset scale, which keeps the rhythm between groups predictable across a page:

spacingGapUse for
quarck / nano4 / 8pxElements that read as one unit — icon and label, field and helper.
xs16pxThe default: siblings inside a group.
sm / md24 / 32pxSeparating groups inside a section.
lg / huge / giant40px+Section-level separation, where <kb-inset> may serve better.

spacing accepts only these eight steps of the inset scale. An unknown value is ignored and the gap keeps its last valid step.

Attributes ​

AttributeTypeDefaultDescription
directionrow | columnrowFlex direction applied to the host.
alignclosed set, see abovestartCross-axis alignment.
justifyclosed set, see abovestartMain-axis alignment.
spacingclosed set, see abovexsGap, resolved against --spacing_inset-{value}.
widthauto | fill | lengthautoHost width.
heightauto | lengthautoHost height.
hiddenbooleanfalseRemoves the stack and its children from layout and the accessibility tree.
onarc string—Echo wiring, source/event:type/sink.

This element dispatches no events.

Styling ​

The gap is the one decision also exposed as a custom property — useful when spacing must respond to a media query, which an attribute can't do.

Custom propertyDefaultControls
--stack-space-gapvar(--spacing_inset-{spacing})Gap between children, overriding the spacing attribute.
css
@media (width < 600px) {
  kb-stack.toolbar { --stack-space-gap: var(--spacing_inset-nano); }
}

Everything else (align, direction, justify, height, width) is an attribute applied directly to the host — set those rather than overriding the same properties in CSS.

States and accessibility ​

  • hidden adds the hidden custom state and display: none, removing the stack and its children from layout and the accessibility tree.
  • The host is declared presentational (role="none"), so the stack itself adds no node to the accessibility tree, and carries no accessible name — there's no alt attribute. Group semantics have to come from what you put inside it — a <nav>, a <ul>, a fieldset.
  • Visual order follows source order, so keyboard order matches the screen. Don't reverse it with flex-direction: row-reverse from outside.

Do's and don'ts ​

DoDon't
Pick a spacing step from the scaleSet a one-off pixel gap next to a scale that already fits
Nest stacks to build a two-dimensional layoutExpect children to wrap — a stack is a single flex line
Reach for <kb-card> when the group needs a surfaceAdd a background and padding to a stack to fake one
Keep source order equal to reading orderReorder visually with row-reverse or order