# aspect-ratio

> Applies `aspect-ratio`, either from a width/height pair or one of the named ratios in `AspectRatioName`.

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

Applies `aspect-ratio`, either from a width/height pair or one of the named
ratios in `AspectRatioName`. Ratios vary too continuously for a full token
family to pay for itself, so only a handful of common shapes get names.

## Quick reference

Every documented call, beside the CSS it emits.

| Call | CSS |
| --- | --- |
| `u.aspect(16, 9)` | `css({ aspectRatio: "16 / 9" })` |
| `u.aspect("square")` | `css({ aspectRatio: "1 / 1" })` |

## Examples

### Basic example

Use `aspect(width, height)` to give an element a fixed aspect ratio, like `aspect(16, 9)` for a video frame:

```tsx
<div mix={[aspect(16, 9), is(80), ...]} />
```

### Named ratios

Pass a name for the common shapes: `"square"`, `"photo"`, `"video"`, `"widescreen"`, `"portrait"` or `"story"`:

```tsx
<div mix={[...]}>
	<div mix={[aspect("square"), is(28), ...]}>square</div>
	<div mix={[aspect("photo"), is(28), ...]}>photo</div>
	<div mix={[aspect("video"), is(28), ...]}>video</div>
	<div mix={[aspect("widescreen"), is(28), ...]}>widescreen</div>
	<div mix={[aspect("portrait"), is(28), ...]}>portrait</div>
	<div mix={[aspect("story"), is(28), ...]}>story</div>
</div>
```

## Applying on a state

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

```ts
u.hover(u.aspect(16, 9))
```

## Responsive design

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

```ts
u.at("md", u.aspect(16, 9))
```

## Signature

```ts
u.aspect(ratio: AspectRatioName)
```
