1. Delta specification
This is a delta specification, meaning that it currently contains only the differences from CSS Animations Level 1 [CSS3-ANIMATIONS]. Once the Level 1 specification is closer to complete, it will be merged with the additions here into a complete level 2 specification.
2. Animations
Changes to any of the animation properties defined in this specification
cause the corresponding CSSAnimation
object and its associated objects
to be updated according to the correspondence between these properties
and Web Animations concepts defined in § 3 Keyframes.
However, if the author modifies the animation using the Web Animations programming interface, the changes from the programming interface take precedence as follows:
-
After a successful call to
setKeyframes()
on theKeyframeEffect
associated with aCSSAnimation
, any subsequent change to matching @keyframes rules or the resolved value of the animation-timing-function property for the target element will not be reflected in that animation.However, if the last matching @keyframes rule is removed the animation must still be canceled.
-
After a successful call to
updateTiming()
on theKeyframeEffect
associated with aCSSAnimation
, for each property included in thetiming
parameter, any subsequent change to a corresponding animation property will not be reflected in that animation.For example, calling
cssAnimation.effect.updateTiming({ duration: 1000 })
would cause subsequent changes to animation-duration to be ignored whilst changes to animation-delay would still be reflected in theKeyframeEffect
's timing. -
After a successful call to
play()
orpause()
on aCSSAnimation
, any subsequent change to the animation-play-state will no longer cause theCSSAnimation
to be played or paused as defined in § 3.5 The animation-play-state property. -
After a successful call to
reverse()
on aCSSAnimation
or after successfully setting thestartTime
on aCSSAnimation
, if, as a result of that call the play state of theCSSAnimation
changes to or from the paused play state, any subsequent change to the animation-play-state will no longer cause theCSSAnimation
to be played or paused as defined in § 3.5 The animation-play-state property.The requirement for a change to or from the paused play state ensures that even after calling
reverse()
or setting thestartTime
on a running animation, the animation continues to observe changes in animation-play-state. -
After successfully setting the
effect
of aCSSAnimation
tonull
or someAnimationEffect
other than the originalKeyframeEffect
, all subsequent changes to animation properties other than animation-name or animation-play-state will not be reflected in that animation. Similarly, any change to matching @keyframes rules will not be reflected in that animation. However, if the last matching @keyframes rule is removed the animation must still be canceled.
Note, the reference to a successful call in the above rules is necessary to ensure that when an exception is thrown by any of these methods, the override behavior is not applied.
2.1. Owning element
The owning element of an animation refers to the element or pseudo-element to which the animation-name property was applied that generated the animation.
If an animation generated using the markup defined in this specification is later disassociated from that markup by an update to the computed value of the animation-name property on the owning element, the animation is disassociated from its owning element (that is, it has no owning element from that point forwards).
In the example below, animation
’s initial owning element is elem
. animation
is disassociated from element
through an update to the computed value of elem
’s animation-name property.
elem. style. animation= 'spin 1s' ; let animation= elem. getAnimations()[ 0 ]; // animation’s owning element is elem elem. style. animation= '' ; // animation no longer has an owning element
Note that although the owning element is often equal to the target element of an animation’s associated effect, this is not always the case. The following example demonstrates some of the situations where these two elements may differ.
elem. style. animation= 'move 1s' ; let animation= elem. getAnimations()[ 0 ]; // animation.effect.target == elem == animation’s owning element animation. effect. target= elem2; // animation.effect.target == elem2 != animation’s owning element animation. effect= null ; // animation.effect?.target is undefined != animation’s owning element
2.2. Animation composite order
Animations generated from the markup defined in this specification have an animation class of ‘CSS Animation’.
CSS Animations with an owning element have a later composite order than CSS Transitions but an earlier composite order than animations without a specific animation class.
Within the set of CSS Animations with an owning element, two animations A and B are sorted in composite order (first to last) as follows:
-
If the owning element of A and B differs, sort A and B by tree order of their corresponding owning elements. With regard to pseudo-elements, the sort order is as follows:
-
element
-
::marker
-
::before
-
any other pseudo-elements not mentioned specifically in this list, sorted in ascending order by the Unicode codepoints that make up each selector
-
::after
-
element children
-
-
Otherwise, sort A and B based on their position in the computed value of the animation-name property of the (common) owning element.
The composite order of CSS Animations without an owning element is based on their position in the global animation list.
This differs from the behavior defined for transitions. We should probably sort transitions first, then animation, then use the global animation list. The reason being that when developer tools etc. hang on to orphaned animations and transitions in order to replay them, they should maintain roughly the same composite order.
CSS Animations generated using the markup defined in this specification are not added to the global animation list when they are created. Instead, these animations are appended to the global animation list at the first moment when they transition out of the idle play state after being disassociated from their owning element. CSS Animations that have been disassociated from their owning element but are still idle do not have a defined composite order.
Note, this behavior relies on the fact that disassociating an animation from its owning element always causes it to enter (or remain) in the idle play state.
3. Keyframes
For a given target (pseudo-)element, element, an animation name, name, and the position of the animation in element’s animation-name list, position, keyframe objects are generated as follows:
-
Let default timing function be the timing function at position position of the resolved value of the animation-timing-function for element, repeating the list as necessary as described in CSS Animations 1 § 3.2 The animation-name property.
-
Let default composite be replace.
-
Find the last @keyframes at-rule in document order with <keyframes-name> matching name.
If there is no @keyframes at-rule with <keyframes-name> matching name, abort this procedure. In this case no animation is generated, and any existing animation matching name is canceled.
-
Let keyframes be an empty sequence of keyframe objects.
-
Let animated properties be an empty set of longhand CSS property names.
-
Perform a stable sort of the keyframe blocks in the @keyframes rule by the offset specified in the keyframe selector, and iterate over the result in reverse applying the following steps:
-
Let keyframe offset be the value of the keyframe selector converted to a value in the range 0 ≤ keyframe offset ≤ 1.
-
Let keyframe timing function be the value of the last valid declaration of animation-timing-function specified on the keyframe block, or, if there is no such valid declaration, default timing function.
-
Let keyframe composite be the value of the last valid declaration of animation-composition specified on the keyframe block, or, if there is no such valid declaration, default composite.
-
After converting keyframe timing function to its canonical form (e.g. such that step-end becomes steps(1, end)) let keyframe refer to the existing keyframe in keyframes with matching keyframe offset, timing function and composite, if any.
If there is no such existing keyframe, let keyframe be a new empty keyframe with offset, keyframe offset, timing function, keyframe timing function, composite, keyframe composite, and prepend it to keyframes.
-
Iterate over all declarations in the keyframe block and add them to keyframe such that:
-
Each shorthand property is expanded to its longhand subproperties.
-
All logical properties are converted to their equivalent physical properties.
-
For any expanded physical longhand properties that appear more than once, only the last declaration in source order is added.
Note, since multiple keyframe blocks may specify the same keyframe offset, and since this algorithm iterates over these blocks in reverse, this implies that if any properties are encountered that have already added at this same keyframe offset, they should be skipped.
-
-
Add each property name that was added to keyframe to animated properties.
-
-
If there is no keyframe in keyframes with offset 0, or if amongst the keyframes in keyframes with offset 0 not all of the properties in animated properties are present,
-
Let initial keyframe be the keyframe in keyframes with offset 0, timing function default timing function and composite default composite.
If there is no such keyframe, let initial keyframe be a new empty keyframe with offset 0, timing function default timing function, composite |default composite, and add it to keyframes after the last keyframe with offset 0.
-
For each property in animated properties that is not present in some other keyframe with offset 0, add the computed value of that property for element to the keyframe.
-
-
Similarly, if there is no keyframe in keyframes with offset 1, or if amongst the keyframes in keyframes with offset 1 not all of the properties in animated properties are present,
-
Let final keyframe be the keyframe in keyframes with offset 1, timing function default timing function and composite default composite.
If there is no such keyframe, let final keyframe be a new empty keyframe with offset 1, timing function default timing function and composite default composite, and add it to keyframes after the last keyframe with offset 1.
-
For each property in animated properties that is not present in some other keyframe with offset 1, add the computed value of that property for element to the keyframe.
-
The above procedure requires iterating over keyframe blocks in reverse. It could be rewritten so this is not required but that will likely change the behavior for some edge cases. We should verify what current implementations do and possible remove the requirement to iterate in reverse.
3.1. The animation-duration property
The animation-duration property specifies the iteration duration of the animation’s associated animation effect.
3.2. The animation-timing-function property
The animation-timing-function is used to determine the timing function applied to each keyframe as defined in § 3 Keyframes.
3.3. The animation-iteration-count property
The animation-iteration-count property specifies the iteration count of the animation’s associated animation effect.
3.4. The animation-direction property
The animation-direction property specifies the playback direction of the animation’s associated animation effect.
3.5. The animation-play-state property
The animation-play-state is used to pause or play the animation.
If at any time, including when the animation is first generated, the resolved value of animation-play-state corresponding to an animation is newly running, the implementation must run the procedure to play an animation for the given animation with the auto-rewind flag set to false.
If at any time, including when the animation is first generated, the resolved value of animation-play-state corresponding to an animation is newly paused, the implementation must run the procedure to pause an animation for the given animation.
The above requirements do not apply if the animation’s play state is being overridden by the Web Animations API as described in § 2 Animations.
3.6. The animation-delay property
The animation-delay property specifies the start delay of the animation’s associated animation effect.
3.7. The animation-fill-mode property
The animation-fill-mode property specifies the fill mode of the animation’s associated animation effect.
3.8. The animation-composition property
Opera?EdgeNone
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The animation-composition property defines the composite operation used when multiple animations affect the same property simultaneously.
Name: | animation-composition |
---|---|
Value: | <single-animation-composition># |
Initial: | replace |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Computed value: | list, each item a keyword as specified |
Canonical order: | per grammar |
Animation type: | not animatable |
<single-animation-composition> = replace | add | accumulate
The values of animation-composition have the meaning defined for the corresponding values of the composite operation defined in Web Animations [WEB-ANIMATIONS].
When specified in a keyframe, animation-composition defines the composite operation to use for each property specified in that keyframe until the next keyframe specifying each property.
@keyframes heartbeat { from { scale: 1; animation-timing-function: ease-out; } 30% { scale: 1.3; } } .heartbeat { animation: heartbeat 0.3s 2s infinite; } @keyframes throb { 50% { scale: 1.8; } } .icon:mouseover { animation: throb 0.4s add; }
If these two animations are applied to the same element, normally only one animation would apply, but by specifying add as the animation-composition on the second animation, the result of the two animations will be combined.
Since CSS Transitions [CSS3-TRANSITIONS] have a lower composite order, it is possible to use animation-composition to combine CSS Animations with underlying transitions as in the following example.
.icon { filter: blur(20px); transition: filter 0.5s; } .icon:hover { filter: blur(0px); animation: brightness-pulse 3s infinite add; } @keyframes brightness-pulse { 0% { scale: 1.1; filter: brightness(130%); } 10% { scale: 1; filter: brightness(100%); } }
Create pictures of these examples and verify they make sense.
3.9. The animation-timeline property
In only one current engine.
Opera?EdgeNone
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The animation-timeline property defines the timeline used with the animation.
Note: This specification does not introduce any syntax to specify animation timelines but instead it is up to others specifications such as Scroll-linked Animations [SCROLL-ANIMATIONS] to do so.
Name: | animation-timeline |
---|---|
Value: | <single-animation-timeline># |
Initial: | auto |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Computed value: | list, each item either a case-sensitive css identifier or the keywords none, auto. |
Canonical order: | per grammar |
Animatable: | no |
<single-animation-timeline> = auto | none | <timeline-name>
The animation-timeline property is similar to properties like animation-name and animation-duration in that it can have one or more values, each one imparting additional behavior to a corresponding animation on the element, with the timelines matched up with animations as described here.
Each value has type <single-animation-timeline>, whose possible values have the following effects:
- auto
-
The animation’s timeline is a
DocumentTimeline
, more specifically the default document timeline. - none
-
The animation is not associated with a timeline.
- <timeline-name>
-
Find the last timeline at-rule in document order with its name matching <timeline-name>. If such a timeline at-rule exists, then the animation’s timeline is a timeline as defined by that rule. Otherwise the animation is not associated with a timeline.
<timeline-name> = <custom-ident> | <string>
Make it easier to use animation-name to select the timeline when animation-timeline is not specified. Allowing animation-name to be used for selecting timeline enables most common animations to have to use a single name for both their keyframes and timeline which is simple and ergonomics. The animation-timeline property gives authors additional control to independently select keyframes and timeline if necessary.
3.10. The animation shorthand property
The animation shorthand property syntax is as follows:
<single-animation> = <time> || <easing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode> || <single-animation-play-state> || [ none | <keyframes-name> ] || <single-animation-timeline>
4. Animation Events
4.1. Event dispatch
Note, this is a more general description of event dispatch than that of CSS Animations Level 1 [CSS3-ANIMATIONS] since it must account for the possibility of animations being seeked or reversed using the Web Animations API [WEB-ANIMATIONS].
The target for a CSS animation event is
the animation’s owning element.
If there is no owning element, no CSS animation events are dispatched
(although the animation playback events defined in Web Animations are still
dispatched at the corresponding CSSAnimation
object).
For the purpose of determining which events to dispatch, the phases defined in the Web Animations model are used. These definitions apply to an animation effect, however, for the purpose of dispatching events, we consider a CSS Animation to have the same phase as its associated effect. For example, a CSS Animation is in the before phase if its associated effect is in the before phase.
A CSS Animation that does not have an associated effect is considered to be in the idle phase if its current time is unresolved, in the before phase if its current time is less than zero, and in the after phase otherwise.
Similarly, subsequent references to the start delay, active duration, current iteration, iteration start, and iteration duration of a CSS animation should be understood to refer to the corresponding properties of the animation’s associated effect.
For calculating the elapsedTime
of each event, the following
definitions are used:
-
interval start =
max(min(-start delay, active duration), 0)
-
interval end =
max(min(associated effect end - start delay, active duration), 0)
Each time a new animation frame is established and the animation does not have a pending play task or pending pause task, the events to dispatch are determined by comparing the animation’s phase before and after establishing the new animation frame as follows:
Change | Events dispatched | Elapsed time (ms) |
---|---|---|
idle or before → active | animationstart
| interval start |
idle or before → after ٭ | animationstart
| interval start |
animationend
| interval end | |
active → before | animationend
| interval start |
active → active and the current iteration of the animation’s associated effect has changed since the previous animation frame | animationiteration
| (See below) † |
active → after | animationend
| interval end |
after → active | animationstart
| interval end |
after → before ٭ | animationstart
| interval end |
animationend
| interval start | |
not idle and not after → idle | animationcancel
| The active time of the animation at the moment it was cancelled calculated using a fill mode of both. |
٭ Where multiple events are listed for a state change, all events are dispatched in the order listed and in immediate succession.
† The elapsed time for
an animationiteration
event is defined as follows:
-
Let previous current iteration be the current iteration from the previous animation frame.
-
If previous current iteration is greater than current iteration, let iteration boundary be
current iteration + 1
, otherwise let it be current iteration. -
The elapsed time is the result of evaluating
(iteration boundary - iteration start) × iteration duration)
.
Since the elapsed time defined in the table and procedure above is
expressed in milliseconds, it must be divided by 1,000 to produce a value in
seconds before being assigned to the elapsedTime
member of
the AnimationEvent
.
5. DOM Interfaces
5.1. The CSSAnimation interface
In all current engines.
Opera?Edge84+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
[Exposed =Window ]interface :
CSSAnimation Animation {readonly attribute CSSOMString animationName ; };
-
In all current engines.
Firefox75+Safari13.1+Chrome84+
Opera?Edge84+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?animationName
, of type CSSOMString, readonly -
The key used to find matching keyframes rules that define the associated effect at the point when the animation was created. This is the value of the animation-name property that caused this object to be generated.
5.2. Requirements on pending style changes
Various operations may affect the computed values of properties on elements. User agents may, as an optimization, defer recomputing these values until it becomes necessary. However, all operations included in programming interface defined in this specification, as well as those operations defined in Web Animations [WEB-ANIMATIONS] that may return objects or animation state defined by this specification, must produce a result consistent with having fully processed any such pending changes to computed values.
elem
is initially updated, a user agent may defer recalculating
the computed value of the animation property.
However, the getAnimations()
method called on elem
is specified by Web Animations and can return CSSAnimation
objects as
defined in this specification.
Hence, as result of the requirements in this section, the user agent must
calculate the updated value of elem
’s animation property and
create the requested CSSAnimation
object before returning its result.
Similarly, reading playState
may depend on pending style
changes.
6. Privacy and Security Considerations
This specification introduces no new privacy or security considerations.