# Spacing

Consistent spacing for components and layout primitives.

Zenos uses a shared spacing scale to create rhythm within components and across page layouts. The scale follows a 4px base unit and provides enough range for dense controls, content groups, and large structural regions.

Layout primitives accept spacing keys instead of Tailwind utility strings. This keeps responsive props typed and makes spacing decisions consistent at every call site.

## Scale

| Range     | Typical use                                                            |
| --------- | ---------------------------------------------------------------------- |
| `0`–`2`   | Hairline separation, compact icon relationships, and dense controls    |
| `3`–`5`   | Form fields, component content, and closely related groups             |
| `6`–`10`  | Cards, panels, grids, and page-level content groups                    |
| `12`–`24` | Major sections, spacious page regions, and large responsive boundaries |

The ranges are guidance, not component defaults. Start from the relationship between elements and use the smallest value that communicates it clearly.

## Relationships before measurements

Spacing describes how strongly elements belong together. A label sits closer to its control than the field sits to the next field. A card title sits closer to its description than the card sits to neighboring cards.

Use consistent spacing for equivalent relationships. Avoid choosing a new value to solve every individual screen.

## Layout props

`Stack`, `Grid`, `Cluster`, and `FormLayout` expose `gap`. Grid-based primitives also support independent `rowGap` and `columnGap` where the two axes need different rhythm.

```tsx
<Stack gap="4">
  <Header />
  <Content />
</Stack>
```

Structural primitives such as `Stack`, `Section`, `Center`, and `Layout` expose typed padding props where they own the relevant boundary. Prefer those props when spacing is part of the component's structure.

```tsx
<Section padding={{ base: "4", md: "8" }} gap="6">
  <Header />
  <Content />
</Section>
```

## Responsive spacing

Responsive values use the shared [`base`, `sm`, `md`, `lg`, `xl`, and `2xl` breakpoints](/foundations/breakpoints/). Increase space when more room improves hierarchy; do not expand every gap automatically at each breakpoint.

```tsx
<Grid columns={{ base: 1, md: 2 }} gap={{ base: "3", md: "6" }}>
  {children}
</Grid>
```

Object values cascade upward. In this example, `3` applies from the base viewport until `md`, and `6` applies from `md` onward.

## Logical directions

Use logical padding props such as inline start, inline end, block start, and block end when direction matters. Logical spacing follows the document direction automatically and works more reliably for right-to-left interfaces than physical left and right values.

See [RTL](/foundations/rtl/) for application setup, directional icons, portals, keyboard behavior, and a complete testing checklist.

## Component and application spacing

Zenos components own the internal spacing needed for their anatomy and interaction states. Consumers should compose components with layout primitives rather than reaching into internal children with fragile selectors.

Application-specific spacing remains appropriate for unique page composition:

```tsx
<Box className="mt-7 lg:mt-11">
  <ProductSpecificVisualization />
</Box>
```

Use `className` for isolated product needs. When the same relationship repeats, prefer a Zenos layout primitive with a spacing token.

## Guidance

- Use smaller values within a component and larger values between distinct regions.
- Let one parent own the gap between siblings; avoid stacking child margins.
- Prefer `gap` for sibling relationships and padding for container boundaries.
- Keep touch target size separate from visible spacing.
- Test narrow screens, 200% zoom, long labels, and translated content.
- Use `0` intentionally when another visual treatment already communicates grouping.

Spacing should make relationships easier to understand. It should not compensate for unclear hierarchy or unnecessary wrappers.

Source: https://zenos-ui.pages.dev/foundations/spacing/