What are the 15 most common web animation mistakes?
Most motion problems repeat: slowness, annoying motion, broken Arabic, or motion nobody asked for. The 15 mistakes sit in 5 groups, each with a source or note, plus a baseline code that avoids most of them.
Steps
- Performance: (1) Animating layout properties such as width and top instead of
transformandopacity(web.dev). (2) Puttingwill-changeon everything: MDN says use it as a last resort for an existing performance problem, not to anticipate problems. (3) Using setInterval/setTimeout for motion instead of requestAnimationFrame (MDN, CSS and JavaScript animation performance). - Access: (4) Ignoring
prefers-reduced-motion(MDN). (5) Flashing more than three times per second (WCAG 2.3.1). (6) Automatic motion longer than five seconds with no way to stop it (WCAG 2.2.2). - Clarity: (7) Text contrast below 4.5:1 (or 3:1 for large text) (WCAG 1.4.3). (8) Long durations: NN/g says 500 ms starts to feel like a drag and most fall between 100 and 500. (9) Moving numbers without
tabular-nums, so they jitter (MDN). - Arabic and RTL: (10) Splitting Arabic words into letters or adding
letter-spacing, which breaks the joins (MDN). (11) Using left/right instead of logical properties, so motion flips wrongly in RTL (MDN). (12) Forgettinglanganddiron the page (W3C). - Build: (13) Redrawing everything on Canvas every frame instead of pre-rendering repeated shapes on an offscreen canvas (MDN). (14) Hard-coding durations and colors everywhere instead of CSS variables (MDN, custom properties). (15) Using GIF or MP4 for simple vector motion, when LottieFiles says Lottie files are smaller than both (the vendor's claim).
Sources
- web.dev, stick to compositor-only properties: https://web.dev/articles/stick-to-compositor-only-properties-and-manage-layer-count
- MDN, will-change: https://developer.mozilla.org/en-US/docs/Web/CSS/will-change
- MDN, CSS and JavaScript animation performance: https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/CSS_JavaScript_animation_performance
- MDN, prefers-reduced-motion: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
- W3C, Understanding 2.3.1 Three Flashes or Below Threshold: https://www.w3.org/WAI/WCAG22/Understanding/three-flashes-or-below-threshold.html
- W3C, Understanding 2.2.2 Pause, Stop, Hide: https://www.w3.org/WAI/WCAG22/Understanding/pause-stop-hide.html
- W3C, Understanding 1.4.3 Contrast (Minimum): https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html
- NN/g, animation duration: https://www.nngroup.com/articles/animation-duration/
- MDN, font-variant-numeric: https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric
- MDN, letter-spacing: https://developer.mozilla.org/en-US/docs/Web/CSS/letter-spacing
- MDN, CSS logical properties and values: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values
- W3C, html dir: https://www.w3.org/International/questions/qa-html-dir
- MDN, Optimizing canvas: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Optimizing_canvas
- MDN, Using CSS custom properties: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
- LottieFiles, what is Lottie: https://lottiefiles.com/what-is-lottie
The code below fixes most of the first six mistakes in a few lines: transform and opacity only, logical properties, steady-width digits, no letter-spacing on Arabic, variables for timing, and a calm mode.
The code
CSS
/* 1. animate transform and opacity only */
.card{transition:transform .25s ease-out,opacity .25s ease-out}
/* 2. logical properties instead of left/right */
.badge{margin-inline-start:.5rem;padding-inline:.75rem}
/* 3. steady digits so numbers do not jitter */
.stat{font-variant-numeric:tabular-nums}
/* 4. never letter-space Arabic */
:lang(ar){letter-spacing:0}
/* 5. one place for timings */
:root{--t-fast:150ms;--t-base:250ms}
/* 6. calm mode */
@media (prefers-reduced-motion: reduce){
*,*::before,*::after{animation:none !important;transition:none !important;scroll-behavior:auto !important}
}The final "calm mode" pattern (turning off animation and transition) is a common pattern, not a word-for-word recommendation from one source. Test it on your site.
can't find the motion you need? Request it here