# Spacing

Padding, margin, and the space between children, on the spacing scale.

Source: https://www.zazz.sh/api/utilities/spacing/

A bare number is a step on the spacing scale (`--p: 4` is `4 × --spacing`). The named `--space-*` tokens map to 1, 2, 4, 6, 11, 24, and 40; use the number in `style`. Any length works too. Sides are `t`, `r`, `b`, `l` and set logical properties, so `l` is the right side in a right-to-left document. Margins also take `auto`.

`--space-x` and `--space-y` go on a container and put a margin after each direct child but the last: on the inline end for `x`, the block end for `y`. They take states and breakpoints on the container and need a base (`--space-y: 2; --space-y--md: 4`). A child's own margin utility wins. A nested container on the same axis still gets its parent's margin; its own value spaces its children. Dialogs and popovers keep their own margins. A hidden last child still counts as the last, so the visible one before it keeps its margin, and `flex-direction: row-reverse` puts the margins on the wrong side. In flex and grid, use `--gap`; it wraps cleanly and leaves the children's margins alone.

## Reference

| Utility | Writes | Value | Tiers | Notes |
| --- | --- | --- | --- | --- |
| `--p` | `padding` | scale number or length | breakpoints | works tier-only; `--before-p` / `--after-p` |
| `--px` | `padding-inline` | scale number or length | breakpoints | works tier-only; `--before-px` / `--after-px` |
| `--py` | `padding-block` | scale number or length | breakpoints | works tier-only; `--before-py` / `--after-py` |
| `--pt` | `padding-block-start` | scale number or length | breakpoints | works tier-only; `--before-pt` / `--after-pt` |
| `--pr` | `padding-inline-end` | scale number or length | breakpoints | works tier-only; `--before-pr` / `--after-pr` |
| `--pb` | `padding-block-end` | scale number or length | breakpoints | works tier-only; `--before-pb` / `--after-pb` |
| `--pl` | `padding-inline-start` | scale number or length | breakpoints | works tier-only; `--before-pl` / `--after-pl` |
| `--m` | `margin` | scale number or length | breakpoints | keywords: `auto` |
| `--mx` | `margin-inline` | scale number or length | breakpoints | keywords: `auto` |
| `--my` | `margin-block` | scale number or length | breakpoints | keywords: `auto` |
| `--mt` | `margin-block-start` | scale number or length | breakpoints | keywords: `auto` |
| `--mr` | `margin-inline-end` | scale number or length | breakpoints | keywords: `auto` |
| `--mb` | `margin-block-end` | scale number or length | breakpoints | keywords: `auto` |
| `--ml` | `margin-inline-start` | scale number or length | breakpoints | keywords: `auto` |
| `--space-x` | `margin-inline-end on each direct child but the last` | scale number or length | breakpoints, states |  |
| `--space-y` | `margin-block-end on each direct child but the last` | scale number or length | breakpoints, states |  |

## Examples

```html
<div
  style="
    --display: flex;
    --flex-wrap: wrap;
    --items: start;
    --gap: 6;
  "
>
  <div
    style="
      --p: 2;
      --bg: var(--color-muted);
      --radius: 2.5;
    "
  >
    <div
      data-ui="text-xs"
      style="
        --display: grid;
        --place-items: center;
        --p: 4;
        --aspect: 1;
        --font-weight: strong;
        --text: var(--color-primary-foreground);
        --bg: var(--color-primary);
        --radius: 1.5;
      "
    >
      --p: 2
    </div>
  </div>
  <div
    style="
      --p: 4;
      --bg: var(--color-muted);
      --radius: 2.5;
    "
  >
    <div
      data-ui="text-xs"
      style="
        --display: grid;
        --place-items: center;
        --p: 4;
        --aspect: 1;
        --font-weight: strong;
        --text: var(--color-primary-foreground);
        --bg: var(--color-primary);
        --radius: 1.5;
      "
    >
      --p: 4
    </div>
  </div>
  <div
    style="
      --p: 6;
      --bg: var(--color-muted);
      --radius: 2.5;
    "
  >
    <div
      data-ui="text-xs"
      style="
        --display: grid;
        --place-items: center;
        --p: 4;
        --aspect: 1;
        --font-weight: strong;
        --text: var(--color-primary-foreground);
        --bg: var(--color-primary);
        --radius: 1.5;
      "
    >
      --p: 6
    </div>
  </div>
  <div
    style="
      --p: 11;
      --bg: var(--color-muted);
      --radius: 2.5;
    "
  >
    <div
      data-ui="text-xs"
      style="
        --display: grid;
        --place-items: center;
        --p: 4;
        --aspect: 1;
        --font-weight: strong;
        --text: var(--color-primary-foreground);
        --bg: var(--color-primary);
        --radius: 1.5;
      "
    >
      --p: 11
    </div>
  </div>
</div>
```

