Home / Learn / How long should a UI animation take?

How long should a UI animation take?

A slow animation feels like a delay, and one that is too fast cannot be seen. Here are practical rules from well-known sources, plus ready CSS variables that keep them in one place.

Steps

  1. Start with the shortest duration that does not feel jarring. Nielsen Norman Group says most UI animations fall between 100 and 500 ms depending on complexity and distance traveled, and that animations are far more often too long than too short.
  2. For simple feedback (a checkbox, a toggle) use about 100 ms. For larger changes such as a modal appearing, 200 to 300 ms can be right (NN/G).
  3. Make entrances slower than exits. As a starting point Material Design 3 suggests 250 to 400 ms for entering the screen, 200 ms for leaving it, and 300 to 500 ms for elements that begin and end on screen.
  4. The more often users see an animation, the shorter and quieter it should be (NN/G). Keep durations in CSS variables so they stay consistent.
  5. Anything that starts automatically and lasts more than 5 seconds must be pausable by the user (WCAG 2.2.2). Respect prefers-reduced-motion by shortening the motion or removing it.

Sources

The code

HTML

<!doctype html>
<html lang="ar" dir="rtl">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Animation durations</title>
<style>
  :root {
    --d-feedback: 100ms;   /* checkbox, toggle (NN/G) */
    --d-exit: 200ms;       /* leaving the screen (M3) */
    --d-enter: 300ms;      /* modal, panel entering (NN/G 200-300, M3 250-400) */
    --ease-out: cubic-bezier(.2, 0, 0, 1);
    --ease-in: cubic-bezier(.3, 0, 1, 1);
  }
  @media (prefers-reduced-motion: reduce) {
    :root { --d-feedback: 0.01ms; --d-exit: 0.01ms; --d-enter: 0.01ms; }
  }
  body { font-family: system-ui, "Segoe UI", Tahoma, sans-serif; display: grid; place-items: center; min-height: 100vh; margin: 0; }
  button { padding: .6rem 1.2rem; font: inherit; cursor: pointer; transition: background-color var(--d-feedback) linear; }
  button:hover { background: #dcd7ff; }
  dialog { border: 0; border-radius: .8rem; padding: 1.5rem; opacity: 0; transform: translateY(12px) scale(.98);
    transition: opacity var(--d-exit) var(--ease-in), transform var(--d-exit) var(--ease-in); }
  dialog[open] { opacity: 1; transform: none; transition-duration: var(--d-enter); transition-timing-function: var(--ease-out); }
  @starting-style { dialog[open] { opacity: 0; transform: translateY(12px) scale(.98); } }
</style>
<button id="open" type="button">افتح النافذة</button>
<dialog id="dlg" aria-labelledby="t">
  <h2 id="t">نافذة تجريبية</h2>
  <form method="dialog"><button>إغلاق</button></form>
</dialog>
<script>
  document.getElementById("open").addEventListener("click", () => document.getElementById("dlg").showModal());
</script>
</html>

Related categories: Hover & Cursor · Scene Transitions