Layout
Stacks, rows and grids, widths, alignment and breakpoints: enough for most pages without writing CSS.
Stack and row
stack N puts children in a column with N pixels between them, from the space scale. row N puts them in a row that wraps onto new lines, centred vertically. Both remove their children's own top and bottom margins, so the gap is the only space. A <ul> or <ol> laid out with stack, row or grid loses its bullets and indent, since it's being used as a layout, not a list.
<main s="stack 24">
<h1 s="3xl bold">Title</h1>
<p>Text</p>
<div s="row 8">
<a s="button primary">Yes</a>
<a s="button">No</a>
</div>
</main>
Grid
grid N makes N equal columns; span N lets an item take several. The gap is the one from the stack or row it switches from; on its own, write grid 3 gap 24.
<div s="stack 24 md:grid 3">
<article s="card md:span 2">Wide</article>
<article s="card">Narrow</article>
</div>
stack, row and grid each set the display and alignment, so you can switch between them at breakpoints, and the grid keeps the gap.
Width
max N limits an element to N pixels wide and centres it: the usual page column. N comes from the width scale, 320, 480, 640, 768, 1024, 1280 unless you set widths in the config. measure limits text to about 65 characters a line, the comfortable length for reading.
<main s="max 1024 pad-x 24">
<p s="measure">A long paragraph…</p>
</main>
Padding counts inside the width: max 1024 pad 24 is 1024 pixels wide in all.
Alignment
| Write | Does |
|---|---|
align start|center|end|stretch|baseline | lines children up across the layout (vertically in a row) |
justify start|center|end|between | spreads them along it; between pushes the first and last to the edges |
center | centres the content both ways |
<nav s="row 16 justify between">
<a href="/">Logo</a>
<a href="/docs/">Docs</a>
</nav>
An align you set stays when the layout switches at a breakpoint: s="stack 16 md:row 24 align start" keeps start alignment as a row.
Full-height pages
screen makes an element at least as tall as the viewport, using dvh so mobile browser bars are accounted for. With center, the content sits in the middle:
<body s="screen center">
<main s="stack 8">…</main>
</body>
Showing and hiding
hide hides an element; show shows it again, usually from a breakpoint. On an element that is itself a stack, row or grid, repeat the layout instead, since show would undo it (Kerf tells you):
<span s="hide md:show">Shown from 768px</span>
<nav s="hide md:row 16">A row from 768px</nav>
For a header menu that's a panel on phones and a row of links from a breakpoint up, use menu.
Images and video
Images and video never grow wider than their container. Three words shape them:
| Write | Does |
|---|---|
ratio 16:9 | gives it a fixed shape, any whole width:height: ratio 4:3, ratio 1:1, ratio 9:16 |
cover, contain | how the picture fills that shape: cover crops it to fill, contain shows all of it |
round, round full | rounds the corners with the brand radius; full makes a circle or a pill. Works on any element, not only images |
ratio 4:3 cover round border-border
ratio 1:1 cover round full border-border<img src="hero.jpg" alt="…" width="1600" height="900" s="ratio 16:9 cover round">
<img src="me.jpg" alt="…" width="96" height="96" s="ratio 1:1 cover round full">
<video src="demo.mp4" s="ratio 16:9 contain"></video>
Every <img> needs width and height, the file's own size in pixels. They let the browser keep the image's space before it loads, so the page doesn't jump; ratio changes the shape it's shown in. cover or contain without ratio (or screen) does nothing, since the image keeps its own shape, so Kerf warns you. See Checks.
Wide content
scroll lets an element scroll sideways inside itself instead of widening the page on a phone. Wrap wide tables in it. Code blocks do this already.
<div s="scroll">
<table>…</table>
</div>