# margin

> Applies logical margin using the spacing scale, `"auto"`, or a raw CSS length.

```ts
import { m } from "@sdxc/u/size";
```

Applies logical margin using the spacing scale, `"auto"`, or a raw CSS
length. Follows the same 1/2/4-value logical mapping as `p()` — see
[MDN: logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values).

## Quick reference

Every documented call, beside the CSS it emits.

| Call | CSS |
| --- | --- |
| `u.m(4)` | `css({ margin: "calc(var(--ui-spacing, 0.25rem) * 4)" })` |
| `u.m(4, "auto")` | `css({ marginBlock: "...", marginInline: "auto" })` |

## Examples

### Basic example

Use `m(n)` with a step of the spacing scale, like `m(4)` or `m(8)`, to add margin on every side of an element:

```tsx
<div mix={[...]}>
	<div mix={[m(8), ...]}>m(8)</div>
</div>
```

### Block and inline margin

Pass two values to set the block margin and then the inline margin, like `m(4, 12)`:

```tsx
<div mix={[...]}>
	<div mix={[m(4, 12), ...]}>m(4, 12)</div>
</div>
```

### Each side

Pass four values to set the block-start, inline-end, block-end and inline-start margins in that order, like `m(2, 8, 6, 4)`:

```tsx
<div mix={[...]}>
	<div mix={[m(2, 8, 6, 4), ...]}>m(2, 8, 6, 4)</div>
</div>
```

### Centering with auto

Pass `"auto"` as the inline margin to center an element that has a width, like `m(0, "auto")`:

```tsx
<div mix={[...]}>
	<div mix={[m(0, "auto"), is(64), ...]}>m(0, "auto")</div>
</div>
```

## Using a custom value

Every scale argument also takes a raw CSS value, which passes through untouched.

```ts
u.m("2.75rem")
```

## Applying on a state

Wrap the call in a state utility to scope it to one selector.

```ts
u.hover(u.m(4))
```

## Responsive design

Wrap the call in a container query to scope it to one width.

```ts
u.at("md", u.m(4))
```

## Customizing your theme

### Customizing spacing

Every numeric step multiplies `--ui-spacing`, so redefining it rescales every spacing and sizing utility at once:

```css
:root {
	--ui-spacing: 0.25rem;
}
```

Every call that names the step now reads the new value:

```ts
m(4)
```

## Signature

```ts
u.m(...values: SpacingValue[])
```
