Chapter 10: UI Animations Without Performance Jank

Animate smooth, efficient, and accessible


Animation is one of the most powerful tools in your UI toolkit.
It brings interfaces to life, guides attention, communicates feedback.

But bad animation? That just makes your site feel slow, clunky, or broken.

This chapter teaches you how to animate like a pro:


Section 10.1: Don’t Animate Everything, Only Animate What Matters

Good animation:

Bad animation:

Rule: Animate opacity, transform, and scale.
Avoid layout properties unless you absolutely have to.


Section 10.2: How Browsers Handle Animation

There are 3 phases in rendering:

  1. Style: compute styles (CSS rules, selector matching)
  2. Layout: calculate positions and box sizes
  3. Paint & Composite: draw pixels and layer them

GPU-accelerated properties:

These skip layout + paint and go straight to compositing (i.e. fast path).

Layout-triggering properties:

These cause reflow and force the browser to recalculate layout = slow.


Section 10.3: Use transform and opacity Instead

.modal {
  transform: scale(0.9);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.modal.open {
  transform: scale(1);
  opacity: 1;
}

Section 10.4: transition vs @keyframes

transition

button {
  transition: background-color 0.2s ease;
}

@keyframes

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

Use with:

.element {
  animation: fadeIn 0.5s ease forwards;
}

Section 10.5: Easing Functions Matter

Example:

transition: all 300ms cubic-bezier(0.33, 1, 0.68, 1); /* Ease out */

Check easings.net to explore them visually.


Section 10.6: Accessibility: Respect Motion Preferences

Some users experience motion sickness or cognitive overload.

Respect their system preferences:

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

Always include this in your base styles.


Section 10.7: Animate With JavaScript (When Needed)

Use the Web Animations API for:

element.animate([
  { opacity: 0, transform: "scale(0.9)" },
  { opacity: 1, transform: "scale(1)" }
], {
  duration: 300,
  easing: "ease-out",
  fill: "forwards"
});

This runs on a separate thread and doesn’t block the main thread like jQuery used to.


Section 10.8: Performance Debugging

Use Chrome DevTools → Performance tab

Look for:

Also use:


Section 10.9: Real Examples

Animate tooltip

.tooltip {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.tooltip[data-visible="true"] {
  opacity: 1;
  transform: translateY(0);
}

Animate route/page entry

.page-enter {
  animation: fadeIn 300ms ease-out forwards;
}

Loading bar

.loader {
  width: 0;
  height: 4px;
  background: blue;
  animation: loading 2s linear infinite;
}
@keyframes loading {
  0% { width: 0; }
  100% { width: 100%; }
}

Summary


Resources


Coming Up Next

In Chapter 11, we’ll cover building real-world UI components with HTML and CSS only: cards, modals, dropdowns, sliders in the semantic, accessible way.