# var

> Resolves a custom property reference: `var(--{name})`, or with a fallback, `var(--{name}, {fallback})`.

```ts
import { var } from "@sdxc/u/general";
```

Resolves a custom property reference: `var(--{name})`, or with a fallback,
`var(--{name}, {fallback})`. `name` omits the leading `--`, matching
`u.vars()`; the raw string fits anywhere a utility takes a CSS value.

## Quick reference

Every documented call, beside the CSS it emits.

| Call | CSS |
| --- | --- |
| `u.var("sidebar-width")` | `"var(--sidebar-width)"` |
| `u.var("sidebar-width", "18rem")` | `"var(--sidebar-width, 18rem)"` |

## Examples

### Basic example

Use `u.var(name, fallback)` to read a custom property in any utility that takes a CSS value; it is written `u.var` because `var` is a reserved word:

```tsx
<div mix={[hstack({ gap: 4 })]}>
	<aside mix={[is(u.var("sidebar-width", "12rem")), ...]}>sidebar</aside>
	<main mix={[grow(), ...]}>main</main>
</div>
```

### Setting it from a parent

Set the property on an ancestor with `u.vars()` and every `u.var()` below it picks the value up, so one layout adapts by context:

```tsx
<div mix={[...]}>
	<div mix={[hstack({ gap: 4 })]}>
		<aside mix={[is(u.var("sidebar-width", "12rem")), ...]}>12rem</aside>
		<main mix={[grow(), ...]}>main</main>
	</div>
	<div mix={[u.vars({ "sidebar-width": "20rem" }), hstack({ gap: 4 })]}>
		<aside mix={[is(u.var("sidebar-width", "12rem")), ...]}>20rem</aside>
		<main mix={[grow(), ...]}>main</main>
	</div>
</div>
```

## Applying on a state

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

```ts
u.hover(u.var("sidebar-width"))
```

## Responsive design

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

```ts
u.at("md", u.var("sidebar-width"))
```

## Signature

```ts
u.var(name: string, fallback?: string)
```
