Multiple animations and interpolation
Definition and purpose
Multiple animations may affect different properties or compete on the same property. Each animation contributes an effect to a stack. By default, replacement composition makes a later effect on a property replace the underlying value; add and accumulate are property-dependent alternatives.
Independent effects
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @keyframes fade { from { opacity: 0; } to { opacity: 1; } } @keyframes slide { from { transform: translateX(0px); } to { transform: translateX(40px); } } #a { animation: fade 2s linear -1s paused, slide 2s linear -1s paused; } </style> </head> <body> <div id="a">A</div> <div id="b">B</div> </body></html>Both independent properties reach their halfway values.
Syntax and mental model
Comma-separated animation names and associated lists match by position, with shorter lists repeated as needed. animation-composition: add combines an effect with the underlying value according to the property rules; transform addition is order-sensitive. Numeric values such as opacity can interpolate continuously, while discrete values such as many keyword pairs switch instead of producing intermediate numbers.
Replacement versus addition
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @keyframes shift { from, to { transform: translateX(10px); } } #a, #b { transform: translateX(20px); animation: shift 1s paused; } #b { animation-composition: add; } </style> </head> <body> <div id="a">A</div> <div id="b">B</div> </body></html>A replaces the base transform; B adds the 10px translation to the underlying 20px.
Common mistakes
Do not assume add means numeric addition for every property or equals accumulate. Inspect actual effects; dynamic composition mutation has known environment-specific discrepancies in the reference audit.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Keyframes and animation controls. Next lesson: Reduced motion and motion paths.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Multiple animations and interpolation — knowledge check
Five questions on multiple animations and interpolation.
What is the default composition?
What separates animation names?
Can independent opacity and transform animations coexist?
Does add always mean ordinary numeric addition?
Which type of interpolation switches between values?