# Layout and spacing

Spacing is the cheapest way to make a design look calm and deliberate. Most amateur layouts are cramped, inconsistent and aligned to too many edges.

## The spacing scale

A 4px base: **4, 8, 12, 16, 24, 32, 48, 64, 96, 128** (and 160 or 192 for big marketing sections). Use only these values for padding, gaps and margins. The steps get bigger as values grow, so choices between neighbors stay distinct (24 vs 32, not 24 vs 26).

## Proximity

Space tells people what belongs together.

- **Inside < between.** Space within a group should be noticeably smaller than space between groups, about half or less. Heading to its paragraph: 8–12px. Paragraph to the next section's heading: 32–64px.
- **Labels hug their content.** A form label sits 6–8px from its field; fields sit 16–24px apart; groups of fields 32–48px apart.
- **Space before lines.** Try more space before adding a divider or a box. If you still need separation, a single hairline or a background tint usually beats a full card.
- **Start generous, then tighten.** It's easier to see where something feels too loose than to rescue a cramped layout.

## Padding

- Buttons and inputs: horizontal padding about 1.5 to 2× the vertical (10px × 16px; 12px × 20px).
- Cards and panels: 16–24px in apps, 24–40px in marketing.
- Equal padding on all sides of a container unless there's a reason (a header with a divider below it can have less bottom padding).

## Grids and widths

- **Marketing pages**: a 12-column grid, content max width 1120–1280px, gutters 24–32px, side margins 24px on mobile to 64–96px on wide screens.
- **Reading**: 640–720px for article text, wherever it sits on the page.
- **Forms**: one column, 400–560px wide. Two columns only for short related fields (first and last name, city and postcode).
- **App shells**: sidebar 220–280px, top bar 48–64px, content with its own max width so wide monitors don't stretch tables and text endlessly.
- **Don't fill the width just because it's there.** Empty space at the side of a narrow, well-set column looks better than text stretched across 1400px.

## Alignment

- Every element starts on a shared edge or grid column. Count the distinct left edges on a screen and reduce them.
- Align text baselines across columns where they sit side by side.
- **Optical alignment** beats mathematical: nudge play icons right, let quote marks hang, align icons to the cap height of their text, and give round shapes a little more size than squares to look equal.
- Center short, isolated things (a hero headline, an empty state). Left-align everything people read for more than two lines.

## Density

Choose density for the audience and stay consistent:

| Density     | Row / control height | Use for                                |
| ----------- | -------------------- | -------------------------------------- |
| Compact     | 28–32px              | data-heavy tools, expert daily use     |
| Default     | 36–40px              | most apps                              |
| Comfortable | 44–56px              | consumer apps, touch, infrequent tasks |

## Responsive

- Design the narrowest layout first for content apps; it forces the priority list from step 1 into a single column.
- Reflow columns rather than shrinking them: 3 → 2 → 1, sidebars become drawers or tabs.
- Reduce display type with `clamp()`, not body text.
- Touch targets are at least 44×44px, even when the visible element is smaller.
- Common frame widths: 390 (phone), 768 (tablet), 1280–1440 (desktop).

## Composition for interest

Where the direction allows it, these keep layouts from looking like templates:

- **Asymmetric splits**: 5/7, 4/8 or 1/3 instead of halves; text on the narrow side, image or product on the wide side.
- **Scale contrast**: one element much larger than everything else.
- **Varied section rhythm**: a tight grid, then an open single statement, then a full-bleed band. Vary padding too; not every section needs 96px top and bottom.
- **Bento grids only when the content varies.** Cells of different sizes should hold content of different importance, not the same card stretched.
- **Overlap**: an image crossing into the next section, a card overlapping a color band, a headline over a photo edge.
- **Bleed**: images or type cropped by the viewport edge suggest a world beyond the frame.
- **Editorial columns**: a narrow side column for captions, numbers or notes beside the main text.
- **Sticky asides**: an image, a summary or a live preview that stays while its content scrolls.
- **Whitespace as a feature**: a single line of text with a lot of space around it is a strong statement.

## Implementation notes

- Use flexbox and grid with `gap` rather than margins on children; spacing then lives in one place.
- Avoid absolute positioning for layout. Keep it for deliberate overlaps and floating decoration.
- Let content define height. Fixed heights break with real content and translations.
