Layout & spacing

A 4px grid, space that grows with the distance between ideas, and one breakpoint between a phone and the rest.

Space things by how closely they belong together, in steps of Tailwind's 4px scale, and lay the screen out for a phone first, then add md: for the rest.

Below 768px the search takes the whole width, and the label filter and Compose share the row under it; from md up, all three sit on one line. One tree, laid out by CSS.

Spacing#

The more two things belong together, the closer they sit. A handful of steps cover nearly everything:

BetweenGap
An icon and its label, inside a controlgap-1.56px
Controls that act together: a toolbar, a field and its buttongap-28px
Modules: between two, and around the region they fillModuleGrid8px
The rows of a form, the items of a list with padding of their owngap-416px
Groups: a form's sections, a card's header and bodygap-624px
Sections of a pagegap-8 or more32px+

Use gap on the parent rather than margins on the children: the space then belongs to the layout, and a child dropped in or taken out never leaves a double gap behind. Padding inside a panel matches the gap between its groups, so a card is p-4 with gap-4 inside.

Profile

Access tokens

  • ci-runnerRead and write runs · Used 4 minutes ago
  • deploy-botRead runs, publish releases · Used yesterday
  • backup-scriptRead everything · Never used

Profile and Access tokens are sections, gap-8 apart. Inside each, the heading, the body and the buttons are groups, gap-6; the form's rows and the tokens are gap-4; the two buttons that close the form act together, gap-2. The icon in Compose above sits gap-1.5 from its label, which Button does by itself.

Editor

Send them by

Do

Separate two groups with space first, a line only when space is not enough.

Editor

Send them by

Don't

Box every group in its own bordered card, or rule off groups that space already sets apart. Each line competes with the content for attention.

A long run of rows alike, a mailbox or a group of settings, is where space is not enough: each row holds several parts, and a hairline between the rows says which parts go together. A list's rows take it from List; a group of settings puts a Separator with purpose="row" between its rows, which a style whose dialogs part rows by space alone leaves blank.

Groups that are not rows of one list take a Separator when space is not enough between them: clusters of buttons in a toolbar, where a gap wide enough to set them apart would scatter the row. It is an element of the layout, so the parent's gap spaces it like any other child, and orientation="vertical" stands it between the items of a row. A pane's own edge, such as a sidebar's, is that Pane's edge instead: the line belongs to the pane and goes with it, and edge={{ md: "end" }} draws it only from the breakpoint where the panes stand side by side. Between two ways to do one thing, a Separator takes a label: the "or" between a sign-in form and the passkey and single sign-on buttons under it.

The toolbar's buttons fall into three groups: how text looks, how a block is shaped, what is attached. A separator between groups in a Toolbar takes decorative={false}, so a screen reader hears where one group ends; elsewhere it stays decorative, as it is by default. Where the row does not fit, the toolbar moves the last group into its ⋯ first, and draws no separator beside the ⋯ (Toolbars).

Modules#

A page of modules lays them out in a ModuleGrid, which stands them 8px apart and pads the region by the same amount; the page writes no spacing of its own between modules. Each Card keeps its own rule on every side and a light shadow under it, and the page's ground shows between them.

Open
38
Closed this week
112
Waiting on review
9
Oldest open
41 days
Queues
QueueOpenOldest
Inbox143 days
Billing1141 days
Releases86 days
Docs512 days
On call
alice until Friday, then bob.
Next release
Thursday, with 6 cards ready.

Columns and spans go in the grid's className (md:grid-cols-4, col-span-full). An aside of stacked modules is a ModuleGrid inside the grid: a grid inside another adds no padding of its own, so the aside's edges line up with its neighbours'. Modules in one row match heights; a stack keeps its modules at their own.

A reader that fills the height beside a rail gives the grid one row, grid-rows-[minmax(0,1fr)], and lets the reader's body (min-h-0 overflow-y-auto) and the rail scroll on their own.

Figures that read as one, such as the cells of a single stat strip, are cells ruled off inside one Card, never cards set edge to edge.

Panes and frames#

