# translateX

> Translates the element along the inline axis using the spacing scale or a raw CSS length.

```ts
import { translateX } from "@sdxc/u/transform";
```

Translates the element along the inline axis using the spacing scale or a
raw CSS length. Composes with every other `transform/` utility, so
`u.translateX()` combined with `u.rotate()` applies both.

## Quick reference

Every documented call, beside the CSS it emits.

| Call | CSS |
| --- | --- |
| `u.translateX(4)` | `css({ "--ui-translate-x": "calc(var(--ui-spacing, 0.25rem) * 4)", transform: "translate(var(--ui-translate-x, 0), var(--ui-translate-y, 0)) ..." })` |

## Examples

### Basic example

Use `translateX(n)` with a step of the spacing scale, like `translateX(2)` or `translateX(6)`, to move an element horizontally:

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

### Using negative values

Pass a negative step, like `translateX(-6)`, to move an element left:

```tsx
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[translateX(-2), ...]}>translateX(-2)</div>
	</div>
	<div mix={[...]}>
		<div mix={[translateX(-6), ...]}>translateX(-6)</div>
	</div>
</div>
```

### Using percentages and lengths

Pass a string for any CSS length; a percentage like `translateX("50%")` is a share of the element's own width:

```tsx
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[translateX("50%"), ...]}>translateX("50%")</div>
	</div>
	<div mix={[...]}>
		<div mix={[translateX("12px"), ...]}>translateX("12px")</div>
	</div>
</div>
```

### Applying on hover

Combine it with `hover()` to nudge part of a button forward. Hover the button to try it:

```tsx
<button type="button" mix={[hover(when("& span", translateX(2))), ...]}>
	Read more <span mix={[inlineBlock(), transition("transform")]}>→</span>
</button>
```

## Using a custom value

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

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

## Applying on a state

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

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

## Responsive design

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

```ts
u.at("md", u.translateX(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
translateX(4)
```

## Signature

```ts
u.translateX(value: SpacingValue)
```
