Foundations
Alignment
What lands on a margin or a center line — the shape, the letter or the icon box — and where the icon buttons at the two ends of a header go.
Align what the eye sees, not the box. Each kind of element has one point that lands on the line, and it uses the same point horizontally and vertically.
Principles
- One edge per column. Everything in a column of content starts on the same margin: 16px on a phone and with a mouse on a desktop, 20px on a touch screen from 768px (Spacing). A column of list cells (Activity, the sidebar and the phone's Home, search results) keeps 20px on a phone too (16px with a mouse), where its rows' content starts (Lists). In raft-ui the margin is
--column-margin, which heads, notices and footers pad by. - Align the visible thing. A shape aligns by its edge, text by its letters, a frameless icon button by its icon box.
Usage
A control and its label
A checkbox, radio or switch centers on the first line of its label — the same line whether or not a description follows it. A settings row is the exception: its controls center on the whole row.
- Center the control on the first line of its label. Offset it by half the difference between that line and the control —
(1lh - 20px) / 2for a 20px box — so it lands correctly at every type size without a hand-tuned nudge. - Don't align the control to the top of the text block. A 20px box sitting on the top of an 18px line hangs 1px below the line's center, and on a 16px line 2px below it.
- Don't center it on the label either. A label is often one line, which makes the two look the same — until it wraps, and the control slides to the middle of the block: 27px off the first line at a narrow width, and 8px off as soon as a description follows. The first line is what the control belongs to; the block is a coincidence.
- Leave 8px between the control and its label.
- Never shrink the control, and move it rather than resize the row. The switch keeps its size (50 × 30 on a touch screen, 38 × 22 with a mouse) and the checkbox and radio 20px wherever they sit. A control shorter than the line takes a box one line tall; a control taller than the line is moved up onto it, not given a row of its own. In a
<label>row a box never takes less room than its 20px, so a row oftext-xsis 20px tall; give a wrapping small label a 20px line (leading-5) so the box can sit on its first line. - In a settings row, the controls center on the whole row. The leading icon or avatar and the trailing switch, value or chevron center on the row, with or without a description: a row reads as one unit, and its controls belong to the whole row, not to the title. The row is its padding and its tallest part: 54px on a phone with a switch and a title alone. A setting that applies at once reserves no line under its text: its result line (SaveStatus) takes no room until a change fails, and then the row grows by it and the controls center on the whole row, the error with it (cindyz, 2026-11-10, #proj-raft-ui:4ae1a74e). A checkbox or radio next to wrapping text in a
<label>row still sits on that text's first line. - Let a tap between two options land on the nearer one. A box or a circle in a
<label>row reaches 4px past its line, half the 8px gap to the next option, and the label is the target for the rest. On its own, outside a label, its hit area is 44px on a touch screen.
raft-ui does this wherever it puts a control beside its label, so don't add a margin-top or items-center of your own:
FieldItemcenters aCheckbox,RadioGroupItemorSwitchin it on the first line of itsFieldLabel, 8px before it.- A
CheckboxorRadioGroupItemplaced directly in a<label>row takes a box one line of the label tall, centered on that line, so it sits wherever the row puts a line of text: on the first line withitems-start, and on the one line withitems-center, whatever the row's min-height. Set the label's type on the<label>, since the box reads its line from there, and useitems-startwhen the text can wrap. A switch beside a label goes in aFieldItemor aListRow. - A
ListRow variant="plain"centers both its ends on the whole row, with or without a description or aSaveStatusline under it.
In Space Grotesk's metrics the cap-height center and the middle of the text's box differ by 0.006em, under 0.1px at the sizes we set. Rendered, Chromium rounds the ascent and descent to whole pixels and puts an odd pixel of leading under the text, so at 11/13, 13/18, 15/20 and 16/24 the letters sit up to 0.5px above the line box's middle; Safari and Firefox center them exactly. Center on the line box anyway: a correction for one engine moves the other 0.5px the wrong way, and 0.5px alone doesn't show in a row. An odd difference between a mark and its line can also leave the mark up to 0.5px off in a given engine, which is below what shows in a row too, so we don't correct it either. A hand-tuned margin-top is a sign the control was aligned to the wrong thing: it is the right answer for one label at one size, and silently wrong for the next. Write the offset as the arithmetic, not as the number it currently comes to: Banner once carried mt-px for a 16px icon and mt-[4.5px] for a 9px status, (18 - 16) / 2 and (18 - 9) / 2 against an 18px line, and both went wrong when the desktop line changed. An icon or a status light that leads a line of text is centered on the first line the same way in every component (A mark that leads text).
A mark that leads text
A banner, a toast, a panel notice, an action card's notice and a status chip start their text with a mark: a notice with a Lucide icon (or the avatar of whoever it is about), a status chip with a status light. A notice never uses a status light to say what kind of notice it is (success, info, warning, error); it leads with its intent's icon or an avatar. One square mark must not carry several meanings, and a status light keeps its own: whether an agent, a person or a computer is working or online, a task's status, and the square attention dot that marks something waiting or unread. A notice about one of those things may still show that thing's light inside it. The mark belongs to the first line, like a control to its label. The one rule they share is where the mark sits. Each component keeps its own icon size and gap, set by the component: a banner's icon is 20px (16px in a sm banner), a toast's 16px, an action card notice's 14px.
- Center the mark on the first line of its text. Write the offset as the arithmetic,
(1lh - size) / 2, or move the mark half a line down and back up by half its own height, so it lands on the line at every type size, on the phone scale and the desktop one, and stays on the first line when the text wraps or a description follows. - Center it on the line box. In Space Grotesk's metrics the cap-height center and the middle of the text's box differ by 0.006em, under 0.1px at the sizes we set. Rendered, Chromium rounds the ascent and descent to whole pixels and puts an odd pixel of leading under the text, so at 11/13, 13/18, 15/20 and 16/24 the letters sit up to 0.5px above the line box's middle; Safari and Firefox center them exactly. Center on the line box anyway: a correction for one engine moves the other 0.5px the wrong way, and 0.5px alone doesn't show in a row. An odd difference between a mark and its line can also leave the mark up to 0.5px off in a given engine, which is below what shows in a row too, so we don't correct it either. A line of Chinese keeps Space Grotesk's line box (the fallback face doesn't make it taller), so the Latin in it has the same cap-height center; the ideographs' own ink centers scatter around it by up to 0.4px at 14px and 0.7px at 13px, differing as much from one character to the next, so there is no steady offset to correct and the same center holds for mixed and Chinese text. Never center the mark on the whole text block (it slides to the middle of a wrapped paragraph, as
items-centerdoes) and never place it with a fixedmargin-top. - Keep a status light at its one size, 10px with a 1.5px ink edge, beside any text. It is the same light in a chip, a panel header and a sidebar row, so it is the same size in all of them (Status): 10px is 7px of color, more than the 6px it takes to tell green from yellow from orange, plus two ink edges. It is even because every line and row it sits in is even, so it centers on a whole pixel; a 9px light was drawn with one more device pixel above it than below on 1x and 3x screens (decided by stdrc on 2026-10-22, replacing the 9px of #670).
- Set the type on the row, not only on the text. The mark reads
1lhfrom the type it inherits, so the row that holds the mark and the text carries the text's type, as Banner and PanelNotice do.
In raft-ui, Banner, PanelNotice, ToastIcon and MessageActionCardNotice center an icon placed in them on the first line (Banner and PanelNotice center a Spinner the same way, in the icon's column), and Badge and PanelActivity do the same for a Status, held at 10px whatever size it was given. The lead-icon and lead-dot utilities (styles.css) do it for a mark you place yourself, on a row that carries the text's type; with lead-dot, don't pass the Status a size.
A shape beside plain text
When a shape with its own padding (a chip, a frameless button's hover fill) sits in a row beside plain text, such as the values in a row of task properties, count its padding as part of the gap: pull the shape left by its padding, so its text starts where plain text would and its fill hangs outward.
The row is read as text, so the eye compares where the words start, not where the fills start. Aligning the shapes by their edge would push their words 6px past the plain values beside them, and the row would look ragged. This is the exception to aligning a shape by its edge: that rule holds when shapes line up with one another down a column.
Text of different sizes on one line
A line that mixes sizes or faces, such as a message's sender line (the name in bold text-subhead, the role, the model and a badge's words in text-caption, the time in Space Mono), puts every letter on one baseline: lay it out with items-baseline, not items-center.
- Align the baselines, not the boxes. Each size has its own line box, and centering the boxes centers each face's ascent and descent, not its letters. The smaller notes then stand up to 1px above the name's baseline at every size, the role and the time by different amounts, and the line looks broken at a glance.
- A shared baseline is optical alignment for the two faces. Space Grotesk and Space Mono have the same cap height (0.700em) and the same figure height (0.714em with overshoot), and their x-heights differ by 0.01em. So a time in Space Mono and a role in Space Grotesk of the same size stand exactly as tall on one baseline (rendered at 3x, the digits of
04:11and the capitals of the role have the same ink box to the device pixel), and no per-face offset is needed. Space Mono's taller ascent and descent only make its box sit differently, which is why centering boxes moves it. - A shape with words in it aligns by its words too. A badge in the sender line puts its letters on the baseline, as a chip in a sentence does (Marks in running text). Its 22px box then hangs a pixel lower than it would centered, so on a desktop a line with a badge is a pixel taller than the name's 22px line (on a phone the badge already makes the 20px line 22px). A line without a badge stays the height of the name's line. The shape's own baseline has to be its words': a flex box whose items are centered takes its baseline from its first item, so a TaskChip that led with its status pixel sat on the pixel's bottom edge, and its words stood a pixel off the label beside them in a DescriptionList. Lay the words out on the baseline inside the shape (
items-baseline, with padding for the space above and below) and center only the mark (self-center). - When the line wraps, align the first line. A label that wraps onto more lines sets its first line on the name's baseline, and the time stays on that line.
- In a row with a fill, every text takes the main text's line height, and no mark is taller than that line. A row whose items share the first baseline, such as a task row (the title, then the assignee and status in Space Mono), places each group by the baseline of its own first text, and the group's box is that text's line box. A smaller text has a shorter line: Space Mono's
text-mono-metaandtext-captionare 18px againsttext-callout's 22px, so the group's box sat 3px lower than the title's line, and a mark centered in it (an avatar, a chevron) sat 1.5px below the row's center. A mark taller than that line, such as a 32px action button, made the row taller, and the text sat 2.5px above the center of the hover fill (task rows, 2026-10-23). So give every text on the row the title's line height (leading-(--text-callout--line-height)on the row, and explicitly on sizes that set their own), and let a taller hit area hang into the padding by as much as it is taller than the line. Then the row's content stays centered in its fill. A row that centers its items (items-center), as every raft-ui list row does, needs neither.
Marks in running text
A reference chip, a mention of the person reading, a task chip and inline code sit inside a sentence, so they align as text. The chips share one box, 2px shorter than the line, so they never make it taller; its type, height and sides are in Chips in running text.
- Put their letters on the sentence's baseline. A chip's words line up with the words around it, with or without a leading icon. A chip that took its baseline from its icon floated 3px above the sentence, and a 1px nudge put a channel chip above it too.
- Center the letters in the fill by their cap height. In Space Grotesk the line box already does this. Space Mono's letters sit 0.0275em below the center of their content area, so inline code moves its fill down by that much (top padding
1px - 0.0275em, bottom1px + 0.0275em). Without it the letters sit about 0.6px low. - Center a leading icon on the letters, not on the box. In a chip in running text the two are the same: the chip is the line box of its letters, with no padding above or below, so the icon centers on the chip (
self-center) and the words keep the baseline.
Chips
A chip is a short run of ink in a fill: a reference in a message, a task chip, a badge, a reaction, a tag in a field. The ink at its two ends sits the same distance from the fill's edges, and its parts center on one line. Padding is only the means: a chip keeps its total padding, and its width, and splits it between the two ends so each end makes up for the empty space its own content brings.
- Measure on the ink, not on the boxes. The eye compares the space from the fill's edge to the first and the last thing drawn: an icon's strokes, a letter's outline, a status pixel's square.
- Give an icon end the same padding as a text end. A Lucide icon leaves 1/24 of its box empty at each side, 0.6px at 14px, about what a letter leaves beside it. A reference chip with an icon once split its 9px as 3px before the icon and 6px after the text: the icon sat 3.6px from the edge and the last letter 7px, and the right end looked empty. It now takes 4.5px at each end.
- Give a mark drawn to its edges the same padding too. A status pixel, an app's icon, an emoji and a status light carry no empty space. Task chips, task statuses and reactions once took 2px less on that end, which left 6px before the pixel and 8.5px after the text; they now split the same padding evenly.
- Chips in a message's text follow the same ends. They share one box (Chips in running text): 6px at each end, and 4.5px at each end with a leading mark, the mark then 4px from the text. The loading spinner and a task's status pixel are drawn to their edges, so each keeps its own box: centered in a 14px icon slot, the spinner's pixels sat 6.75px from the edge against about 4.6px after the last letter.
- A tag with a remove button is the exception. A × sits centered in a button 4px shorter than the chip, 2px from its end, and Lucide draws it 3px inside its box, so its ink ends 6px from the edge of a 20px chip and 12px from a 32px one, against 8.4px before the text. Matching them would take padding the tag doesn't have, or move the button off its 2px inset, so the tag stays as it is.
- Correct a fixed icon that is drawn narrower than its box. A bookmark is drawn 2.3px inside a 14px box and a file 1.75px, so the saved marker and a forwarded file take 5.5px on the icon end and 6.5px on the text end, the same 12px in all. A reference chip can't see which icon it was given: a
#, a pin or a file in one keeps 1px to 2px more on its left. Raft writes a channel's#as text. - Leave letters as they are. Two letters' side bearings differ by up to 1px and change with every word, so text at both ends takes equal padding.
- Center a smaller note on the label's letters. A note in smaller machine type after a chip's label, such as
msgon a link to a message, keeps the label's baseline in the layout and is drawn higher by a quarter of the size difference. Space Grotesk and Space Mono both have a 0.5em x-height, so the middles of the two x-heights meet at every type size. On the shared baseline, an 11px note sat 0.3px low beside a 12.25px label and 0.75px low beside a 14px one, and its descenders made it look lower still. - Keep the label on the sentence's baseline. Never center the whole chip to bring its parts together: the label's words would float 2px above the sentence (Marks in running text). Move only the smaller part.
In raft-ui each chip's recipe holds its padding, and MessageReferenceSuffix is the note after a reference chip's label.
Checking alignment
Whether a row sits on one line is measured, not judged by eye at 1x: a 1px drop is easy to miss on a screen and plain at 3x. scripts/align-audit.mjs measures every docs example on a desktop and on a phone and lists every row with a part 0.75px or more off, with a picture of each.
- Find the rows. A row is an element that lays its children out in a line, centered or on the baseline: a flex or grid row, a chip, a button with an icon, a list row, a menu item, a tab, a toast or banner line, a field's adornments. A part over several lines, such as a title over its subtitle or an avatar beside two rows of a grid, is not on the line.
- Measure each part where the eye sees it. An icon, a pixel or a light by the pixels it draws, from a screenshot with it and without it. Text by the pixels of one flat letter (an H, an E, an x, an n), since its box is not its letters, and its font's metrics for the rest: the baseline, the cap height and the x-height. A shape with words in it, such as a badge, by its box.
- Measure against the row's main text. That is its largest, then boldest, run. An icon or a shape is centered on its cap-height middle. On a line without a fill, such as a sender line or a name and its note, text of every size shares the baseline (Text of different sizes on one line). Inside a chip, smaller text centers its x-height on the main text's, or its cap height when it has no lowercase (Chips).
- Take out the renderer's share. Chromium's rounding moves letters up to 0.5px in their line box (A control and its label). The audit works it out for every run of text, reports it apart and flags only the rest: a row is flagged for its own code, not for the browser.
- Keep inline chips on the sentence. A chip in running text puts its main text on the sentence's baseline (Marks in running text); the audit checks that too.
- Fix the rule, not the row. A flagged row points at the element type that is off, such as a spinner in a reference chip or a note after a label. Correct where that type sits, for every row it appears in, and never its size.
Run it against the docs (pnpm dev) with node scripts/align-audit.mjs --base <docs URL>; --only <path> limits it to some examples. The report lists the rows by component, worst first; each picture draws a thin line through the main text's middle and one through each part's. At the end it lists the marks that sit on a half pixel of their line, for information only: that is not corrected (A control and its label).
Other pages are measured the same way. Pages that render from their URL alone are listed in a JSON file for --pages <file>, each with the element that holds its rows. A product that mounts its pages with its own test fixtures, such as Slock's visual-testing cases, imports the script into its own Playwright run: routePinnedFonts() gives its pages the fonts in design/fonts, and auditPage() measures each one. --reset empties the output before that run and --report-only writes the report after it. A page is measured at its own density; below 2x the pixels the audit reads are too coarse for a 0.75px threshold.
The ends of a header
Every header puts the icon buttons at its two ends the same way: a panel header, a thread, profile or task panel's header, a phone's top bar, a drawer's or a sheet's header, a dialog's ×, the sidebar header, a sidebar section's header (its chevron and its last control, Sidebar) and the right end of the web top bar.
- Put the icon box on the content margin. The first icon box starts and the last one ends on the margin of the column the header sits over, the line the content below starts on: 16px on a phone and with a mouse on a desktop, 20px on a touch screen from 768px, in a dialog as in a column (Spacing).
- Let the hit area hang outward. The rest of the button is empty, so it reaches past the line toward the edge, never inward: a 44px button with a 22px icon overhangs by 11px, a 34px one with an 18px icon by 8px, a head's 28px one with an 18px icon by 5px. It stops at the edge of the screen or the panel; every header margin is wider than the largest overhang, so none is cut today.
- Keep the line at every button size. A head's icon button is 28px with a mouse (a content button 34px) and 44px on a phone or a touch screen, also in the desktop layout (Spacing); only the overhang changes. Never place an edge button by its own edge: a 44px Back at the margin puts its icon 11px inside the content below it, while the ⋮ at the other end, placed by its icon, stays on the line, and the two ends stop mirroring.
- Mirror the two ends. Left and right follow the same rule, so Back and the last button sit at the same distance from their edges.
- Leave shapes and text where they are. A filled button, a sticker or a title at the end of a header lands on the same margin by its edge or its letters (Usage).
- Don't shift a button to match its icon's ink. Every icon has a different amount of space inside its box (an arrow, a gear and a vertical ellipsis differ by up to 9px), so the buttons would move with the icon and the two ends would stop mirroring. The same goes for narrow icons such as the vertical ellipsis.
- Use
arrow-leftfor Back, not a chevron. A chevron's ink fills only the middle of its box and would need a shift of its own; an arrow fills the box like other icons.
A phone's top bar once put its icon boxes 2px outside the margin, 14px from the screen edge, so that a common icon's ink (about 2px inside its box) landed near 16px. That made the phone the only header aligned by ink rather than by icon box, and a touch screen in the desktop layout then had no rule at all: it placed Back by the button's edge, 11px inside the line. One rule by icon box holds on every screen and every button size.
In raft-ui the header owns the margin and each frameless icon button declares how far its icon box sits inside it, (button − icon) / 2; the header pulls its first and last child out by that much (Panel).
Related
- Spacing: the margins and header heights.
- Visual comfort: insets, separators and the rhythm around what lands on these lines.
- Typography: the type scale each line height comes from.
- Forms: how a control, its label and its description go together.
- Iconography: the icon sizes.
- Page structure: one edge per column across a desktop screen.