Layout
Arrange elements with <column>, <row> and flex, share free space, push items apart, wrap grids and scroll.
janelkit Included with janelkit. Nothing extra to install. What you will learn
- How <column>, <row> and flex place their children along a main axis.
- The default behavior of each, so layouts are predictable.
- How flex shares free space and how <spacer> and margins push items apart.
- How to wrap a grid and when to scroll.
Three boxes that arrange their children
A layout answers two questions: where each element goes, and how much space it takes. <column> stacks its children from top to bottom. <row> places them from left to right. flex, lowercase, is the general box behind both: a row by default, configurable with direction and the full set of flexbox properties.
The direction a box places its children is its main axis: vertical in a <column>, horizontal in a <row>. The other direction is the cross axis. gap separates children along the main axis; padding separates them from the box edge.
<window title="Boxes" width={460} height={300}>
<column padding={24} gap={12}>
<text>A Column stacks its children.</text>
<textfield placeholder="Fields fill the width" label="Example field" />
<button>Buttons keep their size</button>
<row gap={8}>
<text>A Row centers its children vertically:</text>
<button>One</button>
<button>Two</button>
</row>
</column>
</window>CopyComplete component · Save as src/App.janel in a scaffolded project.
What you should see
The text and the field stretch across the window; the button keeps its natural width. In the last line, the text and two buttons sit side by side, vertically centered.
Know the defaults
Most layout surprises come from defaults. In a <column>, <text>, <textfield>, <textarea>, <column>, <row> and <scroll> take the full width, like blocks, while buttons and checkboxes keep their natural size. In a <row>, children are centered vertically. In both, only children with flex shrink when space is short. flex follows web defaults instead: a row, children stretched across, and every child allowed to shrink down to its content.
Leftover space is not spread between children: it stays at the end unless justify-content says otherwise. The root element fills the whole window.
| Property | Question it answers | Example |
|---|---|---|
| gap | How far apart are siblings? | gap: 12px |
| padding | How far from the box edge? | padding: 24px |
| justify-content | Where along the main axis? | start, center, end, space-between, space-around, space-evenly |
| align-items | Where along the cross axis? | start, center, end, stretch, baseline |
| align-self | Override the alignment of one child? | align-self: stretch |
| flex | How much free space does a child take? | flex: 1 |
| margin | Space outside one child; auto pushes it away. | margin-left: auto |
Push items apart with <spacer> or margin
<spacer> takes the free space in its container and pushes its siblings to the ends. It is the simplest way to build a toolbar with actions on both sides. margin-left: auto on one child does the same from a style rule.
<window title="Toolbar" width={520} height={160}>
<column padding={16} gap={12}>
<row gap={8}>
<button>New</button>
<button>Open</button>
<spacer />
<button variant="primary">Save</button>
</row>
</column>
</window>CopyComplete component · Save as src/App.janel in a scaffolded project.
What you should see
New and Open sit on the left; Save sits at the right edge, whatever the window width.
Wrap a grid without Python
flex-wrap: wrap lets children flow onto new lines when they do not fit. With flex: 1 1 200px each card starts at 200 pixels and grows to fill its line; the grid reflows as the window is resized, with no code.
<script lang="python">
cards = [f"Card {n}" for n in range(1, 9)]
</script>
<window title="Grid" width={640} height={360}>
<flex class="grid">
{#each cards as card}
<column class="card"><text>{card}</text></column>
{/each}
</flex>
</window>
<style>
.grid { flex-wrap: wrap; gap: 12px; padding: 16px; align-items: start; }
.card { flex: 1 1 200px; padding: 16px; background: var(--surface); border-radius: var(--radius); }
</style>CopyComplete component · Save as src/App.janel in a scaffolded project.
What you should see
Eight cards arranged in rows of about three. Narrowing the window moves cards to new lines.
<scroll>, and sizes
<scroll> is a <column> that scrolls vertically when its content is taller than the space it has; by default it takes the free space of its container. It creates all its content, which is right for settings pages and modest lists. For hundreds or thousands of rows use <list>, which only creates the visible rows.
width and height set a preferred size in pixels; 100% takes the available space and other percentages are relative to the container. min-width, max-width, min-height and max-height limit how far an element grows or shrinks. A preferred size is a request, not a guarantee that content fits every window.
Common mistakes
- flex: 1 has no effect when the container only wraps its content: there is no free space to share. Give the container a size, flex or align-self: stretch.
- Do not nest a <scroll> inside a box that grows with its content; the <scroll> then never needs to scroll.
- Spacing between children belongs in gap on the container, not in margins on every child.
Learn moreLarge lists ↗Styles and themes ↗
Key points
- <column> stacks, <row> lines up, flex is the general box; gap and padding set spacing.
- flex shares free space; <spacer> and margin auto push items apart.
- flex-wrap builds grids; <scroll> scrolls, <list> handles very long lists.
English documentation based on the JanelKit source. For additional details, browse the source docs ↗.