UI Patterns
Feedback

Animations

Small animations that confirm what just happened — instant press states, an error shake, a like burst, a drawn check — and what research says about each.

Feedback animation answers "did that work?" without words. The research on it is thinner than the number of animation libraries suggests, so each section below separates what was measured from what is convention. Apple's Human Interface Guidelines on motion sum up the stance: "Aim for brevity and precision in feedback animations" and "Add motion purposefully … Don't add motion for the sake of adding motion."

All animations below use the Web Animations API — no library — and do nothing when the user has asked for reduced motion:

Install with the shadcn CLI, or copy the source below.

npx shadcn@latest add https://ui-patterns.stereobooster.com/r/feedback-motion.json
lib/feedback-motion.ts
export function prefersReducedMotion() {
  return (
    typeof matchMedia !== "undefined" &&
    matchMedia("(prefers-reduced-motion: reduce)").matches
  );
}

export function shake(element: Element) {
  if (prefersReducedMotion()) return;
  element.animate(
    [
      { transform: "translateX(0)" },
      { transform: "translateX(-6px)" },
      { transform: "translateX(6px)" },
      { transform: "translateX(-4px)" },
      { transform: "translateX(4px)" },
      { transform: "translateX(-2px)" },
      { transform: "translateX(0)" },
    ],
    { duration: 360, easing: "ease-in-out" },
  );
}

export function pop(element: Element) {
  if (prefersReducedMotion()) return;
  element.animate(
    [
      { transform: "scale(1)" },
      { transform: "scale(1.3)" },
      { transform: "scale(0.95)" },
      { transform: "scale(1)" },
    ],
    { duration: 350, easing: "ease-out" },
  );
}

/**
 * Particles radiating from the centre of `origin`, which must be
 * positioned (`relative`). Particles use `currentColor`.
 */
export function burst(origin: HTMLElement, { count = 8, distance = 20 } = {}) {
  if (prefersReducedMotion()) return;
  for (let i = 0; i < count; i++) {
    const angle = (i / count) * Math.PI * 2;
    const dx = Math.cos(angle) * distance;
    const dy = Math.sin(angle) * distance;
    const particle = document.createElement("span");
    particle.setAttribute("aria-hidden", "true");
    Object.assign(particle.style, {
      position: "absolute",
      left: "50%",
      top: "50%",
      width: "4px",
      height: "4px",
      borderRadius: "9999px",
      background: "currentColor",
      pointerEvents: "none",
    });
    origin.append(particle);
    const animation = particle.animate(
      [
        { transform: "translate(-50%, -50%) scale(1)", opacity: 1 },
        {
          transform: `translate(calc(-50% + ${dx}px), calc(-50% + ${dy}px)) scale(0)`,
          opacity: 0,
        },
      ],
      { duration: 500, easing: "cubic-bezier(0.2, 0.6, 0.3, 1)" },
    );
    animation.onfinish = animation.oncancel = () => particle.remove();
  }
}

/** Draws a path that has `pathLength="1"` and `stroke-dasharray="1"`. */
export function drawStroke(path: SVGPathElement) {
  if (prefersReducedMotion()) {
    path.style.strokeDashoffset = "0";
    return;
  }
  path.animate([{ strokeDashoffset: 1 }, { strokeDashoffset: 0 }], {
    duration: 300,
    easing: "ease-out",
    fill: "forwards",
  });
}

Press feedback: timing beats decoration

The most important feedback animation is the press state, and what matters about it is when its first frame appears, not what it looks like.

Each button shows its pressed state after the given delay. Tap them in turn — on a phone the 150 ms one feels late, and a quick tap only lights it up after your finger has already left.

What the studies measured:

StudyTaskFinding
Kaaresoja (2016), 24 participantsPressing on-screen buttonsVisual feedback should appear 30–85 ms after touch. Below ~32 ms it feels no more immediate; perceived button quality drops at 100–150 ms.
Jota et al. (2013), CHIFinger landing on a touch screenNo participant could detect latency below 20 ms; 85% couldn't tell 40 ms from 1 ms.
Ng et al. (2012), UISTDraggingPeople noticed differences down to ~6 ms on average — dragging is far stricter than tapping.

Kaaresoja's guidelines for the other senses: audio 20–70 ms, vibration 5–50 ms. When feedback is combined, the visual part can arrive later and still feel simultaneous — about 95 ms with a sound, 100 ms with vibration — so pairing a press with a sound buys some slack.