A Pane is a region of the app's frame rather than a module: panes meet along their edges, and from md up the app draws each one that is read or worked on as a card. A box set among what a surface holds, a block of code, a file, a set of tabs that is one block among others, is a Frame, its heading line on its lid and its closing actions on its foot, both toolbars that give way as the frame narrows. Tabs that switch everything a pane shows are no box in it: Tabs variant="pane" runs their strip across the pane under its header, and the current panel fills the rest of the pane and scrolls on its own, padded as the pane's content is. A table that fills a pane, as the tasks beside the open one's details do in the Tasks demo, takes fill: it takes the rest of the pane's height and scrolls inside it, its header staying at the top, while the pane's toolbars stay put. What stands on the ground and what goes inside what, cards, panes, frames and the links between them, is on Surfaces. The pull request demo's comments, its checks and its reply box are cards on the ground; every block of code in a document is a frame (Long content).

Breakpoints#

Tailwind's breakpoints are the library's, and the line that matters is md, 768px: below it is a phone, at or above it is everything else.

PrefixFromUse
—0The phone layout: one column, full-width fields, navigation in a Sheet or a TabNav on a row of its own
sm:640pxSmall adjustments: a dialog's buttons side by side
md:768pxThe desktop layout: side-by-side panes, a sidebar, a toolbar on one line
lg:, xl:1024px, 1280pxExtra panes that only fit on a wide screen, such as a contents column

A layout change is CSS (md:flex-row) wherever the same elements can be rearranged. Branch in JavaScript only when the tree itself differs, such as a pane that becomes a pushed page, and then use the library's own query so CSS and script never disagree on where the line is:

tsx
import { MD_UP, useMediaQuery } from "@orz/ui/hooks/use-media-query";

const wide = useMediaQuery(MD_UP);
Inbox

Pick a conversation to read it.

Narrow the window to walk the table. From lg up the folders sit in a pane of their own; below it they move into a Sheet behind Folders. From md up the conversation opens beside the list; below it, it replaces the list and the arrow goes back. Every change is a max-md: or lg: class, so the tree stays the same. A dialog's footer puts its buttons side by side from sm up by itself; Overlays shows one.

Width decides the layout; the pointer decides the room around the controls. A tablet is wide and touched, a narrow desktop window is small and clicked. Do not size controls by width, and do not lay out by pointer: the components already make room on a coarse pointer by themselves.

Width#

  • Content reflows down to 320px wide with no sideways scrolling (WCAG 1.4.10); only something two-dimensional by nature, a table, a log, a diff, scrolls inside its own box.
  • A row that holds a long label gives that label min-w-0 flex-1 and truncate, so the label shrinks and its neighbours keep their size.
  • The window's frame meets its edges: the header, a sidebar and a toolbar run to the window's sides, and a tool's panes fill the window. A filled pane never sits inside a centred box, where its fill would stop short of the edge and float.
  • Prose stops at a readable measure (max-w-prose, max-w-3xl) and centres in the window. A sidebar pushes it aside only when the window is too narrow to centre it clear of the sidebar. A page's contents sit right against the text.
  • Pages that read alike keep the text in one place: a page without a sidebar leaves the sidebar's room free all the same, so its text starts where a page with one starts.

Corners#

--radius is the theme's corner, 2px by default, and the rounded-* steps scale from it: rounded-lg is --radius itself, rounded-md and rounded-sm are smaller, rounded-xl and up are larger. Use the steps rather than pixel values, so a theme that squares its corners squares yours too. A box inside a rounded box takes a smaller step than its parent, so the two curves stay concentric. The components round to --radius too: a card and a dialog, a menu or a popover, a viewer's frame, a control and a chip; a row, a tab and a block inside a part stay square.

On each platform#

  • Pointer. Panes sit side by side and the page pads px-10 or so at the edges.
  • Touch. A phone pads px-4 to px-5, enough to keep content off the screen's edge and off the system's back gesture. Keep content out of the notch and the home indicator with the safe-area insets; Touch & mobile covers them.

In the demos