1. What good press feedback looks like
Press feedback is a small scale-down (to around 0.94–0.97) that starts on pointerdown and reverses on pointerup. It tells the user the app received the touch before any network request or route change finishes.
Two details matter more than the exact scale. First, the animation must start on press, not on click, because click only fires after release. Second, keyboard users press buttons with Space and Enter, so the same feedback should run on keydown and keyup.
- Animate transform only. Changing width, padding or font-size moves the layout around the button.
- Keep the scale subtle. Anything below about 0.9 makes the label hard to read mid-press.
- Reset on pointerleave and pointercancel, or the button can stay shrunk after a scroll gesture.
2. The CSS-only version
For many buttons the :active pseudo-class is enough. It needs no JavaScript and works with keyboard activation in most browsers. Its limitation is that a CSS transition restarts its easing curve every time the state flips, so a quick tap shrinks and grows on a fixed curve with no overshoot.
.press {
transition: transform 120ms ease-out;
}
.press:active {
transform: scale(0.96);
}
@media (prefers-reduced-motion: reduce) {
.press {
transition: none;
}
}3. A spring-based press hook
A spring keeps velocity between states. When the user releases mid-press, the button carries its motion back past 1.0 and settles, which reads as physical. The hook below writes the transform directly to the element inside requestAnimationFrame, so React does not re-render on each frame.
Stiffness controls how fast it moves toward the target; damping controls how much it overshoots. 520 and 22 give a quick press with a small bounce on release.
import { useEffect, useRef } from "react";
export function usePressSpring<T extends HTMLElement>(pressedScale = 0.95) {
const ref = useRef<T>(null);
useEffect(() => {
const el = ref.current;
if (!el) return;
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)");
const stiffness = 520;
const damping = 22;
let value = 1, velocity = 0, target = 1, raf = 0, last = 0;
const write = (v: number) => {
el.style.transform = v === 1 ? "" : `scale(${v.toFixed(4)})`;
};
const tick = (now: number) => {
const dt = Math.min(0.032, Math.max(0, now - last) / 1000);
last = now;
velocity += (-stiffness * (value - target) - damping * velocity) * dt;
value += velocity * dt;
if (Math.abs(velocity) < 0.001 && Math.abs(value - target) < 0.001) {
value = target;
velocity = 0;
raf = 0;
write(value);
return;
}
write(value);
raf = requestAnimationFrame(tick);
};
const go = (next: number) => {
target = next;
if (reduce.matches) {
value = next;
write(value);
return;
}
if (!raf) {
last = performance.now();
raf = requestAnimationFrame(tick);
}
};
const down = () => go(pressedScale);
const up = () => go(1);
const keyDown = (e: KeyboardEvent) => {
if ((e.key === " " || e.key === "Enter") && !e.repeat) down();
};
const keyUp = (e: KeyboardEvent) => {
if (e.key === " " || e.key === "Enter") up();
};
el.addEventListener("pointerdown", down);
el.addEventListener("pointerup", up);
el.addEventListener("pointerleave", up);
el.addEventListener("pointercancel", up);
el.addEventListener("keydown", keyDown);
el.addEventListener("keyup", keyUp);
el.addEventListener("blur", up);
return () => {
cancelAnimationFrame(raf);
el.removeEventListener("pointerdown", down);
el.removeEventListener("pointerup", up);
el.removeEventListener("pointerleave", up);
el.removeEventListener("pointercancel", up);
el.removeEventListener("keydown", keyDown);
el.removeEventListener("keyup", keyUp);
el.removeEventListener("blur", up);
};
}, [pressedScale]);
return ref;
}
// Usage
export function SaveButton({ onClick }: { onClick: () => void }) {
const ref = usePressSpring<HTMLButtonElement>();
return (
<button ref={ref} type="button" onClick={onClick} className="rounded-full bg-zinc-900 px-5 py-2.5 text-white">
Save
</button>
);
}4. The same idea in a Kipluo component
Kipluo's Favorite Toggle is a heart button that uses this press-and-release spring plus a small burst and a synthesized pop sound when it turns on. It is free and installs as editable source with npx kipluo add favorite-toggle.
It is a real toggle button: it exposes aria-pressed, works with Space and Enter, and with reduced motion on the springs settle instantly.
// npx kipluo add favorite-toggle
import { useState } from "react";
import { FavoriteToggle } from "@/components/kipluo/favorite-toggle";
export function LikeButton() {
const [liked, setLiked] = useState(false);
return <FavoriteToggle pressed={liked} onPressedChange={setLiked} />;
}Accessibility checklist
Tick each one off as you check your build. Your ticks stay in this browser.
0 of 4 checked
Build it yourself or install it
Build it yourself when
You want a subtle press effect on ordinary buttons. The CSS :active rule or the hook above is enough.
Install Kipluo when
You want a toggle with press spring, a celebratory burst, a matched sound and aria-pressed already wired, in React and Flutter.