Get started
Motion
Ochre moves on ease-out curves: quick to start, gentle to settle, no bounce. Snappy, bouncy and soft share the same shape at 320, 360 and 440 ms, so Tailwind classes, Vue, plain HTML and JavaScript all move the same way, and every component uses them.
Curves
Press Play. Each dot travels the same distance; only the duration changes. The grey one is CSS's plain ease-out for comparison.
snappy
Presses, toggles, indicators
bouncy
Things arriving
soft
Panels, sheets, heights
ease-out
For comparison
The same curves drive CSS, Vue, plain HTML and the Web Animations API.
Principles
Move with purpose
Motion explains where something came from or went. If it doesn't, leave it still.
Fast in, faster out
Entrances take 320 to 440 ms; exits are around 160 ms with an ease-in, because people have already moved on.
Ease out, never bounce
Things start quickly and settle gently. Nothing overshoots or wobbles; movement is short, a few pixels, not a fling.
Calm by default
Snappy for small things, soft for panels, sheets and pages. Bouncy keeps its name for older code but no longer bounces.
Reduced motion means still
With reduced motion on, every duration drops to zero and nothing loops. Everything still works.
Utilities
From ochre-motion.css, imported after the other two Ochre stylesheets. They come with the theme:
@import "tailwindcss";
@import "../styles/ochre.css";
@import "../styles/ochre-tailwind.css";
@import "../styles/ochre-motion.css";
transition-uiColours and shadows change quickly; scale, translate and rotate ride an ease-out. Put it on anything interactive.pressGives a little (scale 0.97) while pressed. Pair it with transition-ui.spring-snappy · spring-bouncy · spring-softEasing and duration together, for your own transition-[…] properties.ease-snappy · ease-bouncy · ease-softJust the easing, when you set the duration yourself.animate-pop-in · animate-rise-in · animate-fade-inEntrances: pops for small things, rises for rows and messages, fades for overlays.animate-blur-inWords or lines that arrive while streaming, such as AI answers.animate-shakeOnce, when something becomes invalid. Never on load.animate-drawStrokes that draw in: ticks and sparklines. Set --draw-length to the path length.animate-pulse-softSkeletons and waiting states. A calm opacity pulse, no shimmer.staggerDelays an animation by --i × 40 ms. Set style="--i: 2" on each item.Helpers
A small module for the movement CSS can't do alone. In React it's @/components/ochre/motion; Vue gets the same as composables and plain HTML as ochre-motion.js.
Indicator
A highlight that glides between items: tabs, segmented controls, menus and pagination use it.
FLIP lists
Items glide to their new places when a list reorders, and new ones pop in. Give each a stable data-flip key.
- Maya Shah
- Sam Okafor
- Lena Fischer
- Tomás Ruiz
- Aiko Mori
- Ravi Nair
Auto height
Wrap content that grows or shrinks, and its height follows with a slower ease-out.
Code
Free for everyone, like the tokens. Installing any component that moves brings it along.
"use client";
import * as React from "react";
// The same ease-out curves as ochre-motion.css, for the Web Animations API (which can't read CSS variables).
export const spring = {
snappy: {
duration: 320,
easing:
"cubic-bezier(0.32, 0.72, 0, 1)",
},
bouncy: {
duration: 360,
easing:
"cubic-bezier(0.22, 1, 0.36, 1)",
},
soft: {
duration: 440,
easing:
"cubic-bezier(0.22, 1, 0.36, 1)",
},
} as const;
export type SpringName = keyof typeof spring;
export function prefersReducedMotion() {
return typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
}
export function useReducedMotion() {
return React.useSyncExternalStore(
(onChange) => {
const query = window.matchMedia("(prefers-reduced-motion: reduce)");
query.addEventListener("change", onChange);
return () => query.removeEventListener("change", onChange);
},
prefersReducedMotion,
() => false,
);
}
// Animates an element with a named curve; resolves when it ends. Does nothing with reduced motion.
export function animate(el: Element, keyframes: Keyframe[] | PropertyIndexedKeyframes, name: SpringName = "snappy", delay = 0) {
if (prefersReducedMotion()) return Promise.resolve();
return el.animate(keyframes, { ...spring[name], delay, fill: "backwards" }).finished.catch(() => undefined);
}
// A highlight that glides between items: tabs, segmented controls, menus, pagination.
// Mark each item with data-indicator="<key>" and render <span style={style} /> inside the container.
// The first measurement jumps into place; later ones slide on the snappy curve.
export function useIndicator<T extends HTMLElement>(activeKey: string | number | null | undefined) {
const ref = React.useRef<T>(null);
const [style, setStyle] = React.useState<React.CSSProperties>({ opacity: 0 });
const placed = React.useRef(false);
React.useLayoutEffect(() => {
const container = ref.current;
if (!container) return;
const measure = () => {
const el = activeKey == null ? null : container.querySelector<HTMLElement>(`[data-indicator="${CSS.escape(String(activeKey))}"]`);
if (!el) {
setStyle((s) => ({ ...s, opacity: 0 }));
return;
}
setStyle({
position: "absolute",
left: 0,
top: 0,
width: el.offsetWidth,
height: el.offsetHeight,
translate: `${el.offsetLeft}px ${el.offsetTop}px`,
opacity: 1,
transition: placed.current
? `translate var(--duration-snappy) var(--ease-snappy), width var(--duration-snappy) var(--ease-snappy), height var(--duration-snappy) var(--ease-snappy), opacity var(--motion-fast) ease-out`
: "none",
});
placed.current = true;
};
measure();
const observer = new ResizeObserver(measure);
observer.observe(container);
return () => observer.disconnect();
}, [activeKey]);
return { ref, style };
}
// Keeps something in the DOM long enough to animate out. Use data-state to style both ends.
export function usePresence(open: boolean, exitMs = 200) {
const [mounted, setMounted] = React.useState(open);
const [state, setState] = React.useState<"open" | "closed">(open ? "open" : "closed");
React.useEffect(() => {
if (open) {
setMounted(true);
const frame = requestAnimationFrame(() => setState("open"));
return () => cancelAnimationFrame(frame);
}
setState("closed");
const timer = setTimeout(() => setMounted(false), prefersReducedMotion() ? 0 : exitMs);
return () => clearTimeout(timer);
}, [open, exitMs]);
return { mounted, state };
}
// Moves list items smoothly when they reorder, appear or disappear (FLIP).
// Give each child data-flip="<stable key>" and pass something that changes when the list does.
export function useFlip<T extends HTMLElement>(deps: React.DependencyList) {
const ref = React.useRef<T>(null);
const last = React.useRef(new Map<string, DOMRect>());
React.useLayoutEffect(() => {
const container = ref.current;
if (!container) return;
const next = new Map<string, DOMRect>();
container.querySelectorAll<HTMLElement>("[data-flip]").forEach((el) => {
const key = el.dataset.flip!;
const rect = el.getBoundingClientRect();
next.set(key, rect);
const prev = last.current.get(key);
if (!prev) {
if (last.current.size) animate(el, [{ opacity: 0, scale: 0.96 }, { opacity: 1, scale: 1 }], "bouncy");
return;
}
const dx = prev.left - rect.left;
const dy = prev.top - rect.top;
if (dx || dy) animate(el, [{ translate: `${dx}px ${dy}px` }, { translate: "0 0" }], "snappy");
});
last.current = next;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
return ref;
}
// Animates its height whenever its content grows or shrinks.
export function AutoHeight({ children, className, spring: name = "soft" }: { children: React.ReactNode; className?: string; spring?: SpringName }) {
const inner = React.useRef<HTMLDivElement>(null);
const [height, setHeight] = React.useState<number | "auto">("auto");
React.useLayoutEffect(() => {
const el = inner.current;
if (!el) return;
const observer = new ResizeObserver(() => setHeight(el.offsetHeight));
observer.observe(el);
return () => observer.disconnect();
}, []);
return (
<div
className={className}
style={{
height,
overflow: "hidden",
transition: `height var(--duration-${name}) var(--ease-${name})`,
}}
>
<div ref={inner}>{children}</div>
</div>
);
}
// Changes a figure a digit at a time. Only the characters that differ move: the old one steps 10px away
// and fades quickly, the new one comes 14px from the other side and settles, 28ms apart from left to
// right. Up when the value rises, down when it falls. A figure of a different length fades in whole
// with the same step. Characters from `quietFrom` on take the subtle colour (decimals).
const STEP_IN = 14;
const STEP_OUT = 10;
const IN_MS = 320;
const OUT_MS = 160;
const GAP_MS = 28;
const EASE_OUT = "cubic-bezier(0.32, 0.72, 0, 1)";
const EASE_IN = "cubic-bezier(0.4, 0, 1, 1)";
const numeric = (text: string) => Number(text.replace(/[^\d.-]/g, "")) || 0;
export function stepFigure(
el: HTMLElement,
text: string,
{ dir, animateIn = false, quietFrom = Infinity }: { dir?: 1 | -1; animateIn?: boolean; quietFrom?: number } = {},
) {
const old = el.dataset.figure ?? null;
if (old === text) return;
el.dataset.figure = text;
const still = prefersReducedMotion();
const up = dir ?? (old !== null && numeric(text) < numeric(old) ? -1 : 1);
const same = old !== null && old.length === text.length;
if (!same) {
el.replaceChildren(
...[...text].map((ch) => {
const cell = document.createElement("span");
cell.style.cssText = "position:relative;display:inline-block;white-space:pre";
cell.append(Object.assign(document.createElement("span"), { textContent: ch }));
return cell;
}),
);
}
const cells = [...el.children] as HTMLElement[];
let k = 0;
[...text].forEach((ch, i) => {
const cell = cells[i];
cell.classList.toggle("text-text-subtle", i >= quietFrom);
if (same && old![i] === ch) return;
const was = same ? (cell.querySelector(":scope > span:not([data-out])") as HTMLElement | null) : null;
const now = same ? Object.assign(document.createElement("span"), { textContent: ch }) : (cell.firstElementChild as HTMLElement);
if (same) cell.append(now);
if (still || (old === null && !animateIn)) return void was?.remove();
const delay = (old === null ? 80 : 0) + k++ * GAP_MS;
now.animate([{ transform: `translateY(${up * STEP_IN}px)`, opacity: 0 }, { transform: "none", opacity: 1 }], {
duration: IN_MS,
delay: delay + (was ? 60 : 0),
easing: EASE_OUT,
fill: "backwards",
});
if (was) {
was.dataset.out = "";
Object.assign(was.style, { position: "absolute", left: "0", top: "0" });
was.animate([{ transform: "none", opacity: 1 }, { transform: `translateY(${-up * STEP_OUT}px)`, opacity: 0 }], {
duration: OUT_MS,
delay,
easing: EASE_IN,
fill: "forwards",
});
// A timer, not onfinish: a paused or hidden timeline must not leave old digits behind.
setTimeout(() => was.remove(), delay + OUT_MS + 40);
}
});
}