No Login Data Private Local Save

animation‑composition Demo - Online Blend Multiple Animations

6
0
0
0

Animation Composition Demo

Explore how animation-composition controls the blending of multiple CSS animations on the same property.

Chrome 112+ Firefox 115+ Safari 16+ Edge 112+
replace
Replace (default)
The last animation overrides all previous ones. Animation A is lost.
-35 0 +35

Only shake is visible — movement range: ±12px

add
Add (blend)
Both animations add together. The ball moves far and shakes simultaneously.
-47 0 +47

Full range: -12 to +82px — both animations combined

accumulate
Accumulate
Values accumulate across iterations. Similar to add but respects fill modes & iteration buildup.
-47 0 +47

Accumulated range: ±47px — builds on previous state

0.3x1x3x
Tip: Click a panel to highlight it
How It Works
replace The last declared animation wins. Earlier animations affecting the same property are overwritten entirely.
add Animation values are summed together. Each animation contributes its delta, producing a combined effect.
accumulate Like add, but values stack across iterations. Ideal for progressive buildup effects with animation-fill-mode.
Frequently Asked Questions
What does animation-composition do?
It controls how multiple CSS animations affecting the same property are combined. By default (replace), the last animation overrides previous ones. With add, values are summed. With accumulate, values build up across iterations — perfect for progressive effects like score counters or layered motion.
When should I use add vs replace?
Use replace when you want a new animation to fully take over (e.g., a hover effect replacing a base animation). Use add when you want animations to cooperate — like combining a slow drift with a rapid tremor, or layering a bounce on top of a pan. This avoids the need to write a single complex keyframe that does everything.
How is accumulate different from add?
Both sum animation values, but accumulate tracks the cumulative total across animation iterations. This matters when using animation-fill-mode: forwards or non-infinite iterations — accumulated values persist and build up. For infinite looping animations (like this demo), add and accumulate appear very similar. The difference becomes clear with finite, non-looping animations.
Does animation-composition work with all CSS properties?
It works with most animatable properties, but is most useful for transform, translate, rotate, scale, and numeric properties like opacity or margin. For color properties or discrete values, the effect is less intuitive. It shines brightest with transform components where you want independent control over different aspects of motion.
Is this supported in all modern browsers?
Yes — as of 2024, all major browsers support animation-composition: Chrome 112+, Firefox 115+, Safari 16+, and Edge 112+. It's safe for production use with a fallback (the default replace behavior applies when unsupported). Always test on your target browser range.
Can I apply different composition modes to different properties in the same animation?
animation-composition applies to the entire animation, not per-property. If you need per-property control, split your effects into separate animations and assign each its own composition mode. For example, one animation for translateX with add, and another for opacity with replace.
What's a practical real-world use case?
Imagine a game character that has a walking bob (slow vertical translateY) and a damage shake (fast horizontal translateX). With animation-composition: add, both animations run independently and combine naturally — the character bobs while shaking when hit. Without it, you'd need to manually merge keyframes, which is brittle and hard to maintain.
How do I check browser support in JavaScript?
Use CSS.supports('animation-composition', 'add') or check the computed style of an element. For a fallback, wrap your add/accumulate rules in a @supports (animation-composition: add) { ... } block so unsupported browsers gracefully degrade to replace behavior.
.my-element {
  /* Apply two animations to the same property */
  animation: driftRight 3s ease-in-out infinite,
           rapidShake 0.4s ease-in-out infinite;
  animation-composition: add; /* replace | add | accumulate */
}