```html
<div
  style="
    --display: flex;
    --flex-wrap: wrap;
    --items: start;
    --gap: 6;
  "
>
  <div
    style="
      --p: 6;
      --bg: var(--color-muted);
      --radius: 2.5;
    "
  >
    <div
      data-ui="text-xs"
      style="
        --display: grid;
        --place-items: center;
        --p: 4;
        --aspect: 1;
        --font-weight: strong;
        --text: var(--color-primary-foreground);
        --bg: var(--color-primary);
        --radius: 1.5;
      "
    >
      --p: 6
    </div>
  </div>
  <div
    style="
      --p: 6;
      --pl: 0;
      --bg: var(--color-muted);
      --radius: 2.5;
    "
  >
    <div
      data-ui="text-xs"
      style="
        --display: grid;
        --place-items: center;
        --p: 4;
        --aspect: 1;
        --font-weight: strong;
        --text: var(--color-primary-foreground);
        --bg: var(--color-primary);
        --radius: 1.5;
      "
    >
      --p: 6; --pl: 0
    </div>
  </div>
  <div
    style="
      --p: 6;
      --py: 2;
      --bg: var(--color-muted);
      --radius: 2.5;
    "
  >
    <div
      data-ui="text-xs"
      style="
        --display: grid;
        --place-items: center;
        --p: 4;
        --aspect: 1;
        --font-weight: strong;
        --text: var(--color-primary-foreground);
        --bg: var(--color-primary);
        --radius: 1.5;
      "
    >
      --p: 6; --py: 2
    </div>
  </div>
</div>
```

```html
<div
  style="
    --display: flex-col;
    --gap: 6;
    --w: 100%;
    --max-w: 96;
  "
>
  <div
    style="
      --p: 4;
      --bg: var(--color-muted);
      --radius: 4.5;
    "
  >
    <div
      data-ui="text-sm"
      style="
        --p: 4;
        --mx: auto;
        --w: fit-content;
        --font-weight: strong;
        --text-align: center;
        --text: var(--color-primary-foreground);
        --bg: var(--color-primary);
        --radius: 2.5;
      "
    >
      --mx: auto
    </div>
  </div>
  <div
    style="
      --display: flex;
      --p: 4;
      --gap: 4;
      --bg: var(--color-muted);
      --radius: 4.5;
    "
  >
    <span data-ui="badge" data-badge-variant="muted">start</span>
    <span data-ui="badge" data-badge-variant="primary" style="--ml: auto">--ml: auto</span>
  </div>
</div>
```

```html
<div style="--space-y: 6">
  <div style="--space-y: 2">
    <p>--space-y: 2 puts a margin after each paragraph.</p>
    <p>The last one gets none.</p>
    <p>A child's own margin utility wins.</p>
  </div>
  <div
    style="
      --display: flex;
      --space-x: 2;
      --space-x--md: 4;
    "
  >
    <button type="button" data-ui="button">Save</button>
    <button type="button" data-ui="button" data-button-variant="outline">Cancel</button>
    <button type="button" data-ui="button" data-button-variant="ghost">Help</button>
  </div>
</div>
```
