# Motion (/docs/motion)





Motion in the kit comes from a small set of named tokens: six curves picked by the *job* a
transition does, two spring curves, and a five-step duration scale. They live in `theme.css` next
to the colours, so a transition you write in your app moves the same way the kit's own do.

```tsx
<div className="transition-transform ease-emphasized duration-(--duration-slow)" />
```

Every `--ease-*` token is also a Tailwind `ease-*` utility. Durations have no utility namespace in
Tailwind v4, so they're read as a variable: `duration-(--duration-slow)`.

## Curves [#curves]

Press **Play** to race every curve over the same distance and duration. The springs run over their
settle times (see [Springs](#springs)), so they *look* like their designed durations: 400ms, and
450ms for the overshoot. The slow speed multiplies everything by four so you can read the shapes.

<Preview align="block" code="&#x22;<div className=\&#x22;transition-transform ease-standard duration-(--duration-spring)\&#x22; />\n<div className=\&#x22;transition-transform ease-emphasized duration-(--duration-spring)\&#x22; />\n<div className=\&#x22;transition-transform ease-spring duration-(--duration-spring-settle)\&#x22; />&#x22;">
  <CurveRace />
</Preview>

| Token                     | Utility                 | Curve                                | Use it for                                                                                               |
| ------------------------- | ----------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------- |
| `--ease-standard`         | `ease-standard`         | `cubic-bezier(0.2, 0, 0, 1)`         | Colours and fades — the default.                                                                         |
| `--ease-emphasized`       | `ease-emphasized`       | `cubic-bezier(0.32, 0.72, 0, 1)`     | Large travel: a tab indicator sliding across, an image growing into a lightbox.                          |
| `--ease-decelerate`       | `ease-decelerate`       | `cubic-bezier(0.16, 1, 0.3, 1)`      | Transforms that *enter* — a popover or toast arriving. Never opacity.                                    |
| `--ease-accelerate`       | `ease-accelerate`       | `cubic-bezier(0.4, 0, 1, 1)`         | Exits: something leaving speeds up as it goes.                                                           |
| `--ease-anticipate`       | `ease-anticipate`       | `cubic-bezier(0.18, -0.04, 0.55, 1)` | Modal and drawer entrances — a hair of wind-up before they travel.                                       |
| `--ease-overshoot`        | `ease-overshoot`        | `cubic-bezier(0.34, 1.56, 0.64, 1)`  | A one-shot pop past the target and back, like a rating star being picked.                                |
| `--ease-spring`           | `ease-spring`           | `linear(…)`, generated               | Something coming to rest, with no overshoot. Play it over `--duration-spring-settle`.                    |
| `--ease-spring-overshoot` | `ease-spring-overshoot` | `linear(…)`, generated               | A release that carries momentum past its target once. Play it over `--duration-spring-overshoot-settle`. |

### Opacity never takes `--ease-decelerate` [#opacity-never-takes---ease-decelerate]

`--ease-decelerate` is built for things that arrive: it covers about two-thirds of the distance
in the first 15% of the time, then eases into place. On a transform that reads as *fast, then gentle*. On
opacity it reads as a blink — the element is nearly opaque almost at once, and the rest of the
duration is invisible. Fade with `--ease-standard`, even when the transform beside it decelerates.

<Preview align="block" code="&#x22;<div className=\&#x22;transition-opacity ease-standard duration-[800ms]\&#x22; />\n<div className=\&#x22;transition-opacity ease-decelerate duration-[800ms]\&#x22; />&#x22;">
  <FadeComparison />
</Preview>

## Durations [#durations]

| Token                                | Value | Use it for                                                     |
| ------------------------------------ | ----- | -------------------------------------------------------------- |
| `--duration-instant`                 | 100ms | Hover and press feedback, small colour changes.                |
| `--duration-fast`                    | 150ms | Small surfaces appearing and leaving.                          |
| `--duration-normal`                  | 200ms | The default: fades, toggles, most state changes.               |
| `--duration-slow`                    | 300ms | Large travel: a panel, a tab indicator, a morph.               |
| `--duration-spring`                  | 400ms | How long a spring *looks* — the number to design with.         |
| `--duration-spring-settle`           | 588ms | What `--ease-spring` actually plays over. Generated.           |
| `--duration-spring-overshoot-settle` | 653ms | What `--ease-spring-overshoot` actually plays over. Generated. |

Shorter is safer than longer. Exits can be a step faster than the matching entrance — by the time
something is leaving, the user has already moved on.

## Springs [#springs]

The two spring curves aren't hand-tuned beziers: they're a damped spring, solved in closed form and
sampled into a CSS `linear()` timing function. The kit's JavaScript plays the same springs, from
the same presets, and a test fails if the CSS and the JS ever disagree.

| Preset      | Looks like | Settles at | Bounce | CSS tokens                                                       |
| ----------- | ---------- | ---------- | ------ | ---------------------------------------------------------------- |
| `settle`    | 400ms      | 588ms      | 0      | `--ease-spring` + `--duration-spring-settle`                     |
| `overshoot` | 450ms      | 653ms      | 0.18   | `--ease-spring-overshoot` + `--duration-spring-overshoot-settle` |
| `snap`      | 250ms      | 368ms      | 0      | — (JS only)                                                      |

A spring is described by how long it looks and how bouncy it is, the way Apple's
`Spring(duration:bounce:)` and Framer's `visualDuration` describe it, rather than by stiffness and
damping. A bounce of 0 is critically damped — the fastest approach that never overshoots — and
anything above it overshoots once, then settles. A 400ms spring is 98.6% of the way there at
400ms.

The last 1.4% is still motion, though, and it takes a while: a spring creeps into place. So each
spring curve has **two durations**. The perceived one is what you design with
(`--duration-spring`). The settle time is what the `linear()` curve was sampled over, and it is the
only duration that plays it correctly. Pair a spring curve with its `-settle` token, never with
`--duration-spring`:

```tsx
// Looks like 400ms, ends without a snap.
<div className="transition-transform ease-spring duration-(--duration-spring-settle)" />

// Wrong: squeezes the whole curve into 400ms, so it looks like ~270ms.
<div className="transition-transform ease-spring duration-(--duration-spring)" />
```

What CSS can't do is start a spring with momentum. When a drag is released mid-flick, the kit builds the spring with the release velocity and plays
it from JavaScript, so the motion continues out of the hand instead of restarting from rest.

## Reduced motion [#reduced-motion]

When a visitor turns on "Reduce motion" in their OS, every animation in the kit either goes away or
collapses to an instant change. State still changes — a modal still opens, a toast still leaves —
only the motion between the two states is removed. The contract has three parts:

* **CSS transitions** in components carry Tailwind's `motion-reduce:` variant
  (`motion-reduce:transition-none`, `motion-reduce:animate-none`).
* **Enter and exit keyframe animations** (`--animate-*`) are collapsed to a 1ms fade by a block at
  the end of `theme.css`. It's 1ms rather than none so `animationend` still fires and an overlay
  still unmounts. A test fails if a new `--animate-*` token ships without its line in that block.
* **JavaScript motion** checks the setting when it starts. The kit plays its own JS animations at
  0ms rather than skipping them, so the last frame still lands and anything waiting on the motion
  to finish (moving focus, cleaning up) runs exactly as it would have.

For your own JavaScript-driven motion, use [`useReducedMotion`](/docs/hooks/use-reduced-motion):

```tsx
import { useReducedMotion } from '@42-central/ui-react';

const reduced = useReducedMotion();
viewport.scrollBy({ left: delta, behavior: reduced ? 'auto' : 'smooth' });
```

## Reading tokens from JavaScript [#reading-tokens-from-javascript]

The Web Animations API can't take `var(--ease-standard)` as an easing — it wants the value. Read it
off the element's computed style, which also picks up anything a consumer has retuned:

```tsx
const style = getComputedStyle(el);

el.animate(keyframes, {
  duration: Number.parseFloat(style.getPropertyValue('--duration-slow')),
  easing: style.getPropertyValue('--ease-emphasized'),
});
```

This is what the kit does internally, with the token values built in as a fallback for when
`theme.css` isn't loaded.

## Retuning [#retuning]

The tokens are ordinary custom properties on `:root`. Override them there and every transition
that uses them follows — the kit's and yours:

```css
:root {
  --duration-slow: 250ms;
  --ease-emphasized: cubic-bezier(0.3, 0.7, 0, 1);
}
```

Don't hand-edit the two `linear()` spring tokens or their `-settle` durations; they're generated
in pairs. If you replace a spring curve with your own `linear()`, replace its `-settle` duration with
it.
