-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
2162 lines (1603 loc) · 69.9 KB
/
Overview.html
File metadata and controls
2162 lines (1603 loc) · 69.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang=en>
<head>
<title>CSS Animations</title>
<!--
<link href="http://purl.org/dc/terms/" rel="schema.dcterms">
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright" rel="dcterms.rights">
-->
<meta content="CSS Animations" name=dcterms.title>
<meta content=text name=dcterms.type>
<meta content=2013-05-06 name=dcterms.date>
<meta content="L. David Baron" name=dcterms.creator>
<meta content=W3C name=dcterms.publisher>
<meta content="http://dev.w3.org/csswg/css3-animations/"
name=dcterms.identifier>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<link href="../default.css" rel=stylesheet type="text/css">
<style type="text/css">
div.prod { margin: 1em 2em; }
</style>
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS Animations</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 6 May 2013</h2>
<dl>
<dt>This version:
<dd><a
href="http://dev.w3.org/csswg/css3-animations/">http://dev.w3.org/csswg/css3-animations/</a>
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-animations/">http://www.w3.org/TR/css3-animations/</a>
<dt>Editor's draft:
<dd><a
href="http://dev.w3.org/csswg/css3-animations/">http://dev.w3.org/csswg/css3-animations/</a>
(<a
href="https://dvcs.w3.org/hg/csswg/log/tip/css-animations/Overview.src.html">change
log</a>, <a
href="https://dvcs.w3.org/hg/csswg/log/tip/css3-animations/Overview.src.html">older
change log</a>)
<dt>Previous version:
<dd><a href="http://www.w3.org/TR/2012/WD-css3-animations-20130219/">
http://www.w3.org/TR/2012/WD-css3-animations-20130219/</a>
<dt id=editors-list>Editors:
<dd><a href="mailto:dino@apple.com">Dean Jackson</a> (<a
href="http://www.apple.com/">Apple Inc</a>)
<dd><a href="mailto:ratan@microsoft.com">Rossen Atanassov</a> (<a
class=org href="http://www.microsoft.com/">Microsoft</a>)
<dd class=vcard><a class=fn href="http://dbaron.org/">L. David Baron</a>
(<a class=org href="http://www.mozilla.org/">Mozilla</a>)
<dt>Former editors:
<dd><a href="mailto:hyatt@apple.com">David Hyatt</a> (<a
href="http://www.apple.com/">Apple Inc</a>)
<dd><a href="mailto:cmarrin@apple.com">Chris Marrin</a> (<a
href="http://www.apple.com/">Apple Inc</a>)
<dd>Sylvain Galineau, Microsoft
<dt>Issues list:
<dd><a
href="https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&product=CSS&component=Animations&resolution=---&cmdtype=doit">in
Bugzilla</a>
<dt>Feedback:
<dd><a
href="mailto:www-style@w3.org?subject=%5Bcss-animations%5D%20feedback">www-style@w3.org</a>
with subject line “<kbd>[css-animations] <var>… message topic
…</var></kbd>” (<a
href="http://lists.w3.org/Archives/Public/www-style/"
rel=discussion>archives</a>)
<dt>Test suite:
<dd>none yet
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2013 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a
href="http://ev.buaa.edu.cn/">Beihang</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract> Abstract</h2>
<p> This CSS module describes a way for authors to animate the values of
CSS properties over time, using keyframes. The behavior of these keyframe
animations can be controlled by specifying their duration, number of
repeats, and repeating behavior.
<h2 class="no-num no-toc" id=status> Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-animations%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css3-animations” in the subject, preferably like this:
“[<!---->css3-animations<!---->] <em>…summary of comment…</em>”
<p>This document was produced by the <a
href="http://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of
the <a href="http://www.w3.org/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</a>. W3C maintains a <a
href="http://www.w3.org/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.</p>
<!--end-status-->
<h2 class="no-num no-toc" id=contents> Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#introduction"><span class=secno>1. </span> Introduction</a>
<li><a href="#values"><span class=secno>2. </span> Values</a>
<li><a href="#animations"><span class=secno>3. </span> Animations</a>
<li><a href="#keyframes"><span class=secno>4. </span> Keyframes</a>
<ul class=toc>
<li><a href="#timing-functions"><span class=secno>4.1. </span> Timing
functions for keyframes</a>
<li><a href="#animation-name-property"><span class=secno>4.2. </span>
The ‘<code class=property>animation-name</code>’ Property</a>
<li><a href="#animation-duration-property"><span class=secno>4.3.
</span> The ‘<code class=property>animation-duration</code>’
Property</a>
<li><a href="#animation-timing-function-property"><span class=secno>4.4.
</span> The ‘<code class=property>animation-timing-function</code>’
Property</a>
<li><a href="#animation-iteration-count-property"><span class=secno>4.5.
</span> The ‘<code class=property>animation-iteration-count</code>’
Property</a>
<li><a href="#animation-direction-property"><span class=secno>4.6.
</span> The ‘<code class=property>animation-direction</code>’
Property</a>
<li><a href="#animation-play-state-property"><span class=secno>4.7.
</span> The ‘<code class=property>animation-play-state</code>’
Property</a>
<li><a href="#animation-delay-property"><span class=secno>4.8. </span>
The ‘<code class=property>animation-delay</code>’ Property</a>
<li><a href="#animation-fill-mode-property"><span class=secno>4.9.
</span> The ‘<code class=property>animation-fill-mode</code>’
Property</a>
<li><a href="#animation-shorthand-property"><span class=secno>4.10.
</span> The ‘<code class=property>animation</code>’ Shorthand
Property</a>
</ul>
<li><a href="#animation-events"><span class=secno>5. </span> Animation
Events</a>
<ul class=toc>
<li><a href="#AnimationEvent-interface"><span class=secno>5.1. </span>
Interface <code>AnimationEvent</code></a>
<ul class=toc>
<li><a href="#AnimationEvent-IDL"><span class=secno>5.1.1. </span> IDL
Definition</a>
<li><a href="#AnimationEvent-attributes"><span class=secno>5.1.2.
</span> Attributes</a>
</ul>
<li><a href="#AnimationEvent-types"><span class=secno>5.2. </span> Types
of <code>AnimationEvent</code></a>
</ul>
<li><a href="#dom-interfaces"><span class=secno>6. </span> DOM
Interfaces</a>
<ul class=toc>
<li><a href="#CSSRule-interface"><span class=secno>6.1. </span>
Interface <code>CSSRule</code></a>
<ul class=toc>
<li><a href="#CSSRule-IDL"><span class=secno>6.1.1. </span> IDL
Definition</a>
</ul>
<li><a href="#CSSKeyframeRule-interface"><span class=secno>6.2. </span>
Interface <code>CSSKeyframeRule</code></a>
<ul class=toc>
<li><a href="#CSSKeyframeRule-IDL"><span class=secno>6.2.1. </span>
IDL Definition</a>
<li><a href="#CSSKeyframeRule-attributes"><span class=secno>6.2.2.
</span> Attributes</a>
</ul>
<li><a href="#CSSKeyframesRule-interface"><span class=secno>6.3. </span>
Interface <code>CSSKeyframesRule</code></a>
<ul class=toc>
<li><a href="#CSSKeyframesRule-IDL"><span class=secno>6.3.1. </span>
IDL Definition</a>
<li><a href="#CSSKeyframesRule-attributes"><span class=secno>6.3.2.
</span> Attributes</a>
<li><a href="#CSSKeyframesRule-appendRule"><span class=secno>6.3.3.
</span> The <code>appendRule</code> method</a>
<li><a href="#CSSKeyframesRules-deleteRule"><span class=secno>6.3.4.
</span> The <code>deleteRule</code> method</a>
<li><a href="#CSSKeyframesRule-findRule"><span class=secno>6.3.5.
</span> The <code>findRule</code> method</a>
</ul>
</ul>
<li><a href="#acknowledgments"><span class=secno>7.
</span>Acknowledgments</a>
<li><a href="#references"><span class=secno>8. </span>References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
</ul>
<li class=no-num><a href="#property-index">Property index</a>
<li class=no-num><a href="#index">Index</a>
</ul>
<!--end-toc-->
<h2 id=introduction><span class=secno>1. </span> Introduction</h2>
<p><em>This section is not normative.</em>
<p> CSS Transitions <a href="#CSS3-TRANSITIONS"
rel=biblioentry>[CSS3-TRANSITIONS]<!--{{CSS3-TRANSITIONS}}--></a> provide
a way to interpolate CSS property values when they change as a result of
underlying property changes. This provides an easy way to do simple
animation, but the start and end states of the animation are controlled by
the existing property values, and transitions provide little control to
the author on how the animation progresses.
<p> This proposal introduces <dfn id=defined-animations>defined
animations</dfn>, in which the author can specify the changes in CSS
properties over time as a set of keyframes. Animations are similar to
transitions in that they change the presentational value of CSS properties
over time. The principal difference is that while transitions trigger
<em>implicitly</em> when property values change, animations are
<em>explicitly</em> executed when the animation properties are applied.
Because of this, animations require explicit values for the properties
being animated. These values are specified using animation keyframes,
described below.
<p> Many aspects of the animation can be controlled, including how many
times the animation iterates, whether or not it alternates between the
begin and end values, and whether or not the animation should be running
or paused. An animation can also delay its start time.
<h2 id=values><span class=secno>2. </span> Values</h2>
<p> This specification follows the <a
href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property
definition conventions</a> from <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Value types not defined in
this specification are defined in CSS Level 2 Revision 1 <a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Other CSS
modules may expand the definitions of these value types: for example <a
href="#CSS3VAL" rel=biblioentry>[CSS3VAL]<!--{{CSS3VAL}}--></a>, when
combined with this module, expands the definition of the
<var><length></var> value type as used in this specification.
<p>In addition to the property-specific values listed in their definitions,
all properties defined in this specification also accept the <a
href="http://dev.w3.org/csswg/css3-values/#common-keywords">‘<code
class=css>initial</code>’</a> and <a
href="http://dev.w3.org/csswg/css3-values/#common-keywords">‘<code
class=css>inherit</code>’</a> keyword as their property value. For
readability it has not been repeated explicitly.
<h2 id=animations><span class=secno>3. </span> Animations</h2>
<p> CSS Animations affect computed property values. During the execution of
an animation, the computed value for a property is controlled by the
animation. This overrides the value specified in the normal styling
system. Animations override all normal rules, but are overriden by
!important rules.
<p> If at one point in time there are multiple animations specifying
behavior for the same property, the animation whose name occurs last in
the value of ‘<a href="#animation-name"><code
class=property>animation-name</code></a>’ will override the other
animations at that point.
<p> An animation does not affect the computed value before the application
of the animation, before the animation delay has expired, and after the
end of the animation.
<div class=figure> <img alt="" src=sandwich.png>
<p class=caption> Computation of animated property values
</div>
<p> The diagram above shows how property values are computed. The intrinsic
style is shown at the top of the diagram. The computed value is derived
from intrinsic style at the times when an animation is not running and
also when an animation is delayed (see below for specification of
animation delay). During an animation, the computed style is derived from
the animated value.
<p> The start time of an animation is the latter of two moments: the time
at which the style is resolved that specifies the animation, or the time
the document's load event is fired. Therefore, an animation specified in
the document style sheet will begin at the document load. An animation
specified on an element by modifying the style after the document has
loaded will start when the style is resolved. That may be immediately in
the case of a pseudo style rule such as hover, or may be when the
scripting engine returns control to the browser (in the case of style
applied by script).
<p> An animation applies to an element if its name appears as one of the
identifiers in the computed value of the ‘<a
href="#animation-name"><code class=property>animation-name</code></a>’
property. Once an animation has started it continues until it ends or the
‘<a href="#animation-name"><code
class=property>animation-name</code></a>’ is removed. The values used
for the keyframes and animation properties are snapshotted at the time the
animation starts. Changing them during the execution of the animation has
no effect. Note also that changing the value of ‘<a
href="#animation-name"><code class=property>animation-name</code></a>’
does not necessarily restart an animation (e.g., if a list of animations
are applied and one is removed from the list, only that animation will
stop; The other animations will continue). In order to restart an
animation, it must be removed then reapplied.
<p> The end of the animation is defined by the combination of the ‘<a
href="#animation-duration"><code
class=property>animation-duration</code></a>’, ‘<a
href="#animation-iteration-count"><code
class=property>animation-iteration-count</code></a>’ and ‘<a
href="#animation-fill-mode"><code
class=property>animation-fill-mode</code></a>’ properties.
<div class=example>
<pre>
div {
animation-name: diagonal-slide;
animation-duration: 5s;
animation-iteration-count: 10;
}
@keyframes diagonal-slide {
from {
left: 0;
top: 0;
}
to {
left: 100px;
top: 100px;
}
}</pre>
<p> This will produce an animation that moves an element from (0, 0) to
(100px, 100px) over five seconds and repeats itself nine times (for a
total of ten iterations).
</div>
<p> Setting the display property to ‘<code class=property>none</code>’
will terminate any running animation applied to the element and its
descendants. If an element has a display of ‘<code
class=property>none</code>’, updating display to a value other than
‘<code class=property>none</code>’ will start all animations applied
to the element by the ‘<a href="#animation-name"><code
class=property>animation-name</code></a>’ property, as well as all
animations applied to descendants with display other than ‘<code
class=property>none</code>’.
<p> While authors can use animations to create dynamically changing
content, dynamically changing content can lead to seizures in some users.
For information on how to avoid content that can lead to seizures, see <a
href="http://www.w3.org/TR/WCAG20/#seizure">Guideline 2.3: Seizures: Do
not design content in a way that is known to cause seizures</a> (<a
href="#WCAG20" rel=biblioentry>[WCAG20]<!--{{WCAG20}}--></a>).
<h2 id=keyframes><span class=secno>4. </span> Keyframes</h2>
<p> Keyframes are used to specify the values for the animating properties
at various points during the animation. The keyframes specify the behavior
of one cycle of the animation; the animation may iterate one or more
times.
<p> Keyframes are specified using a specialized CSS at-rule. A @keyframes
rule consists of the keyword "@keyframes", followed by an identifier
giving a name for the animation (which will be referenced using ‘<a
href="#animation-name"><code class=property>animation-name</code></a>’),
followed by a set of style rules (delimited by curly braces).
<p> The <dfn id=keyframe-selector>keyframe selector</dfn> for a keyframe
style rule consists of a comma-separated list of percentage values or the
keywords ‘<code class=property>from</code>’ or ‘<code
class=property>to</code>’. The selector is used to specify the
percentage along the duration of the animation that the keyframe
represents. The keyframe itself is specified by the block of property
values declared on the selector. The keyword ‘<code
class=property>from</code>’ is equivalent to the value ‘<code
class=css>0%</code>’. The keyword ‘<code class=property>to</code>’
is equivalent to the value ‘<code class=css>100%</code>’. <span
class=note>Note that the percentage unit specifier must be used on
percentage values. Therefore, ‘<code class=css>0</code>’ is an invalid
keyframe selector.</span>
<p> If a ‘<code class=css>0%</code>’ or ‘<code
class=css>from</code>’ keyframe is not specified, then the user agent
constructs a ‘<code class=css>0%</code>’ keyframe using the computed
values of the properties being animated. If a ‘<code
class=css>100%</code>’ or ‘<code class=css>to</code>’ keyframe is
not specified, then the user agent constructs a ‘<code
class=css>100%</code>’ keyframe using the computed values of the
properties being animated. If a keyframe selector specifies negative
percentage values or values higher than 100%, then the keyframe will be
ignored.
<p> The <dfn id=keyframe-declaration-block>keyframe declaration block</dfn>
for a keyframe rule consists of properties and values. Properties that are
unable to be animated are ignored in these rules, with the exception of
‘<a href="#animation-timing-function"><code
class=property>animation-timing-function</code></a>’, the behavior of
which is described below. In addition, keyframe rule declarations
qualified with !important are ignored.
<p class=issue> Need to describe what happens if a property is not present
in all keyframes.
<p> The @keyframes rule that is used by an animation will be the last one
encountered in sorted rules order that matches the name of the animation
specified by the ‘<a href="#animation-name"><code
class=property>animation-name</code></a>’ property. @keyframes rules do
not cascade; therefore, an animation will never derive keyframes from more
than one @keyframes rule.
<p class=note> Note that since empty @keyframes rule are valid, they may
hide the keyframes of those preceding animation definitions with a
matching name.
<p> To determine the set of keyframes, all of the values in the selectors
are sorted in increasing order by time. If there are any duplicates, then
the last keyframe specified inside the @keyframes rule will be used to
provide the keyframe information for that time. There is no cascading
within a @keyframes rule if multiple keyframes specify the same keyframe
selector values.
<p> If a property is not specified for a keyframe, or is specified but
invalid, the animation of that property proceeds as if that keyframe did
not exist. Conceptually, it is as if a set of keyframes is constructed for
each property that is present in any of the keyframes, and an animation is
run independently for each property.
<div class=example>
<pre>
@keyframes wobble {
0% {
left: 100px;
}
40% {
left: 150px;
}
60% {
left: 75px;
}
100% {
left: 100px;
}
}</pre>
<p> Four keyframes are specified for the animation named "wobble". In the
first keyframe, shown at the beginning of the animation cycle, the value
of the ‘<code class=property>left</code>’ property being animated is
‘<code class=css>100px</code>’. By 40% of the animation duration,
‘<code class=property>left</code>’ has animated to ‘<code
class=css>150px</code>’. At 60% of the animation duration, ‘<code
class=property>left</code>’ has animated back to ‘<code
class=css>75px</code>’. At the end of the animation cycle, the value of
‘<code class=property>left</code>’ has returned to ‘<code
class=css>100px</code>’. The diagram below shows the state of the
animation if it were given a duration of ‘<code
class=css>10s</code>’.
<div class=figure> <img alt="" src=animation1.png>
<p class=caption> Animations states specified by keyframes
</div>
</div>
<p> The following is the grammar for the keyframes rule.
<pre>
keyframes_rule: KEYFRAMES_SYM S+ IDENT S* '{' S* keyframes_blocks '}' S*;
keyframes_blocks: [ keyframe_selector '{' S* declaration? [ ';' S* declaration? ]* '}' S* ]* ;
keyframe_selector: [ FROM_SYM | TO_SYM | PERCENTAGE ] S* [ ',' S* [ FROM_SYM | TO_SYM | PERCENTAGE ] S* ]*;
@{K}{E}{Y}{F}{R}{A}{M}{E}{S} {return KEYFRAMES_SYM;}
{F}{R}{O}{M} {return FROM_SYM;}
{T}{O} {return TO_SYM;}</pre>
<h3 id=timing-functions><span class=secno>4.1. </span> Timing functions for
keyframes</h3>
<p> A keyframe style rule may also declare the timing function that is to
be used as the animation moves to the next keyframe.
<div class=example>
<pre>
@keyframes bounce {
from {
top: 100px;
animation-timing-function: ease-out;
}
25% {
top: 50px;
animation-timing-function: ease-in;
}
50% {
top: 100px;
animation-timing-function: ease-out;
}
75% {
top: 75px;
animation-timing-function: ease-in;
}
to {
top: 100px;
}
}</pre>
<p> Five keyframes are specified for the animation named "bounce". Between
the first and second keyframe (i.e., between 0% and 25%) an ‘<code
class=css>ease-out</code>’ timing function is used. Between the second
and third keyframe (i.e., between 25% and 50%) an ‘<code
class=css>ease-in</code>’ timing function is used. And so on. The
effect will appear as an element that moves up the page ‘<code
class=css>50px</code>’, slowing down as it reaches its highest point
then speeding up as it falls back to ‘<code class=css>100px</code>’.
The second half of the animation behaves in a similar manner, but only
moves the element ‘<code class=css>25px</code>’ up the page.
</div>
<p> A timing function specified on the "to" or 100% keyframe is ignored.
<p> See the ‘<a href="#animation-timing-function"><code
class=property>animation-timing-function</code></a>’ property for more
information.
<h3 id=animation-name-property><span class=secno>4.2. </span> The ‘<a
href="#animation-name"><code class=property>animation-name</code></a>’
Property</h3>
<p> The ‘<a href="#animation-name"><code
class=property>animation-name</code></a>’ property defines a list of
animations that apply. Each name is used to select the keyframe at-rule
that provides the property values for the animation. If the name does not
match any keyframe at-rule, there are no properties to be animated and the
animation will not execute. Furthermore, if the animation name is ‘<code
class=css>none</code>’ then there will be no animation. This can be used
to override any animations coming from the cascade. If multiple animations
are attempting to modify the same property, then the animation closest to
the end of the list of names wins.
<p id=list-matching> Each animation listed by name should have a
corresponding value for the other animation properties listed below. If
the lists of values for the other animation properties do not have the
same length, the length of the ‘<a href="#animation-name"><code
class=property>animation-name</code></a>’ list determines the number of
items in each list examined when starting animations. The lists are
matched up from the first value: excess values at the end are not used. If
one of the other properties doesn't have enough comma-separated values to
match the number of values of ‘<a href="#animation-name"><code
class=property>animation-name</code></a>’, the UA must calculate its
used value by repeating the list of values until there are enough. This
truncation or repetition does not affect the computed value. <span
class=note>Note: This is analogous to the behavior of the ‘<code
class=css>background-*</code>’properties, with ‘<code
class=property>background-image</code>’ analogous to ‘<a
href="#animation-name"><code
class=property>animation-name</code></a>’.</span>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=animation-name>animation-name</dfn>
<tr>
<th><a href="#values">Value</a>:
<td><a href="#single-animation-name"><single-animation-name></a> [
‘<code class=css>,</code>’ <a
href="#single-animation-name"><single-animation-name></a> ]*
<tr>
<th>Initial:
<td>‘<code class=css>none</code>’
<tr>
<th>Applies To:
<td>all elements, ::before and ::after pseudo-elements
<tr>
<th>Inherited:
<td>no
<tr>
<th>Animatable:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed Value:
<td>As specified
<tr>
<th>Canonical Order:
<td><abbr title="follows order of property value definition">per
grammar</abbr>
</table>
<div class=prod> <dfn
id=single-animation-name><single-animation-name></dfn> = none |
<IDENT></div>
<!--
<p>
It is possible for elements to have multiple animations running that change the same property or properties. In this case the animations combine in a manner defined by the property. For example, animations on 'opacity' will add together and animations on 'transform' will have their transformation matrices multiplied.
<div class="example">
<p style="display:none">
Example(s):
<pre>
@keyframes 'border-bloat' {
from {
border-width: 0;
}
to {
border-width: 10px;
}
}
@keyframes 'border-diet' {
from {
border-width: 4px;
}
to {
border-width: 2px;
}
}
div {
animation-name: 'border-bloat', 'border-diet';
animation-duration: 10s, 4s;
}
</pre>
<p>
The above example has two animations executing on the same property, 'border-width'. The animations are additive. That is, the
resulting value for the property will be the addition of the values from the
two animations.
<p>
At time '0s' the element's border will be 4px wide (0px from 'border-bloat' plus 4px from 'border-diet').
At time '4s' the element's border will be 6px wide (4px from 'border-bloat' plus 2px from 'border-diet').
At time '10s' the element's border will be 10px wide (10px from 'border-bloat' and no addition from
'border-diet' as it is no longer executing).
</div>
-->
<h3 id=animation-duration-property><span class=secno>4.3. </span> The ‘<a
href="#animation-duration"><code
class=property>animation-duration</code></a>’ Property</h3>
<p> The ‘<a href="#animation-duration"><code
class=property>animation-duration</code></a>’ property defines the
length of time that an animation takes to complete one cycle.
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=animation-duration>animation-duration</dfn>
<tr>
<th><a href="#values">Value</a>:
<td> <span><time></span> [, <span><time></span>]*
<tr>
<th>Initial:
<td>‘<code class=css>0s</code>’
<tr>
<th>Applies To:
<td>all elements, ::before and ::after pseudo-elements
<tr>
<th>Inherited:
<td>no
<tr>
<th>Animatable:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed Value:
<td>as specified
<tr>
<th>Canonical Order:
<td><abbr title="follows order of property value definition">per
grammar</abbr>
</table>
<p> The initial value is ‘<code class=css>0s</code>’, meaning that the
animation takes no time. When the duration is ‘<code
class=css>0s</code>’ ‘<a href="#animation-fill-mode"><code
class=property>animation-fill-mode</code></a>’ still applies, so an
animation that fills backwards will show the value of the 0% keyframe
during any delay period, and an animation that fills forwards will retain
the value specified at the 100% keyframe, even if the animation was
instantaneous. Also, animation events are still fired. A negative ‘<a
href="#animation-duration"><code
class=property>animation-duration</code></a>’ value renders the
declaration invalid.
<h3 id=animation-timing-function-property><span class=secno>4.4. </span>
The ‘<a href="#animation-timing-function"><code
class=property>animation-timing-function</code></a>’ Property</h3>
<p> The ‘<a href="#animation-timing-function"><code
class=property>animation-timing-function</code></a>’ property describes
how the animation will progress over one cycle of its duration. See the
‘<code class=property>transition-timing-function</code>’ property <a
href="#CSS3-TRANSITIONS"
rel=biblioentry>[CSS3-TRANSITIONS]<!--{{!CSS3-TRANSITIONS}}--></a> for a
complete description of timing function calculation.
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=animation-timing-function>animation-timing-function</dfn>
<tr>
<th><a href="#values">Value</a>:
<td><span><single-timing-function></span> [ ‘<code
class=css>,</code>’ <span><single-timing-function></span> ]*
<tr>
<th>Initial:
<td>‘<code class=css>ease</code>’
<tr>
<th>Applies To:
<td>all elements, ::before and ::after pseudo-elements
<tr>
<th>Inherited:
<td>no
<tr>
<th>Animatable:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed Value:
<td>as specified
<tr>
<th>Canonical Order:
<td><abbr title="follows order of property value definition">per
grammar</abbr>
</table>
<p>All the valid values of ‘<code
class=css><single-timing-function></code>’ are defined by the
‘<code class=property>transition-timing-function</code>’ property <a
href="#CSS3-TRANSITIONS"
rel=biblioentry>[CSS3-TRANSITIONS]<!--{{!CSS3-TRANSITIONS}}--></a>.
<p> For a keyframed animation, the ‘<a
href="#animation-timing-function"><code
class=property>animation-timing-function</code></a>’ applies between
keyframes, not over the entire animation. For example, in the case of an
‘<code class=css>ease-in-out</code>’ timing function, an animation
will ease in at the start of the keyframe and ease out at the end of the
keyframe. An ‘<a href="#animation-timing-function"><code
class=property>animation-timing-function</code></a>’ defined within a
keyframe block applies to that keyframe, otherwise the timing function
specified for the animation is used. In addition, only the first value of
the property applies when it is used in a keyframe block.
<h3 id=animation-iteration-count-property><span class=secno>4.5. </span>
The ‘<a href="#animation-iteration-count"><code
class=property>animation-iteration-count</code></a>’ Property</h3>
<p> The ‘<a href="#animation-iteration-count"><code
class=property>animation-iteration-count</code></a>’ property specifies
the number of times an animation cycle is played. The initial value is
‘<code class=css>1</code>’, meaning the animation will play from
beginning to end once. A value of ‘<code class=css>infinite</code>’
will cause the animation to repeat forever. Non-integer numbers will cause
the animation to end part-way through a cycle. Negative values of ‘<a
href="#animation-iteration-count"><code
class=property>animation-iteration-count</code></a>’ are invalid. This
property is often used in conjunction an ‘<a
href="#animation-direction"><code
class=property>animation-direction</code></a>’ value of ‘<a
href="#alternate"><code class=css>alternate</code></a>’, which will
cause the animation to play in reverse on alternate cycles.
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=animation-iteration-count>animation-iteration-count</dfn>
<tr>
<th><a href="#values">Value</a>:
<td><a
href="#single-animation-iteration-count"><single-animation-iteration-count></a>
[ ‘<code class=css>,</code>’ <a
href="#single-animation-iteration-count"><single-animation-iteration-count></a>
]*
<tr>
<th>Initial:
<td>‘<code class=css>1</code>’
<tr>
<th>Applies To:
<td>all elements, ::before and ::after pseudo-elements
<tr>
<th>Inherited:
<td>no
<tr>
<th>Animatable:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed Value:
<td>as specified
<tr>
<th>Canonical Order:
<td><abbr title="follows order of property value definition">per
grammar</abbr>
</table>
<div class=prod> <dfn
id=single-animation-iteration-count><single-animation-iteration-count></dfn>
= infinite | <number></div>
<h3 id=animation-direction-property><span class=secno>4.6. </span> The