ποΈ Mastering animation-composition in CSS
π What Is animation-composition?
The animation-composition property controls how multiple animations applied to the same element combine their effects. Instead of one animation overriding the other, you choose whether they should:
- πΉ replace β last animation wins
- πΉ add β animations add together
- πΉ accumulate β animations stack based on iteration count
>>βanimation-composition helps animations work together instead of fighting each other.β
π§© Basic Syntax
Syntax
animation-composition: replace | add | accumulate;π― Values Explained
| Value | Description | Use Case |
|---|---|---|
| replace | Each animation overrides the previous one | Default behavior |
| add | Adds transform or property values together | Use for layered effects like move + spin |
| accumulate | Each iteration accumulates the effect | Useful for incremental buildup animations |
π§ͺ Example Keyframes
Keyframes
@keyframes moveRight {
to { transform: translateX(100px); }
}
@keyframes rotate {
to { transform: rotate(45deg); }
}π¬ Example 1: replace (Default)
replace example
.box {
animation-name: moveRight, rotate;
animation-duration: 1s, 1s;
animation-composition: replace;
}β Only the rotate animation applies because it replaces moveRight.
π¬ Example 2: add (Combine Animations)
add example
.box {
animation-name: moveRight, rotate;
animation-duration: 1s, 1s;
animation-composition: add;
}β Final effect = translate + rotate happening together
β Perfect for combining movement, scaling, and rotation
π¬ Example 3: accumulate (Build Over Time)
accumulate example
.box {
animation-name: moveRight;
animation-duration: 1s;
animation-iteration-count: 5;
animation-composition: accumulate;
}β Each iteration adds 100px to the previous movement
β Final movement after 5 iterations = 500px
π¨ Visual Example: Move + Scale + Rotate Combined
Combined layered animation
@keyframes scaleUp {
to { transform: scale(1.3); }
}
.shape {
animation-name: moveRight, scaleUp, rotate;
animation-duration: 1s, 1s, 1s;
animation-composition: add;
}β Move + Scale + Rotate all apply simultaneously
β¨ Using animation-composition with Shorthand
Shorthand
animation: moveRight 1s, rotate 1s;
animation-composition: add;| Property | Works with composition? |
|---|---|
| motion-related transforms | β Yes |
| opacity/color | β Yes (value stacking depends on property type) |
| layout properties | β οΈ Not recommended β expensive |
π§ Best Practices
- Use add for combining transform-based animations
- Avoid mixing layout-changing properties (width, height) with composition
- Use accumulate for progressive motion like steps or trails
- Test combinations in DevTools Animation panel
- Try to keep animations GPU-friendly (transform + opacity)
π Debugging Tips
- If animations override each other unexpectedly β you're using replace
- If accumulation feels too fast β adjust iteration count or keyframe values
- Use add only when animations logically stack
- Check browser support β some features are very new
π Browser Support
- β Chrome 117+
- β Edge 117+
- β Firefox (not supported yet)
- β οΈ Safari (experimental)
Note
Since animation-composition is new, always provide graceful degradation.
π Helpful Resources
>>βWith animation-composition, animations donβt compete β they collaborate.β β¨