Wed, 27 Jul 2016 07:30:50 +0800
[css-transitions] Specify serialization for timing functions
See thread starting: https://lists.w3.org/Archives/Public/www-style/2016Apr/0107.html
In particular, notice that Edge/Blink/Gecko all serialize 'steps(1)' differently and at least Gecko and Blink differ with regards to how they handle the optional 'end' / 'start' value.
1 <h1>CSS Transitions</h1>
3 <style type="text/css">
4 table.animatable-properties {
5 border-collapse: collapse;
6 }
7 table.animatable-properties td {
8 padding: 0.2em 1em;
9 border: 1px solid black;
10 }
11 div.prod { margin: 1em 2em; }
12 </style>
15 <pre class="metadata">
16 Status: ED
17 Work Status: Refining
18 Shortname: css-transitions
19 Group: csswg
20 Level: 1
21 TR: https://www.w3.org/TR/css3-transitions/
22 Previous version: https://www.w3.org/TR/2013/WD-css3-transitions-20131119/
23 ED: https://drafts.csswg.org/css-transitions/
24 Editor: L. David Baron, Mozilla https://www.mozilla.org/, http://dbaron.org/
25 Editor: Dean Jackson, Apple Inc https://www.apple.com/, dino@apple.com
26 Editor: David Hyatt, Apple Inc https://www.apple.com/, hyatt@apple.com
27 Editor: Chris Marrin, Apple Inc https://www.apple.com/, cmarrin@apple.com
28 Issue Tracking: Bugzilla bugs for this level https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&product=CSS&component=Transitions&resolution=---&status_whiteboard=defer%20to%20level%202&status_whiteboard_type=notregexp
29 Issue Tracking: Bugzilla bugs for all levels https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&product=CSS&component=Transitions&resolution=---
30 Abstract: CSS Transitions allows property changes in CSS values to occur smoothly over a specified duration.
31 Status Text: <strong>This document</strong> is expected to be relatively close to last call. While some issues raised have yet to be addressed, new features are extremely unlikely to be considered for this level. <p>The following behaviors are at risk: <ul><li><a href="#discrete-interpolation-at-risk">Interpolation in steps of property types that cannot be interpolated</a></li></ul>
32 Ignored Terms: float
33 Ignored Vars: x1, x2, y1, y2
34 Link Defaults: css-transforms (property) transform
35 </pre>
36 <pre class="link-defaults">
37 spec:css21; type:property;
38 text:top
39 text:right
40 text:bottom
41 text:left
42 text:margin-top
43 text:margin-right
44 text:margin-bottom
45 text:margin-left
46 text:padding-top
47 text:padding-right
48 text:padding-bottom
49 text:padding-left
50 text:border-top-color
51 text:border-right-color
52 text:border-bottom-color
53 text:border-left-color
54 text:border-top-width
55 text:border-right-width
56 text:border-bottom-width
57 text:border-left-width
58 text:background-color
59 text:background-position
60 text:border-spacing
61 text:width
62 text:height
63 text:min-width
64 text:min-height
65 text:max-width
66 text:max-height
67 text:clip
68 text:letter-spacing
69 text:line-height
70 text:outline-color
71 text:outline-width
72 text:text-indent
73 text:font-size
74 text:font-weight
75 text:vertical-align
76 text:visibility
77 text:word-spacing
78 text:z-index
79 spec:css-color-3;
80 type:property;
81 text:color
82 text:opacity
83 type:value
84 text:green
85 text:blue
86 text:transparent
87 spec:css-values-3; type:type; text:<time>
88 </pre>
89 <!-- FIXME: These overrides aren't great for dev/TR switching -->
90 <pre class="anchors">
91 url: https://www.w3.org/TR/css3-background/#shadow-inset; type: value; for: shadow; text: inset;
92 url: https://www.w3.org/TR/css3-background/#box-shadow-none; type: value; for: shadow; text: none;
93 url: https://www.w3.org/TR/CSS21/visufx.html#propdef-visibility; type: value; for: visibility; text: visible;
94 urlPrefix: https://www.w3.org/TR/css3-color/; type: value;
95 text: transparent
96 text: blue
97 text: green
98 url: http://w3c.github.io/dom/#constructing-events; type: dfn; text: event constructor;
99 url: https://html.spec.whatwg.org/multipage/infrastructure.html#concept-event-dispatch; type: dfn; text: dispatch;
100 </pre>
101 </dl>
103 Introduction {#introduction}
104 ============================
106 <p><em>This section is not normative.</em>
107 <p>
108 This document introduces new CSS features to enable <em>implicit transitions</em>, which describe how CSS properties can be made to change smoothly from one value to another over a given duration.
109 </p>
111 <span id="transitions-">Transitions</span> {#transitions}
112 =========================================================
114 <p>
115 Normally when the value of a CSS property changes, the rendered result is instantly updated, with the affected elements immediately changing from the old property value to the new property value. This section describes a way to specify transitions using new CSS properties. These properties are used to animate smoothly from the old state to the new state over time.
116 </p>
117 <p>
118 For example, suppose that transitions of one second have been defined on the 'left' and
119 'background-color' properties. The following diagram illustrates the effect of updating those properties on an element, in this case moving it to the right and changing the background from red to blue. This assumes other transition parameters still have their default values.
120 </p>
121 <div class="figure">
122 <img src="transition1.png" alt="">
123 </div>
124 <p class="caption">
125 Transitions of 'left' and 'background-color'
126 </p>
127 <p>
128 Transitions are a presentational effect. The <a>computed value</a> of a property transitions over time from the old value to the new value. Therefore if a script queries the <a>computed value</a> of a property (or other data depending on it) as it is transitioning, it will see an intermediate value that represents the current animated value of the property.
129 </p>
130 <p>
131 Only animatable CSS properties can be transitioned. See the table at the end of this document for a list
132 of properties that are animatable.
133 </p>
134 <p>
135 The transition for a property is defined using a number of new properties. For example:
136 </p>
137 <div class="example">
138 <p style="display:none">
139 Example(s):
140 </p>
141 <pre>
142 div {
143 transition-property: opacity;
144 transition-duration: 2s;
145 }
146 </pre>The above example defines a transition on the 'opacity' property that, when a new value is assigned to it, will cause a smooth change between the old value and the new value over a period of two seconds.
147 </div>
148 <p>
149 Each of the transition properties accepts a comma-separated list, allowing multiple transitions to be defined, each acting on a different property. In this case, the individual transitions take their parameters from the same index in all the lists. For example:
150 </p>
151 <div class="example">
152 <p style="display:none">
153 Example(s):
154 </p>
155 <pre>
156 div {
157 transition-property: opacity, left;
158 transition-duration: 2s, 4s;
159 }
161 </pre>This will cause the 'opacity' property to transition over a period of two seconds and the left property to transition over a period of four seconds.
162 </div>
164 <p id="list-matching">
165 In the case where the lists of values in transition properties
166 do not have the same length, the length of the
167 'transition-property' list determines the number of items in
168 each list examined when starting transitions. The lists are
169 matched up from the first value: excess values at the end are
170 not used. If one of the other properties doesn't have enough
171 comma-separated values to match the number of values of
172 'transition-property', the UA must calculate its used value by
173 repeating the list of values until there are enough. This
174 truncation or repetition does not affect the computed value.
175 <span class="note">
176 Note: This is analogous to the behavior of the 'background-*'
177 properties, with 'background-image' analogous to
178 'transition-property'.
179 </span>
180 </p>
182 <div class="example">
183 <p style="display:none">
184 Example(s):
185 </p>
186 <pre>
187 div {
188 transition-property: opacity, left, top, width;
189 transition-duration: 2s, 1s;
190 }
191 </pre>The above example defines a transition on the 'opacity' property of 2 seconds duration, a
192 transition on the 'left' property of 1
193 second duration, a transition on the 'top' property of 2 seconds duration and a
194 transition on the 'width' property of 1
195 second duration.
197 </div>
199 <p>
200 While authors can use transitions to create dynamically changing content,
201 dynamically changing content can lead to seizures in some users.
202 For information on how to avoid content that can lead to seizures, see
203 <a href="https://www.w3.org/TR/WCAG20/#seizure">Guideline 2.3:
204 Seizures:
205 Do not design content in a way that is known to cause seizures</a>
206 ([[WCAG20]]).
207 </p>
209 <span id="the-transition-property-property-">The 'transition-property' Property</span> {#transition-property-property}
210 ----------------------------------------------------------------------------------------------------------------------
212 <p>
213 The 'transition-property' property specifies the name of the CSS property to which the transition is applied.
214 </p>
215 <pre class="propdef">
216 Name: transition-property
217 Value: ''transition-property/none'' | <<single-transition-property>>#
218 Initial: ''transition-property/all''
219 Applies to: all elements, ::before and ::after pseudo elements
220 Inherited: no
221 Animatable: no
222 Percentages: N/A
223 Media: visual
224 Computed value: Same as specified value.
225 Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
226 </pre>
228 <div class="prod">
229 <dfn type id="single-transition-property"><single-transition-property></dfn> = ''transition-property/all'' | <<custom-ident>>;
230 </div>
232 <p>
233 A value of
234 <dfn value for="transition-property">none</dfn>
235 means that no property will transition.
236 Otherwise, a list of properties to be transitioned, or the
237 keyword <dfn value for="transition-property">all</dfn>
238 which indicates that all properties are to be
239 transitioned, is given.
240 </p>
242 <p>
243 If one of the identifiers listed is not a recognized property
244 name or is not an animatable property, the implementation must
245 still start transitions on the animatable properties in the
246 list using the duration, delay, and timing function at their
247 respective indices in the lists for 'transition-duration',
248 'transition-delay', and 'transition-timing-function'. In other
249 words, unrecognized or non-animatable properties must be kept in
250 the list to preserve the matching of indices.
251 </p>
253 <p>
254 The <<custom-ident>> production in <<single-transition-property>>
255 also excludes the keyword ''transition-property/none'',
256 in addition to the keywords always excluded from <<custom-ident>>.
257 This means that
258 ''transition-property/none'', ''inherit'', and ''initial'' are not
259 permitted as items within a list of more that one identifier;
260 any list that uses them is syntactically invalid.
261 </p>
263 <p>
264 For the keyword ''transition-property/all'',
265 or if one of the identifiers listed is a
266 shorthand property, implementations must start transitions for
267 any of its longhand sub-properties that are animatable (or, for
268 ''transition-property/all'', all animatable properties), using the duration, delay,
269 and timing function at the index corresponding to the shorthand.
270 </p>
271 <p>
272 If a property is specified multiple times in the value of
273 'transition-property' (either on its own, via a shorthand that
274 contains it, or via the ''transition-property/all'' value), then the transition that
275 starts uses the duration, delay, and timing function at the
276 index corresponding to the <em>last</em> item in the value of
277 'transition-property' that calls for animating that property.
278 </p>
279 <p class="note">
280 Note: The ''transition-property/all'' value and 'all' shorthand
281 property work in similar ways, so the
282 ''transition-property/all'' value is just like a shorthand that
283 covers all properties.
284 </p>
286 <span id="the-transition-duration-property-">The 'transition-duration' Property</span> {#transition-duration-property}
287 ----------------------------------------------------------------------------------------------------------------------
289 <p>
290 The 'transition-duration' property defines the length of time that a transition takes.
291 </p>
292 <pre class="propdef">
293 Name: transition-duration
294 Value: <<time>>#
295 Initial: ''0s''
296 Applies to: all elements, ::before and ::after pseudo elements
297 Inherited: no
298 Animatable: no
299 Percentages: N/A
300 Media: interactive
301 Computed value: Same as specified value.
302 Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
303 </pre>
304 <p>
305 This property specifies how long the transition from the old value to the new value should take. By default the value is ''0s'', meaning that the transition is immediate (i.e. there will be no animation). A negative value for 'transition-duration' renders the declaration invalid.
306 </p>
308 <span id="transition-timing-function_tag">The 'transition-timing-function' Property</span> {#transition-timing-function-property}
309 ---------------------------------------------------------------------------------------------------------------------------------
311 <p>
312 The 'transition-timing-function' property
313 describes how the intermediate values used during a transition will be
314 calculated. It allows for a transition to change speed over its
315 duration. These effects are commonly called <em>easing</em> functions.
316 In either case, a mathematical function that provides a smooth curve is
317 used.
318 </p>
319 <p>
320 Timing functions are either defined as a stepping function or
321 a <a
322 href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves">cubic
323 Bézier curve</a>.
324 The timing function takes as its input
325 the current elapsed percentage of the transition duration
326 and outputs the percentage of the way the transition is
327 from its start value to its end value.
328 How this output is used is defined by
329 the <a href="#animatable-types">interpolation rules</a>
330 for the value type.
331 </p>
332 <p>
333 A <a href="http://en.wikipedia.org/wiki/Step_function">stepping</a>
334 function is defined by a number that divides the domain of operation
335 into equally sized intervals. Each subsequent interval is a equal step
336 closer to the goal state. The function also specifies whether the
337 change in output percentage happens at the start or end of the
338 interval (in other words, if 0% on the input percentage is the point
339 of initial change).
340 </p>
341 <div class="figure">
342 <img src="step.png" alt="The step timing function splits
343 the function domain into a number of disjoint straight line
344 segments. steps(1, start) is a function whose
345 output value is 1 for all input values. steps(1, end) is a function whose
346 output value is 0 for all input values less than 1, and output
347 is 1 for the input value of 1. steps(3, start) is a function that
348 divides the input domain into three segments, each 1/3 in length,
349 and 1/3 above the previous segment, with the first segment starting
350 at 1/3. steps(3, end) is a function that
351 divides the input domain into three segments, each 1/3 in length,
352 and 1/3 above the previous segment, with the first segment starting
353 at 0.">
354 </div>
355 <p class="caption">
356 Step timing functions
357 </p>
358 <p>
359 A <a
360 href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves">cubic
361 Bézier curve</a> is defined by four control points, P<sub>0</sub>
362 through P<sub>3</sub> (see Figure 1). P<sub>0</sub> and P<sub>3</sub>
363 are always set to (0,0) and (1,1). The 'transition-timing-function' property is used
364 to specify the values for points P<sub>1</sub> and P<sub>2</sub>. These
365 can be set to preset values using the keywords listed below, or can be
366 set to specific values using the ''cubic-bezier()'' function.
367 In the ''cubic-bezier()'' function, P<sub>1</sub> and
368 P<sub>2</sub> are each specified by both an X and Y value.
369 </p>
370 <div class="figure">
371 <img src="TimingFunction.png" alt="The Bézier timing function is a
372 smooth curve from point P0 = (0,0) to point P3 = (1,1). The
373 length and orientation of the line segment P0-P1 determines
374 the tangent and the curvature of the curve at P0 and the
375 line segment P2-P3 does the same at P3.">
376 </div>
377 <p class="caption">
378 Bézier Timing Function Control Points
379 </p>
380 <pre class="propdef">
381 Name: transition-timing-function
382 Value: <<single-transition-timing-function>>#
383 Initial: ''transition-timing-function/ease''
384 Applies to: all elements, ::before and ::after pseudo elements
385 Inherited: no
386 Animatable: no
387 Percentages: N/A
388 Media: interactive
389 Computed value: Same as specified value.
390 Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
391 </pre>
392 <div class="prod">
393 <dfn type id="single-transition-timing-function"><single-transition-timing-function></dfn> = ''ease'' | ''linear'' | ''ease-in'' | ''ease-out'' | ''ease-in-out'' | ''step-start'' | ''step-end'' | <a lt="steps()" function>steps</a>(<<integer>>[, [ ''start'' | ''end'' ] ]?) | <a lt="cubic-bezier()" function>cubic-bezier</a>(<<number>>, <<number>>, <<number>>, <<number>>)
394 </div>
395 <p>
396 The timing functions have the following definitions.
397 </p>
398 <dl dfn-type="value" dfn-for="transition-timing-function, <single-transition-timing-function>">
399 <dt><dfn>ease</dfn></dt>
400 <dd>
401 The ease function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0.25, 0.1, 0.25, 1)</a>.
402 </dd>
403 <dt><dfn>linear</dfn></dt>
404 <dd>
405 The linear function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0, 0, 1, 1)</a>.
406 </dd>
407 <dt><dfn>ease-in</dfn></dt>
408 <dd>
409 The ease-in function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0.42, 0, 1, 1)</a>.
410 </dd>
411 <dt><dfn>ease-out</dfn></dt>
412 <dd>
413 The ease-out function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0, 0, 0.58, 1)</a>.
414 </dd>
415 <dt><dfn>ease-in-out</dfn></dt>
416 <dd>
417 The ease-in-out function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0.42, 0, 0.58, 1)</a>.
418 </dd>
419 <dt><dfn>step-start</dfn></dt>
420 <dd>
421 The step-start function is equivalent to <a lt="steps()" function>steps(1, start)</a>.
422 </dd>
423 <dt><dfn>step-end</dfn></dt>
424 <dd>
425 The step-end function is equivalent to <a lt="steps()" function>steps(1, end)</a>.
426 </dd>
427 <dt><dfn function lt="steps()">steps(<<integer>>[, [ start | end ] ]?)</dfn></dt>
428 <dd>
429 Specifies a stepping function, described above, taking two
430 parameters. The first parameter specifies the number of intervals
431 in the function. It must be a positive integer (greater than 0).
432 The second parameter, which is optional, is
433 either the value <dfn value for="steps()">start</dfn> or <dfn value for="steps()">end</dfn>, and specifies the point
434 at which the change of values occur within the interval.
435 If the second parameter is omitted, it is given the value ''end''.
436 </dd>
437 <dt><dfn function lt="cubic-bezier()">cubic-bezier(<<number>>, <<number>>, <<number>>, <<number>>)</dfn></dt>
438 <dd>
439 Specifies a <a
440 href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve">cubic-bezier
441 curve</a>. The four values specify points P<sub>1</sub> and
442 P<sub>2</sub> of the curve as (<var>x1</var>, <var>y1</var>, <var>x2</var>, <var>y2</var>). Both x values must be
443 in the range [0, 1] or the definition is invalid. The y values can
444 exceed this range.
445 </dd>
446 </dl>
448 ### Serializing a timing function ### {#serializing-a-timing-function}
450 Timing functions are serialized using the common serialization patterns
451 defined in [[CSSOM]] with the following additional requirements:
453 * The keyword values ''ease'', ''linear'', ''ease-in'', ''ease-out'',
454 and ''ease-in-out'' are serialized as-is, that is, they are
455 <em>not</em> converted to the equivalent ''cubic-bezier()''
456 function before serializing.
458 * Step timing functions, whether they are specified using the
459 ''steps()'' function or either of the ''step-start'' or ''step-end''
460 keywords, are serialized as follows:
462 1. If the point at which the value changes is ''end'', serialize
463 as <a lt="steps()" function>steps(<integer>)</a>.
465 2. Otherwise, serialize as <a lt="steps()"
466 function>steps(<integer>, start)</a>.
468 <span id="the-transition-delay-property-">The 'transition-delay' Property</span> {#transition-delay-property}
469 -------------------------------------------------------------------------------------------------------------
471 <p>
472 The 'transition-delay' property defines when the transition will start. It allows a transition to begin execution some some period of time from when it is applied. A 'transition-delay' value of ''0s'' means the transition will execute as soon as the property is changed. Otherwise, the value specifies an offset from the moment the property is changed, and the transition will delay execution by that offset.
473 </p>
474 <p>
475 If the value for 'transition-delay' is a negative time offset then the transition will execute the moment the property is changed, but will appear to have begun execution at the specified offset. That is, the transition will appear to begin part-way through its play cycle. In the case where a transition has implied starting values and a negative 'transition-delay', the starting values are taken from the moment the property is changed.
476 </p>
477 <pre class="propdef">
478 Name: transition-delay
479 Value: <<time>>#
480 Initial: ''0s''
481 Applies to: all elements, ::before and ::after pseudo elements
482 Inherited: no
483 Animatable: no
484 Percentages: N/A
485 Media: interactive
486 Computed value: Same as specified value.
487 Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
488 </pre>
490 <span id="the-transition-shorthand-property-">The 'transition' Shorthand Property</span> {#transition-shorthand-property}
491 -------------------------------------------------------------------------------------------------------------------------
493 <p>
494 The 'transition' shorthand property combines the four properties described above into a single property.
495 </p>
496 <pre class="propdef">
497 Name: transition
498 Value: <<single-transition>>#
499 Initial: see individual properties
500 Applies to: all elements, ::before and ::after pseudo elements
501 Inherited: no
502 Animatable: no
503 Percentages: N/A
504 Media: interactive
505 Computed value: see individual properties
506 Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
507 </pre>
509 <div class="prod">
510 <dfn type id="single-transition"><single-transition></dfn> = [ ''transition-property/none'' | <<single-transition-property>> ] || <<time>> || <<single-transition-timing-function>> || <<time>>
511 </div>
513 <p>
514 Note that order is important within the items in this property:
515 the first value that can be parsed as a time is assigned to the
516 transition-duration,
517 and the second value that can be parsed as a time is assigned to
518 transition-delay.
519 </p>
521 <p>
522 If there is more than one <<single-transition>> in the shorthand,
523 and any of the transitions has
524 ''transition-property/none'' as the <<single-transition-property>>,
525 then the declaration is invalid.
526 </p>
528 Starting of transitions {#starting}
529 ===================================
531 <p>
532 Implementations must maintain a set of
533 <dfn export lt="running transition">running transitions</dfn>,
534 each of which applies to a specific element and non-shorthand
535 property. Each of these transitions also has a
536 <dfn export for="transition">start time</dfn>, <dfn export for="transition">end time</dfn>,
537 <dfn export for="transition">start value</dfn>, <dfn export for="transition">end value</dfn>,
538 <dfn export for="transition">reversing-adjusted start value</dfn>, and <dfn export for="transition">reversing shortening factor</dfn>.
539 Transitions are added to this set as described in this section,
540 and are removed from this set
541 when they <a>complete</a>
542 or when implementations are required to <dfn export for="transition">cancel</dfn> them.
543 <span class="note">
544 For the rationale behind the <a>reversing-adjusted start value</a>
545 and <a>reversing shortening factor</a>, see [[#reversing]].
546 </span>
547 </p>
549 <p>
550 Implementations must also maintain a set of
551 <dfn export lt="completed transition">completed transitions</dfn>,
552 each of which
553 (like <a>running transitions</a>)
554 applies to a specific element and non-shorthand property.
555 <span class="note">
556 This specification maintains the invariant that
557 there is never both a <a>running transition</a> and
558 a <a>completed transition</a> for the same property and element.
559 </span>
560 </p>
562 <p>
563 If an element is no longer in the document,
564 implementations must remove transitions on it
565 from the <a>running transitions</a> and the
566 <a>completed transitions</a>.
567 </p>
569 <div class="note">
571 <p>
572 This set of completed transitions
573 needs to be maintained
574 in order to prevent
575 transitions from repeating themselves in certain cases,
576 i.e., to maintain the invariant
577 that this specification tries to maintain
578 that unrelated style changes do not trigger transitions.
579 </p>
581 <p class="example">
582 An example where maintaining the set of completed transitions
583 is necessary would be a transition on
584 an inherited property,
585 where the parent specifies a transition of that property for
586 a longer duration (say, ''transition: 4s text-indent'')
587 and a child element that inherits the parent's value specifies
588 a transition of the same property for a shorter duration
589 (say, ''transition: 1s text-indent'').
590 Without the maintenance of this set of completed transitions,
591 implementations could start additional transitions on the child
592 after the initial 1 second transition on the child completes.
593 </p>
595 </div>
597 <p>
598 Various things can cause the <a>computed values</a> of properties
599 on an element to change.
600 These include
601 insertion and removal of elements from the document tree
602 (which both changes whether those elements have <a>computed values</a> and
603 can change the styles of other elements through selector matching),
604 changes to the document tree that cause
605 changes to which selectors match elements,
606 changes to style sheets or style attributes,
607 and other things.
608 This specification does not define when <a>computed values</a> are updated,
609 beyond saying that implementations must not
610 use, present, or display something resulting from the CSS
611 cascading, value computation, and inheritance process [[!CSS3CASCADE]]
612 without updating the <a>computed value</a>
613 (which means merely that implementations cannot avoid
614 meeting requirements of this specification
615 by claiming not to have updated the <a>computed value</a>
616 as part of handling a style change).
617 However,
618 when an implementation updates the <a>computed value</a> of a
619 property on an element
620 to reflect one of these changes,
621 or computes the <a>computed value</a> of a property on an element
622 newly added to the document,
623 it must update the <a>computed value</a>
624 for all properties and elements to reflect all
625 of these changes at the same time
626 (or at least it must be undetectable that it was done at a
627 different time).
628 This processing of a set of simultaneous style changes is called a
629 <dfn export>style change event</dfn>.
630 (Implementations typically have a <a>style change event</a> to
631 correspond with their desired screen refresh rate,
632 and when up-to-date computed style or layout information is needed
633 for a script API that depends on it.)
634 </p>
636 <p>
637 Since this specification does not define
638 when a <a>style change event</a> occurs,
639 and thus what changes to computed values are considered simultaneous,
640 authors should be aware that changing any of the transition
641 properties a small amount of time after making a change that
642 might transition can result in behavior that varies between
643 implementations, since the changes might be considered
644 simultaneous in some implementations but not others.
645 </p>
647 <p>
648 When a <a>style change event</a> occurs,
649 implementations must start transitions based on
650 the <a>computed values</a> that changed in that event.
651 If an element is not in the document during that
652 style change even or was not in the document during
653 the previous style change event,
654 then transitions are not started for that element
655 in that style change event.
656 Otherwise,
657 define the <dfn export>before-change style</dfn> as
658 the <a>computed values</a> of all properties on the element as of
659 the previous <a>style change event</a>,
660 except with any styles derived from declarative
661 animations such as CSS Transitions, CSS Animations
662 ([[CSS3-ANIMATIONS]]),
663 and SMIL Animations ([[SMIL-ANIMATION]], [[SVG11]])
664 updated to the current time.
665 Likewise, define the <dfn export>after-change style</dfn> as
666 the <a>computed values</a> of all properties
667 on the element based on the information
668 known at the start of that <a>style change event</a>,
669 but excluding any styles from CSS Transitions in the computation,
670 and inheriting from
671 the <a>after-change style</a> of the parent.
672 </p>
674 <div class="note">
675 <p>
676 Note that this definition of the <a>after-change style</a>
677 means that a single change
678 can start a transition on the same property
679 on both an ancestor element and its descendant element.
680 This can happen when a property change is inherited
681 from one element with 'transition-*' properties
682 that say to animate the changing property
683 to another element with 'transition-*' properties
684 that also say to animate the changing property.
685 </p>
687 <p>
688 When this happens, both transitions will run,
689 and the transition on the descendant will override
690 the transition on the ancestor
691 because of the normal
692 CSS cascading and inheritance rules ([[CSS3CASCADE]]).
693 </p>
695 <p>
696 If the transition on the descendant completes before
697 the transition on the ancestor,
698 the descendant will then resume inheriting
699 the (still transitioning) value from its parent.
700 This effect is likely not a desirable effect,
701 but it is essentially doing what the author asked for.
702 </p>
703 </div>
705 <p>
706 For each element with a <a>before-change style</a> and
707 an <a>after-change style</a>,
708 and each property (other than shorthands),
709 define the <dfn export>matching transition-property value</dfn> as
710 the last value in the
711 'transition-property' in the element's <a>after-change style</a>
712 that matches the property,
713 as described in
714 [[#transition-property-property]].
715 If there is such a value, then corresponding to it, there is
716 a <dfn export>matching transition duration</dfn>,
717 a <dfn export>matching transition delay</dfn>, and
718 a <dfn export>matching transition timing function</dfn>
719 in the values in the <a>after-change style</a> of
720 'transition-duration', 'transition-delay', and 'transition-timing-function'
721 (see <a href="#list-matching">the rules on matching lists</a>).
722 Define the <dfn export for="transition">combined duration</dfn> of the transition
723 as the sum of max(<a>matching transition duration</a>, ''0s'') and
724 the <a>matching transition delay</a>.
725 For each element and property, the implementation must act
726 as follows:
727 </p>
729 <ol>
730 <li>
731 If all of the following are true:
732 <ul>
733 <li>
734 the element does not have
735 a <a>running transition</a> for the property,
736 </li>
737 <li>
738 the <a>before-change style</a> is different from
739 and can be interpolated with
740 the <a>after-change style</a> for that property,
741 </li>
742 <li>
743 the element does not have a <a>completed transition</a>
744 for the property
745 or the <a>end value</a> of the <a>completed transition</a>
746 is different from the <a>after-change style</a> for the property,
747 </li>
748 <li>
749 there is a <a>matching transition-property value</a>, and
750 </li>
751 <li>
752 the <a>combined duration</a> is greater than ''0s'',
753 </li>
754 </ul>
755 then implementations must
756 remove the <a>completed transition</a> (if present) from the set
757 of completed transitions and
758 start a transition whose:
759 <ul>
760 <li>
761 <a>start time</a> is
762 the time of the <a>style change event</a> plus
763 the <a>matching transition delay</a>,
764 </li>
765 <li>
766 <a>end time</a> is
767 the <a>start time</a> plus
768 the <a>matching transition duration</a>,
769 </li>
770 <li>
771 <a>start value</a> is
772 the value of the transitioning property
773 in the <a>before-change style</a>,
774 </li>
775 <li>
776 <a>end value</a> is
777 the value of the transitioning property
778 in the <a>after-change style</a>,
779 </li>
780 <li>
781 <a>reversing-adjusted start value</a> is the same as
782 the <a>start value</a>, and
783 <li>
784 <a>reversing shortening factor</a> is 1.
785 </li>
786 </ul>
787 </li>
788 <li>
789 Otherwise,
790 if the element has a <a>completed transition</a> for the property
791 and the <a>end value</a> of the <a>completed transition</a>
792 is different from the <a>after-change style</a> for the property,
793 then implementations must
794 remove the <a>completed transition</a> from the set of
795 <a>completed transitions</a>.
796 </li>
797 <li>
798 If the element has a <a>running transition</a> or
799 <a>completed transition</a> for the property,
800 and there is <strong>not</strong>
801 a <a>matching transition-property value</a>,
802 then implementations must
803 <a>cancel</a> the <a>running transition</a>
804 or remove the <a>completed transition</a> from the set of
805 <a>completed transitions</a>.
806 </li>
807 <li>
808 If the element has a <a>running transition</a> for the property,
809 there is a <a>matching transition-property value</a>,
810 and the <a>end value</a> of the <a>running transition</a> is
811 <strong>not</strong> equal to the value of the property in the
812 <a>after-change style</a>, then:
813 <ol>
814 <li>
815 If the <a>current value</a> of the property
816 in the <a>running transition</a>
817 is equal to
818 the value of the property in the <a>after-change style</a>,
819 or if these two values cannot be interpolated,
820 then implementations must
821 <a>cancel</a> the <a>running transition</a>.
822 </li>
823 <li>
824 Otherwise, if the <a>combined duration</a> is
825 less than or equal to ''0s'',
826 or if the
827 <a>current value</a> of the property in the <a>running transition</a>
828 cannot be interpolated with
829 the value of the property in the <a>after-change style</a>,
830 then implementations must
831 <a>cancel</a> the <a>running transition</a>.
832 </li>
833 <li>
834 Otherwise, if the <a>reversing-adjusted start value</a>
835 of the <a>running transition</a> is the same as the value of
836 the property in the <a>after-change style</a>
837 <span class="note">(see the
838 <a href="#reversing">section on reversing of
839 transitions</a> for why these case exists)</span>,
840 implementations must
841 <a>cancel</a> the <a>running transition</a> and
842 start a new transition whose:
843 <ul>
844 <li>
845 <a>reversing-adjusted start value</a> is
846 the <a>end value</a> of the
847 <a>running transition</a>
848 <span class="note">(Note: This represents the logical start state of
849 the transition, and allows some calculations to ignore that
850 the transition started before that state was reached, which
851 in turn allows repeated reversals of the same transition to
852 work correctly),</span>
853 <li>
854 <a>reversing shortening factor</a>
855 is the absolute value, clamped to the range [0, 1],
856 of the sum of:
857 <ol>
858 <li>the output of the timing function of the old transition
859 at the time of the <a>style change event</a>,
860 times the <a>reversing shortening factor</a> of the
861 old transition</li>
862 <li>1 minus the <a>reversing shortening factor</a> of
863 the old transition.</li>
864 </ol>
865 <span class="note">Note: This represents the portion of the
866 space between the <a>reversing-adjusted start value</a>
867 and the <a>end value</a> that the old transition has
868 traversed (in amounts of the value, not time), except with the
869 absolute value and clamping to handle timing functions that
870 have y1 or y2 outside the range [0, 1].</span>
871 </li>
872 <li>
873 <a>start time</a> is
874 the time of the <a>style change event</a> plus:
875 <ol>
876 <li>if the <a>matching transition delay</a>
877 is nonnegative,
878 the <a>matching transition delay</a>, or
879 <li>if the <a>matching transition delay</a>
880 is negative,
881 the product of
882 the new transition's
883 <a>reversing shortening factor</a> and
884 the <a>matching transition delay</a>,
885 </ol>
886 </li>
887 <li>
888 <a>end time</a> is
889 the <a>start time</a> plus the product of
890 the <a>matching transition duration</a> and
891 the new transition's <a>reversing shortening factor</a>,
892 </li>
893 <li>
894 <a>start value</a> is
895 the <a>current value</a> of the property
896 in the <a>running transition</a>,
897 </li>
898 <li>
899 <a>end value</a> is
900 the value of the property
901 in the <a>after-change style</a>,
902 </li>
903 </ul>
904 </li>
905 <li>
906 Otherwise, implementations must
907 <a>cancel</a> the <a>running transition</a>
908 and start a new transition whose:
909 <ul>
910 <li>
911 <a>start time</a> is
912 the time of the <a>style change event</a> plus
913 the <a>matching transition delay</a>,
914 </li>
915 <li>
916 <a>end time</a> is
917 the <a>start time</a> plus
918 the <a>matching transition duration</a>,
919 </li>
920 <li>
921 <a>start value</a> is
922 the <a>current value</a> of the property
923 in the <a>running transition</a>,
924 </li>
925 <li>
926 <a>end value</a> is
927 the value of the property
928 in the <a>after-change style</a>,
929 </li>
930 <li>
931 <a>reversing-adjusted start value</a> is the same as
932 the <a>start value</a>, and
933 <li>
934 <a>reversing shortening factor</a> is 1.
935 </li>
936 </ul>
937 </li>
938 </ol>
939 </li>
941 </ol>
943 <div class="note">
944 <p>
945 Note that the above rules mean that
946 when the computed value of an animatable property changes,
947 the transitions that start are based on the
948 values of the 'transition-property', 'transition-duration',
949 'transition-timing-function', and 'transition-delay' properties
950 at the time the animatable property would first have its new
951 computed value.
952 This means that when one of these 'transition-*' properties
953 changes at the same time as
954 a property whose change might transition,
955 it is the <em>new</em> values of the 'transition-*' properties
956 that control the transition.
957 </p>
958 <div class="example" id="manual-reversing-example">
959 <p style="display:none">
960 Example(s):
961 </p>
962 <p>This provides a way for authors to specify different values
963 of the 'transition-*' properties for the “forward”
964 and “reverse” transitions,
965 when the transitions are between two states
966 (but see <a
967 href="#reversing">below</a> for special reversing behavior when
968 an <em>incomplete</em> transition is interrupted). Authors can
969 specify the value of 'transition-duration',
970 'transition-timing-function', or 'transition-delay' in the same
971 rule where they specify the value that triggers the transition,
972 or can change these properties at the same time as they change
973 the property that triggers the transition. Since it's the new
974 values of these 'transition-*' properties that affect the
975 transition, these values will be used for the transitions
976 <em>to</em> the associated transitioning values. For example:
977 </p>
978 <pre>
979 li {
980 transition: background-color linear 1s;
981 background: blue;
982 }
983 li:hover {
984 background-color: green;
985 transition-duration: 2s; /* applies to the transition *to* the :hover state */
986 }</pre>
987 <p>
988 When a list item with these style rules enters the :hover
989 state, the computed 'transition-duration' at the time that
990 'background-color' would have its new value (''green'') is ''2s'',
991 so the transition from ''blue'' to ''green'' takes 2 seconds.
992 However, when the list item leaves the :hover state, the
993 transition from ''green'' to ''blue'' takes 1 second.
994 </p>
995 </div>
996 </div>
998 <p class="note">
999 Note that once the transition of a property has started
1000 (including being in its delay phase),
1001 it continues running based on
1002 the original timing function, duration, and
1003 delay, even if the 'transition-timing-function',
1004 'transition-duration', or 'transition-delay' property changes
1005 before the transition is complete. However, if the
1006 'transition-property' property changes such that the transition
1007 would not have started, the transition stops (and the
1008 property immediately changes to its final value).
1009 </p>
1011 <p class="note">
1012 Note that above rules mean that
1013 transitions do not start when the computed
1014 value of a property changes as a result of declarative animation
1015 (as opposed to scripted animation).
1016 This happens because the before-change style includes up-to-date
1017 style for declarative animations.
1018 </p>
1020 Faster reversing of interrupted transitions {#reversing}
1021 --------------------------------------------------------
1023 <div class="note">
1025 <p>
1026 Many common transitions effects involve transitions between two states,
1027 such as the transition that occurs when the mouse pointer moves
1028 over a user interface element, and then later moves out of that element.
1029 With these effects, it is common for a running transition
1030 to be interrupted before it completes,
1031 and the property reset to the starting value of that transition.
1032 An example is a hover effect on an element,
1033 where a transition starts when the pointer enters the element,
1034 and then the pointer exits the element before the effect has completed.
1035 If the outgoing and incoming transitions
1036 are executed using their specified durations and timing functions,
1037 the resulting effect can be distractingly asymmetric
1038 because the second transition
1039 takes the full specified time to move a shortened distance.
1040 Instead, this specification makes second transition shorter.
1041 </p>
1043 <p>
1044 The mechanism the above rules use to cause this involves the
1045 <a>reversing shortening factor</a> and the
1046 <a>reversing-adjusted start value</a>.
1047 In particular, the reversing behavior is present whenever
1048 the <a>reversing shortening factor</a> is less than 1.
1049 </p>
1051 <p class="note">
1052 Note that these rules do not fully address the problem for
1053 transition patterns that involve more than two states.
1054 </p>
1056 <p class="note">
1057 Note that these rules lead to the entire timing function of the
1058 new transition being used, rather than jumping into the middle
1059 of a timing function, which can create a jarring effect.
1060 </p>
1062 <p class="note">
1063 This was one of several possibilities that was considered by the
1064 working group. See the
1065 <a href="transition-reversing-demo">reversing demo</a>
1066 demonstrating a number of them, leading to a working group
1067 resolution made on 2013-06-07 and edits made on 2013-11-11.
1068 </p>
1070 </div>
1072 Application of transitions {#application}
1073 =========================================
1075 <p>
1076 When a property on an element is undergoing a transition
1077 (that is, when or after the transition has started and before the
1078 <a>end time</a> of the transition)
1079 the transition adds a style called the <dfn export>current value</dfn>
1080 to the CSS cascade
1081 at the level defined for CSS Transitions in [[!CSS3CASCADE]].
1082 </p>
1084 <p class="note">
1085 Note that this means that computed values
1086 resulting from CSS transitions
1087 can inherit to descendants just like
1088 any other computed values.
1089 In the normal case, this means that
1090 a transition of an inherited property
1091 applies to descendant elements
1092 just as an author would expect.
1093 </p>
1095 <p>
1096 Implementations must add this value to the cascade
1097 if and only if
1098 that property is not currently
1099 undergoing a CSS Animation ([[!CSS3-ANIMATIONS]]) on the same element.
1100 </p>
1102 <p class="note">
1103 Note that this behavior of transitions not applying to the cascade
1104 when an animation on the same element and property is running
1105 does not affect whether the transition has started or ended.
1106 APIs that detect whether transitions are running
1107 (such as <a href="#transition-events">transition events</a>)
1108 still report that a transition is running.
1109 </p>
1111 <p>
1112 If the current time is at or before the
1113 <a>start time</a> of the transition
1114 (that is, during the delay phase of the transition),
1115 the <a>current value</a> is a specified style that will compute
1116 to the <a>start value</a> of the transition.
1117 </p>
1119 <p>
1120 If the current time is after the
1121 <a>start time</a> of the transition
1122 (that is, during the duration phase of the transition),
1123 the <a>current value</a> is a specified style that will compute
1124 to the <a href="#animatable-types">result of interpolating the property</a>
1125 using the <a>start value</a> of the transition as
1126 <var>V</var><sub>start</sub>,
1127 using the <a>end value</a> of the transition as
1128 <var>V</var><sub>end</sub>,
1129 and using (current time - start time) / (end time - start time)
1130 as the input to the timing function.
1131 </p>
1133 Completion of transitions {#complete}
1134 =====================================
1136 <p>
1137 <a>Running transitions</a>
1138 <dfn export for="transition" id="dfn-complete">complete</dfn>
1139 at a time that equal to or after their end time,
1140 but prior to to the first <a>style change event</a>
1141 whose time is equal to or after their <a>end time</a>.
1142 When a transition completes,
1143 implementations must move
1144 all transitions that complete at that time
1145 from the set of <a>running transitions</a>
1146 to the set of <a>completed transitions</a>
1147 and then fire the <a href="#transition-events">events</a>
1148 for those completions.
1149 <span class="note">(Note that doing otherwise, that is,
1150 firing some of the events before doing all of the moving
1151 from <a>running transitions</a> to <a>completed transitions</a>,
1152 could allow
1153 a style change event to happen
1154 without the necessary transitions completing,
1155 since firing the event could cause a style change event,
1156 if an event handler requests up-to-date computed style or
1157 layout data.)</span>
1158 </p>
1160 <span id="transition-events-">Transition Events</span> {#transition-events}
1161 ===========================================================================
1162 <p>
1163 The completion of a CSS Transition generates a corresponding <a href="https://www.w3.org/TR/DOM-Level-2-Events/events.html">DOM Event</a>.
1164 An event is <a>dispatched</a> to the element
1165 for each property that undergoes a transition on that element.
1166 This allows a content developer to perform actions that synchronize
1167 with the completion of a transition.
1168 </p>
1169 <p>
1170 Each event provides the name of the property the transition is
1171 associated with as well as the duration of the transition.
1172 </p>
1173 <dl>
1174 <dt>
1175 <b>Interface <dfn interface id="Events-TransitionEvent">TransitionEvent</dfn></b>
1176 </dt>
1177 <dd>
1178 <p>
1179 The {{TransitionEvent}} interface provides specific contextual information associated with transitions.
1180 </p>
1181 <dl>
1182 <dt>
1183 <b>IDL Definition</b>
1184 </dt>
1185 <dd>
1186 <div class='idl-code'>
1187 <pre class='idl'>
1188 [Constructor(DOMString type, optional TransitionEventInit transitionEventInitDict)]
1189 interface TransitionEvent : Event {
1190 readonly attribute DOMString propertyName;
1191 readonly attribute float elapsedTime;
1192 readonly attribute DOMString pseudoElement;
1193 };
1195 dictionary TransitionEventInit : EventInit {
1196 DOMString propertyName = "";
1197 float elapsedTime = 0.0;
1198 DOMString pseudoElement = "";
1199 };
1200 </pre>
1201 </div>
1202 </dd>
1203 <dt>
1204 <b>Attributes</b>
1205 </dt>
1206 <dd>
1207 <dl>
1208 <dt>
1209 <code class='attribute-name'><dfn attribute for="TransitionEvent" id="Events-TransitionEvent-propertyName">propertyName</dfn></code> of type <code>DOMString</code>, readonly
1210 </dt>
1211 <dd>
1212 The name of the CSS property associated with the transition.
1213 </dd>
1214 </dl>
1215 <dl>
1216 <dt>
1217 <code class='attribute-name'><dfn attribute for="TransitionEvent" id="Events-TransitionEvent-elapsedTime">elapsedTime</dfn></code> of type <code>float</code>, readonly
1218 </dt>
1219 <dd>
1220 The amount of time the transition has been running, in seconds, when this event fired. Note that this value is not affected by the value of <code class="property">transition-delay</code>.
1221 </dd>
1222 </dl>
1223 <dl>
1224 <dt>
1225 <code class='attribute-name'><dfn attribute for="TransitionEvent" id="Events-TransitionEvent-pseudoElement">pseudoElement</dfn></code> of type <code>DOMString</code>, readonly
1226 </dt>
1227 <dd>
1228 The name (beginning with two colons) of the CSS
1229 pseudo-element on which the transition occurred (in
1230 which case the target of the event is that
1231 pseudo-element's corresponding element), or the empty
1232 string if the transition occurred on an element (which
1233 means the target of the event is that element).
1234 </dd>
1235 </dl>
1236 </dd>
1237 </dl>
1238 <p>
1239 <code id="TransitionEvent-constructor">TransitionEvent(type, transitionEventInitDict)</code>
1240 is an <a>event constructor</a>.
1241 </p>
1242 </dd>
1243 </dl>
1244 <p>
1245 There is one type of transition event available.
1246 </p>
1247 <dl>
1248 <dt>
1249 <b><dfn event for="Element" id="transitionend">transitionend</dfn></b>
1250 </dt>
1251 <dd>
1252 The {{transitionend}} event occurs at the completion of the transition. In the
1253 case where a transition is removed before completion, such as if the
1254 transition-property is removed, then the event will not fire.
1255 <ul>
1256 <li>Bubbles: Yes
1257 </li>
1258 <li>Cancelable: No
1259 </li>
1260 <li>Context Info: propertyName, elapsedTime, pseudoElement
1261 </li>
1262 </ul>
1263 </dd>
1264 </dl>
1266 <span id="animation-of-property-types-">Animation of property types</span> {#animatable-types}
1267 ==============================================================================================
1269 <p>
1270 Some property types can be interpolated,
1271 which means they can animate smoothly from one value to another.
1272 Other property types cannot, and thus animate only in a single
1273 step from one value to the other.
1274 </p>
1276 Animation of interpolated property types {#interpolated-types}
1277 --------------------------------------------------------------
1279 <p>
1280 When interpolating between two values,
1281 <var>V</var><sub>start</sub> and <var>V</var><sub>end</sub>,
1282 interpolation is done using the output <var>p</var> of the timing function,
1283 which gives the portion of the value space
1284 that the interpolation has crossed.
1285 Thus the result of the interpolation is
1286 <var>V</var><sub>res</sub> =
1287 (1 - <var>p</var>) ⋅ <var>V</var><sub>start</sub> +
1288 <var>p</var> ⋅ <var>V</var><sub>end</sub>.
1289 </p>
1291 <p>
1292 However, if this value (<var>V</var><sub>res</sub>)
1293 is outside the allowed range of values for the property,
1294 then it is clamped to that range.
1295 This can occur if <var>p</var> is outside of the range 0 to 1,
1296 which can occur if a timing function is specified
1297 with a <var>y1</var> or <var>y2</var> that is outside the range 0 to 1.
1298 </p>
1300 <p>
1301 The following describes how each property type undergoes transition or
1302 animation.
1303 </p>
1305 <ul>
1306 <li id="animtype-color">
1307 <strong>color</strong>: interpolated via red, green, blue and alpha
1308 components (treating each as a number, see below).
1309 The interpolation is done between premultiplied colors
1310 (that is, colors for which the red, green, and blue components
1311 specified have been multiplied by the alpha).
1312 </li>
1313 <li id="animtype-length">
1314 <strong>length</strong>: interpolated as real numbers.
1315 </li>
1316 <li id="animtype-percentage">
1317 <strong>percentage</strong>: interpolated as real numbers.
1318 </li>
1319 <li id="animtype-lpcalc">
1320 <strong>length, percentage, or calc</strong>: when both values
1321 are lengths, interpolated as lengths; when both values are
1322 percentages, interpolated as percentages; otherwise, both
1323 values are converted into a ''calc()'' function that is the
1324 sum of a length and a percentage (each possibly zero), and
1325 these ''calc()'' functions have each half interpolated as real
1326 numbers.
1327 </li>
1328 <li id="animtype-integer">
1329 <strong>integer</strong>: interpolated via discrete steps (whole
1330 numbers). The interpolation happens in real number space and is
1331 converted to an integer by rounding to the nearest integer, with
1332 values halfway between a pair of integers rounded towards
1333 positive infinity.
1334 </li>
1335 <li id="animtype-font-weight">
1336 <strong>font weight</strong>: interpolated via discrete steps
1337 (multiples of 100). The interpolation happens in real number
1338 space and is converted to an integer by rounding to the
1339 nearest multiple of 100, with values halfway between multiples
1340 of 100 rounded towards positive infinity.
1341 </li>
1342 <li id="animtype-number">
1343 <strong>number</strong>: interpolated as real (floating point)
1344 numbers.
1345 </li>
1346 <li id="animtype-rect">
1347 <strong>rectangle</strong>: interpolated via the x, y,
1348 width and height components (treating each as a number).
1349 </li>
1350 <li id="animtype-visibility">
1351 <strong>visibility</strong>: if one of the values is
1352 ''visibility/visible'', interpolated as a discrete step where values of the
1353 timing function between 0 and 1 map to ''visibility/visible'' and other
1354 values of the timing function (which occur only at the
1355 start/end of the transition or as a result of ''cubic-bezier()''
1356 functions with Y values outside of [0, 1]) map to the closer
1357 endpoint; if neither value is ''visibility/visible'' then not interpolable.
1358 </li>
1359 <li id="animtype-shadow-list">
1360 <strong>shadow list</strong>: Each shadow in the list
1361 (treating ''shadow/none'' as a 0-length list)
1362 is interpolated via the
1363 color (as <a href="#animtype-color">color</a>) component,
1364 and x, y, blur, and (when appropriate) spread
1365 (as <a href="#animtype-length">length</a>) components.
1366 For each shadow, if both input shadows are ''shadow/inset''
1367 or both input shadows are not ''shadow/inset'',
1368 then the interpolated shadow must match the input shadows in that regard.
1369 If any pair of input shadows has one ''shadow/inset'' and the other not ''shadow/inset'',
1370 the entire <a href="#animtype-shadow-list">shadow-list</a> is uninterpolable.
1371 If the lists of shadows have different lengths,
1372 then the shorter list is padded at the end
1373 with shadows whose color is ''transparent'',
1374 all lengths are ''0'',
1375 and whose ''shadow/inset'' (or not) matches the longer list.
1376 </li>
1377 <li id="animtype-gradient">
1378 <strong>gradient</strong>: interpolated via the
1379 positions and colors of each stop. They must have the same type
1380 (radial or linear) and same number of stops in order to be animated.
1381 <span class="note">Note: [[CSS3-IMAGES]] may extend this
1382 definition.</span>
1383 </li>
1384 <li id="animtype-paintserver">
1385 <strong>paint server</strong> (SVG): interpolation is only supported
1386 between: gradient to gradient and color to color. They then
1387 work as above.
1388 </li>
1389 <li id="animtype-simple-list">
1390 <strong>simple list</strong> of other types:
1391 If the lists have the same number of items,
1392 and each pair of values can be interpolated,
1393 each item in the list is interpolated using
1394 the rules given for those types.
1395 Otherwise the values are not interpolable.
1396 </li>
1397 <li id="animtype-repeatable-list">
1398 <strong>repeatable list</strong> of other types:
1399 The result list has a length that is the least common multiple
1400 of the lengths of the input lists.
1401 Each item in the result is the interpolation of the value
1402 from each input list repeated to the length of the result list.
1403 If a pair of values cannot be interpolated, then the lists
1404 are not interpolable.
1405 <span class="note">
1406 The repeatable list concept ensures that a list that is
1407 conceptually repeated to a certain length (as
1408 'background-origin' is repeated to the length of the
1409 'background-image' list) or repeated infinitely will
1410 smoothly transition between any values, and so that the
1411 computed value will properly represent the result (and
1412 potentially be inherited correctly).
1413 </span>
1414 </li>
1415 </ul>
1417 <p>Future specifications may define additional types that can
1418 be animated.</p>
1420 <p>See the definition of 'transition-property' for how animation
1421 of shorthand properties and the ''all'' value is applied to any
1422 properties (in the shorthand) that can be animated.</p>
1424 Animation in steps of other property types {#step-types}
1425 --------------------------------------------------------
1427 <p>
1428 When interpolating between two values that cannot be interpolated,
1429 <var>V</var><sub>start</sub> and <var>V</var><sub>end</sub>,
1430 interpolation is done using the output <var>p</var> of the timing function.
1431 If <var>p</var> is less than 0.5, then the
1432 result of the interpolation is
1433 <var>V</var><sub>start</sub>;
1434 if <var>p</var> is greater than or equal to 0.5, then the
1435 result of the interpolation is
1436 <var>V</var><sub>end</sub>.
1437 </p>
1439 <p class="note" id="discrete-interpolation-at-risk">
1440 This is a recent change to which implementations have
1441 not yet updated. (Prior to the change CSS Transitions
1442 and CSS Animations did not run on such changes.) It's
1443 possible that it won't be compatible with existing Web content.
1444 If that is the case, the problem may be mitigated by restricting
1445 this behavior only to CSS Animations (and not to CSS Transitions),
1446 and/or restricting it to step timing functions.
1447 </p>
1449 <span id="animatable-properties-">Animatable properties</span> {#animatable-properties}
1450 =======================================================================================
1452 <!--
1453 As resolved in
1454 http://lists.w3.org/Archives/Public/www-style/2011Sep/0497.html
1455 -->
1457 <p>The definition of each CSS property defines
1458 when the values of that property can be interpolated
1459 by referring to the definitions of property types
1460 in the <a href="#animatable-types">previous section</a>.
1461 The animated value is interpolated from the from and to values when
1462 both the from and the to values of the property have the type described.
1463 (When a composite type such as "length, percentage, or calc" is listed,
1464 this means that both values must fit into that composite type.)
1465 When multiple types are listed in the form "either A or B",
1466 both values must be of the same type to be interpolable.</p>
1468 <p>Otherwise, since the from and to values cannot be interpolated,
1469 the animation is done <a href="#step-types">in a single step</a>.</p>
1471 <p>The 'transition-*' properties defined in this specification do
1472 not undergo transitions.</p>
1474 <p>For properties that exist at the time this specification was
1475 developed, this specification defines how they are
1476 animated. However, future CSS specifications may define
1477 additional properties, additional values for existing properties,
1478 or additional animation behavior of existing values. In order to
1479 describe new animation behaviors and to have the definition of
1480 animation behavior in a more appropriate location, future CSS
1481 specifications should include an "Animatable:" line in the summary
1482 of the property's definition (in addition to the other lines
1483 described in [[CSS21]], <a
1484 href="https://www.w3.org/TR/CSS21/about.html#property-defs">section
1485 1.4.2</a>). This line should say "no" to indicate that a property
1486 cannot be animated or should reference an animation behavior
1487 (which may be one of the behaviors in the <a
1488 href="#animation-of-property-types-">Animation of property
1489 types</a> section above, or may be a new behavior) to define how
1490 the property animates. Such definitions override those given in
1491 this specification.</p>
1493 <p class="issue" id="issue-animatable-name">
1494 It no longer makes sense for this line to be called
1495 "Animatable". It should probably be renamed to "Interpolation",
1496 and the "no" value renamed to "discrete" or "in steps".
1497 See mailing list thread:
1498 <a href="https://lists.w3.org/Archives/Public/www-style/2015May/0256.html">message 1</a>,
1499 <a href="https://lists.w3.org/Archives/Public/www-style/2015May/0257.html">message 2</a>
1500 </p>
1502 <span id="properties-from-css-">Properties from CSS</span> {#animatable-css}
1503 ----------------------------------------------------------------------------
1505 <p>
1506 The following definitions define the animation behavior for
1507 properties in CSS Level 2 Revision 1 ([[CSS21]]) and in Level 3 of
1508 the CSS Color Module ([[CSS3COLOR]]).
1509 </p>
1511 <table class="animatable-properties">
1512 <tr>
1513 <th>Property Name</th>
1514 <th>Type</th>
1515 </tr>
1516 <tr>
1517 <td>'background-color'</td><td>as <a href="#animtype-color">color</a></tr>
1518 <tr>
1519 <td>'background-position'</td><td>as <a href="#animtype-repeatable-list">repeatable list</a> of <a href="#animtype-simple-list">simple list</a> of <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1520 </tr>
1521 <tr>
1522 <td>'border-bottom-color'</td><td>as <a href="#animtype-color">color</a></td>
1523 </tr>
1524 <tr>
1525 <td>'border-bottom-width'</td><td>as <a href="#animtype-length">length</a></td>
1526 </tr>
1527 <tr>
1528 <td>'border-left-color'</td><td>as <a href="#animtype-color">color</a></td>
1529 </tr>
1530 <tr>
1531 <td>'border-left-width'</td><td>as <a href="#animtype-length">length</a></td>
1532 </tr>
1533 <tr>
1534 <td>'border-right-color'</td><td>as <a href="#animtype-color">color</a></td>
1535 </tr>
1536 <tr>
1537 <td>'border-right-width'</td><td>as <a href="#animtype-length">length</a></td>
1538 </tr>
1539 <tr>
1540 <td>'border-spacing'</td><td>as <a href="#animtype-simple-list">simple list</a> of <a href="#animtype-length">length</a></td>
1541 </tr>
1542 <tr>
1543 <td>'border-top-color'</td><td>as <a href="#animtype-color">color</a></td>
1544 </tr>
1545 <tr>
1546 <td>'border-top-width'</td><td>as <a href="#animtype-length">length</a></td>
1547 </tr>
1548 <tr>
1549 <td>'bottom'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1550 </tr>
1551 <tr>
1552 <td>'clip'</td><td>as <a href="#animtype-rect">rectangle</a></td>
1553 </tr>
1554 <tr>
1555 <td>'color'</td><td>as <a href="#animtype-color">color</a></td>
1556 </tr>
1557 <tr>
1558 <td>'font-size'</td><td>as <a href="#animtype-length">length</a></td>
1559 </tr>
1560 <tr>
1561 <td>'font-weight!!property'</td><td>as <a href="#animtype-font-weight">font weight</a></td>
1562 </tr>
1563 <tr>
1564 <td>'height'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1565 </tr>
1566 <tr>
1567 <td>'left'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1568 </tr>
1569 <tr>
1570 <td>'letter-spacing'</td><td>as <a href="#animtype-length">length</a></td>
1571 </tr>
1572 <tr>
1573 <td>'line-height'</td><td>as either <a href="#animtype-number">number</a> or <a href="#animtype-length">length</a></td>
1574 </tr>
1575 <tr>
1576 <td>'margin-bottom'</td><td>as <a href="#animtype-length">length</a></td>
1577 </tr>
1578 <tr>
1579 <td>'margin-left'</td><td>as <a href="#animtype-length">length</a></td>
1580 </tr>
1581 <tr>
1582 <td>'margin-right'</td><td>as <a href="#animtype-length">length</a></td>
1583 </tr>
1584 <tr>
1585 <td>'margin-top'</td><td>as <a href="#animtype-length">length</a></td>
1586 </tr>
1587 <tr>
1588 <td>'max-height'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1589 </tr>
1590 <tr>
1591 <td>'max-width'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1592 </tr>
1593 <tr>
1594 <td>'min-height'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1595 </tr>
1596 <tr>
1597 <td>'min-width'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1598 </tr>
1599 <tr>
1600 <td>'opacity'</td><td>as <a href="#animtype-number">number</a></td>
1601 </tr>
1602 <tr>
1603 <td>'outline-color'</td><td>as <a href="#animtype-color">color</a></td>
1604 </tr>
1605 <tr>
1606 <td>'outline-width'</td><td>as <a href="#animtype-length">length</a></td>
1607 </tr>
1608 <tr>
1609 <td>'padding-bottom'</td><td>as <a href="#animtype-length">length</a></td>
1610 </tr>
1611 <tr>
1612 <td>'padding-left'</td><td>as <a href="#animtype-length">length</a></td>
1613 </tr>
1614 <tr>
1615 <td>'padding-right'</td><td>as <a href="#animtype-length">length</a></td>
1616 </tr>
1617 <tr>
1618 <td>'padding-top'</td><td>as <a href="#animtype-length">length</a></td>
1619 </tr>
1620 <tr>
1621 <td>'right'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1622 </tr>
1623 <tr>
1624 <td>'text-indent'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1625 </tr>
1626 <tr>
1627 <td>'text-shadow'</td><td>as <a href="#animtype-shadow-list">shadow list</a></td>
1628 </tr>
1629 <tr>
1630 <td>'top'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1631 </tr>
1632 <tr>
1633 <td>'vertical-align'</td><td>as <a href="#animtype-length">length</a></td>
1634 </tr>
1635 <tr>
1636 <td>'visibility'</td><td>as <a href="#animtype-visibility">visibility</a></td>
1637 </tr>
1638 <tr>
1639 <td>'width'</td><td>as <a href="#animtype-lpcalc">length, percentage, or calc</a></td>
1640 </tr>
1641 <tr>
1642 <td>'word-spacing'</td><td>as <a href="#animtype-length">length</a></td>
1643 </tr>
1644 <tr>
1645 <td>'z-index'</td><td>as <a href="#animtype-integer">integer</a></td>
1646 </tr>
1647 </table>
1649 <span id="properties-from-svg-">Properties from SVG</span> {#animatable-svg}
1650 ----------------------------------------------------------------------------
1652 <p>
1653 All properties defined as animatable in the SVG specification, provided
1654 they are one of the property types listed above.
1655 </p>
1657 <!-- <table>
1658 <tr>
1659 <th>Property Name</th><th>Type</th>
1660 </tr>
1661 <tr>
1662 <td>stop-color</td><td>as <a href="#animtype-color">color</a></td>
1663 </tr>
1664 <tr>
1665 <td>stop-opacity</td><td>as <a href="#animtype-number">number</a></td>
1666 </tr>
1667 <tr>
1668 <td>fill</td><td>as <a href="#animtype-paintserver">paint server</a></td>
1669 </tr>
1670 <tr>
1671 <td>fill-opacity</td><td>as <a href="#animtype-number">number</a></td>
1672 </tr>
1673 <tr>
1674 <td>stroke</td><td>as <a href="#animtype-paintserver">paint server</a></td>
1675 </tr>
1676 <tr>
1677 <td>stroke-dasharray</td><td>as <a href="#animtype-repeatable-list">repeatable list</a> of <a href="#animtype-number">number</a></td>
1678 </tr>
1679 <tr>
1680 <td>stroke-dashoffset</td><td>as <a href="#animtype-number">number</a></td>
1681 </tr>
1682 <tr>
1683 <td>stroke-miterlimit</td><td>as <a href="#animtype-number">number</a></td>
1684 </tr>
1685 <tr>
1686 <td>stroke-opacity</td><td>as <a href="#animtype-number">number</a></td>
1687 </tr>
1688 <tr>
1689 <td>stroke-width</td><td>as <a href="#animtype-number">number</a></td>
1690 </tr>
1691 <tr>
1692 <td>viewport-fill</td><td>as <a href="#animtype-color">color</a></td>
1693 </tr>
1694 <tr>
1695 <td>viewport-fill-opacity</td><td>as <a href="#animtype-color">color</a></td>
1696 </tr>
1697 </table> -->
1699 Security Considerations {#security}
1700 ===================================
1702 <em>This section is not normative.</em>
1704 The security implications of this specification are limited
1705 because it doesn't allow Web content to do things
1706 that it could not do before.
1707 Rather, it allows things that could previously be done with script
1708 to be done declaratively,
1709 and it ways that implementations can optimize (for frame rate and
1710 CPU usage).
1712 One of the major categories of optimizations
1713 that implementations can make is implementing animation
1714 of certain high-value properties (such as 'transform' and 'opacity')
1715 run on a browser's compositor thread or process
1716 without updating style or layout on the main Web content thread
1717 unless up-to-date style data are needed.
1718 This optimization often requires allocations of graphics memory
1719 to display the contents of the element being animated.
1720 Implementations should take care to ensure that Web content
1721 cannot trigger unsafe out-of-memory handling
1722 by using large numbers of animations
1723 or animations on elements covering large areas
1724 (where large may be defined in terms of pre-transform or post-transform size).
1726 Privacy Considerations {#privacy}
1727 =================================
1729 <em>This section is not normative.</em>
1731 As for security, the privacy considerations of this specification are limited
1732 because it does not allow Web content to do things that it could not do before.
1734 This specification may provide additional mechanisms that help to determine
1735 characteristics of the user's hardware or software.
1736 However, ability to determine performance characteristics of the user's
1737 hardware or software is common to many Web technologies,
1738 and this specification does not introduce new capabilities.
1740 As described in [[#accessibility]],
1741 implementations may provide mitigations to help users with disabilities.
1742 These mitigations are likely to be detectable by Web content,
1743 which means that users who would benefit from these mitigations
1744 may face a tradeoff between keeping their disability private from
1745 the Web content or benefiting from the mitigation.
1747 Accessibility Considerations {#accessibility}
1748 =============================================
1750 <em>This section is not normative.</em>
1752 Motion {#accessibility-motion}
1753 ------------------------------
1755 This specification provides declarative mechanisms for animations
1756 that previously needed to be done using script.
1757 Providing a declarative mechanism has multiple effects:
1758 it makes such animations easier to make and thus likely to be more common,
1759 but it also makes it easier for user agents to modify those animations
1760 if such modifications are needed to meet a user's accessibility needs.
1762 Thus, users who are sensitive to movement,
1763 or who require additional time to read or understand content,
1764 may benefit from user agent features that allow
1765 animations to be disabled or slowed down.
1766 (But see [[#privacy]] for information on the privacy implications
1767 of such mitigations.)
1769 User agent implementors should be aware that Web content
1770 may depend on the firing of <a href="#transition-events">transition events</a>,
1771 so implementations of such mitigations may wish to fire transition events
1772 even if the transitions were not run as continuous animations.
1773 However, it is probably poor practice for Web content to depend on
1774 such events to function correctly.
1776 Cascade {#accessibility-cascade}
1777 --------------------------------
1779 The CSS <a>cascade</a> is a general mechanism in CSS
1780 that allows user needs to interact with author styles.
1781 This specification interacts with the cascade,
1782 but since it only allows animation between values
1783 that result from the existing cascade rules,
1784 it does not interfere with the user's ability to force
1785 CSS properties to have particular values.
1787 The cascade also allows users to disable transitions entirely
1788 by overriding the transition properties.
1791 Changes since Working Draft of 19 November 2013 {#changes}
1792 ==========================================================
1794 <p>The following are the substantive changes made since the
1795 <a href="https://www.w3.org/TR/2013/WD-css3-transitions-20131119/">Working Draft
1796 dated 19 November 2013</a>:</p>
1798 <ul>
1799 <li>Values that cannot be interpolated are transitioned when the timing function crosses its midpoint, instead of not running transitions and changing immediately.</li>
1800 <li>Canceling and interrupting of running transitions is defined much more precisely. This includes the after-change style no longer including styles from CSS Transitions.</li>
1801 <li>Completion of transitions is defined somewhat more precisely.</li>
1802 <li>The transitionend event is no longer cancelable. This is since it has no default action, so canceling it would have no meaning. It also matches the animation events.</li>
1803 <li>The interpolation of ''shadow/inset'' values on shadow lists is no longer backwards.</li>
1804 <li>A [[#conformance]] section, [[#security]] section, [[#privacy]] section, [[#accessibility]] section, and [[#idl-index]] have been added</li>
1805 <li>The identifiers accepted by 'transition-property' are defined in terms of <<custom-ident>>.</li>
1806 <li>Define a little bit more about when changes to computed values happen, by saying at least that implementations must not update the effects of computed values without actually updating computed values.</li>
1807 </ul>
1809 <p>For more details on these changes, see the version control <a href="https://hg.csswg.org/drafts/log/tip/css-transitions/Overview.bs">change log since 2015 January 26</a> and the <a href="https://hg.csswg.org/drafts/log/tip/css-transitions/Overview.src.html">change log from 2013 March 28 to 2015 January 26</a>.</p>
1811 <p>For changes in earlier working drafts:</p>
1813 <ol>
1814 <li>see the <a href="https://www.w3.org/TR/2013/WD-css3-transitions-20131119/#changes">changes section in the 19 November 2013 Working Draft</a>
1815 <li>see the <a href="https://www.w3.org/TR/2013/WD-css3-transitions-20130212/ChangeLog">the ChangeLog</a> for changes in previous working drafts
1816 <li>For more details on these changes, see the version control change logs, which are split in three parts because of file renaming: <a href="https://hg.csswg.org/drafts/log/tip/css-transitions/Overview.bs">change log since 2015 January 26</a>, <a href="https://hg.csswg.org/drafts/log/tip/css-transitions/Overview.src.html">change log from 2013 March 28 to 2015 January 26</a>, <a href="https://hg.csswg.org/drafts/log/tip/css3-transitions/Overview.src.html">change log before 2013 March 28</a>.
1817 </ol>
1819 Acknowledgments {#acknowledgments}
1820 ==================================
1822 <p>Thanks especially to the feedback from
1823 Tab Atkins,
1824 Carine Bournez,
1825 Aryeh Gregor,
1826 Vincent Hardy,
1827 Anne van Kesteren,
1828 Cameron McCormack,
1829 Alex Mogilevsky,
1830 Jasper St. Pierre,
1831 Estelle Weyl,
1832 and all the rest of the
1833 <a href="http://lists.w3.org/Archives/Public/www-style/">www-style</a> community.</p>