Skip to main content
← 🎨 CSS as a design systemΒ·Module B7 Β· Lesson 3
TaskBuild two cards. .card-bad uses transition: left; .card-good uses transition: transform. Both move 100px on hover. .card-bad uses position: relative; left: 0 β†’ left: 100px. .card-good uses transform: translateX(0) β†’ translateX(100px). Demo the difference.

Compositor-only properties: transform, opacity, filter

100 XP7 min
Theory

Why some animations feel buttery, others jank

Browser rendering pipeline: Layout β†’ Paint β†’ Composite. Most CSS property changes trigger Layout (expensive). A few only run on the GPU's compositor (cheap).

Cheap (60fps even on phones):

  • transform β€” translateX/Y, rotate, scale, skew.
  • opacity β€” fade in/out.
  • filter β€” blur, brightness, hue-rotate.

Expensive (drops below 60fps on phones):

  • width, height, margin, padding β€” triggers layout.
  • top, left, right, bottom β€” triggers layout.
  • box-shadow β€” triggers repaint.
  • background-color β€” repaint (lighter than layout, still costs).

The rule

/* BAD β€” left triggers layout on every frame */
.slide { left: 0; transition: left 0.3s; }
.slide:hover { left: 100px; }

/* GOOD β€” translateX runs on the compositor */
.slide { transform: translateX(0); transition: transform 0.3s; }
.slide:hover { transform: translateX(100px); }

ANY property that can be expressed as a transform should be β€” the visual result is identical but the performance is 10Γ— better on mobile.

will-change

.modal { will-change: transform, opacity; }

Hint to the browser: "promote this to its own GPU layer now." Use SPARINGLY β€” applying to many elements wastes memory. Best practice: add will-change only just BEFORE animating, remove after.

πŸ”’

Sign up to start coding

Theory is open to everyone. The interactive editor, live preview, and check are unlocked with a 7-day free trial β€” card required, cancel anytime.

Sign up β€” free trial β†’

First 15 lessons in each track are free. No card needed for those.

← PreviousNext lesson β†’

Get one Python or web tip a day β€” by email

Short, hand-written, no spam. Unsubscribe in one click.