Notes:

  • Show the pressed state on pointer-down with no transition, then animate the release. The demo buttons use duration-0 while pressed and a 200 ms transition back.
  • Delaying touch feedback to tell taps from scrolls costs you. Material's ripple waits 150 ms on touch before starting, which puts its first frame past the point where Kaaresoja's participants rated buttons lower. A quick tap then only gets feedback after the finger has lifted — try the 150 ms button above.
  • Drag targets need the least work per frame. At ~6 ms noticeable differences, the web can't promise "imperceptible", so keep pointer-move handlers minimal and move things with transform.

Error shake

A short horizontal shake on a rejected input — the macOS login window's "no". Try a wrong password, then the right one.

Why this shape of motion works:

  • Starting motion grabs attention; ongoing motion doesn't. Abrams & Christ (2003) found an attention advantage for objects that had just started moving, but none for objects already moving. A single short shake uses that; a looping wiggle doesn't.
  • Small, anchored motion is noticed without being the most distracting. In Bartram, Ware & Calvert (2003) motion was detected far better than colour or shape changes in the periphery (under 2% missed vs up to 25% for colour), and motion that stays in place was rated much less distracting than motion that travels across the screen. A shake is anchored motion.

Notes:

  • The shake is never the message. It's invisible to screen readers and disabled under reduced motion, so the error text sits in an aria-live region and the field gets aria-invalid. Apple: "avoid using it as the only way to communicate important information."
  • Repeat errors need different text. Screen readers don't re-announce an identical live-region string, so the demo adds the attempt number.
  • Once per submit, never per keystroke.
  • Keep the user in place: the demo selects the wrong value so retyping replaces it.
  • If interface sounds are enabled on the Sounds page, the error sound plays with the shake.

Like burst

A pop and a ring of particles when someone likes something. The first post starts already liked — loaded state never animates.

  • Pancakes, but fluffier
  • Why my sourdough failed

Notes:

  • This is delight, not usability, and the evidence is weak. Boyd & Bond (2021) compared the same app with and without micro-interactions (49 participants): the usability score didn't differ significantly (74.5 vs 79.2, p = .37). Some individual "pleasant / likeable" items did, but across 36 items tested without correction, that's partly chance.
  • Animate only the user's own action. Not likes that arrive from the server, not unliking, and never once per item in a bulk action.
  • The burst is a zoom-like onset, the kind Bartram et al. found more distracting — acceptable here because it plays exactly where the user just tapped, as a response, not as an interruption.
  • Unlike is silent: the icon just un-fills.

Success check

A check mark that draws itself once a save completes. The spinner uses the delayed indicator rule: with a 300 ms response there is no spinner at all; with 1200 ms it appears after 500 ms.

Notes:

  • Draw it with stroke-dashoffset. With pathLength="1" the path length is normalised, so the same animation works for any shape.
  • Keep it under ~300 ms — the check confirms, it shouldn't make the user wait. Apple: "Let people cancel motion … don't make people wait for an animation to complete."
  • Announce it too: "Saved" is in a live region next to the icon.

Dialogs and transitions

No study compares fade vs scale vs slide for dialogs specifically. Two studies on transitions give clear direction:

  • Get the new content on screen early. Huhtala et al. (2010) had 26 people compare cross-fade transitions: the one that brought the new image in at 25% of the duration was judged faster in 81–92% of comparisons. "People are not easily tricked — … content appearing late feels slower despite of the animation." Clearing the old view quickly mattered most; the fade-in speed was secondary. A zoom on the outgoing view made late transitions feel slower still.
  • Enter from where it lives. Kraft & Hurtienne (2017) gave 35 people an app with half-second slides between screens arranged in a spatial grid and 35 people the same app with hard cuts. The animated group reconstructed the app's structure with about half the errors (2.4 vs 4.4, large effect), and 57% vs 6% felt they were moving through one continuous space. Task time, workload and UX scores didn't differ — no measured cost, no measured "delight".

Applied to dialogs and sheets:

  • Short and immediate. A fade with a slight scale-up, content visible from the first frames; a faster exit than entrance, since the user asked to leave.
  • Direction matches dismissal. A bottom sheet slides up and is swiped down; Apple: "if someone reveals a view by sliding it down from the top, they don't expect to dismiss the view by sliding it to the side."
  • Small, anchored motion rather than a fly-in from offscreen — traveling motion was the most distracting in Bartram et al.

Reduced motion

Every helper above returns early when prefers-reduced-motion: reduce matches; the state change itself (filled heart, error text, check icon) still happens, so nothing depends on seeing the animation. That covers WCAG 2.3.3 Animation from Interactions.

Further reading

On this page