-
Notifications
You must be signed in to change notification settings - Fork 669
/
Overview.bs
1008 lines (817 loc) · 35.2 KB
/
Overview.bs
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
<pre class=metadata>
Title: CSS Easing Functions Level 2
Status: ED
Prepare for TR: no
Work Status: exploring
Shortname: css-easing
Level: 2
Group: csswg
ED: https://drafts.csswg.org/css-easing/
TR: https://www.w3.org/TR/css-easing-2/
Editor: Brian Birtles, Mozilla https://www.mozilla.org/, bbirtles@mozilla.com, w3cid 43194
Editor: Dean Jackson, Apple Inc https://www.apple.com/, dino@apple.com, w3cid 42080
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact, w3cid 42199
Editor: Chris Lilley, W3C, https://svgees.us/, w3cid 1438
Former Editor: Matt Rakow, Microsoft, w3cid 62267
Former Editor: Shane Stephens, Google, shans@google.com, w3cid 47691
Former Editor: Jake Archibald, Google, jakearchibald@google.com, w3cid 76394
Implementation Report: https://wpt.fyi/results/css/css-easing
Markup Shorthands: markdown yes
Indent: 2
Abstract: This CSS module describes a way for authors to define a transformation
that controls the rate of change of some value.
Applied to animations, such transformations can be used to produce
animations that mimic physical phenomena such as momentum or to cause the
animation to move in discrete steps producing robot-like movement.
Level 2 adds more sophisticated functions for custom easing curves.
!Participate: IRC: <a href="ircs://irc.w3.org:6667/css">#css</a> on W3C's IRC
Repository: w3c/csswg-drafts
WPT Path Prefix: css/css-easing/
WPT Display: closed
!Tests: <a href="https://github.com/web-platform-tests/wpt/tree/master/css/css-easing">web-platform-tests css/css-easing</a>
</pre>
<style>
.easing-graph {
max-width: 400px;
width: 100%;
}
@media (prefers-color-scheme: dark) {
.easing-graph {
background: none;
}
}
</style>
<style>
/* Creates an easing example. Use like <div class=easing-track style="--easing: linear"></div>. */
.easing-track {
position: relative;
height: 1em;
background: linear-gradient(to bottom, transparent calc(50% - 1px), var(--a-normal-underline) 0 calc(50% + 1px), transparent 0);
min-width: 200px;
margin: .5em;
}
.easing-track::before {
content: "";
position: absolute;
width: 1em;
height: 1em;
box-sizing: border-box;
border-radius: 50%;
background: var(--bg);
border: medium solid var(--text);
left: 0;
animation: --easing-track var(--easing) 3s infinite;
}
@keyframes --easing-track {
to { left: calc(100% - 1em); }
}
</style>
<style>
/* Put nice boxes around each algorithm. */
[data-algorithm]:not(.heading) {
padding: .5em;
border: thin solid #ddd; border-radius: .5em;
margin: .5em calc(-0.5em - 1px);
}
[data-algorithm]:not(.heading) > :first-child {
margin-top: 0;
}
[data-algorithm]:not(.heading) > :last-child {
margin-bottom: 0;
}
[data-algorithm] [data-algorithm] {
margin: 1em 0;
}
</style>
Introduction {#introduction}
============================
<em>This section is not normative.</em>
It is often desirable to control the rate at which some value changes.
For example, gradually increasing the speed at which an element moves can
give the element a sense of weight as it appears to gather momentum.
This can be used to produce intuitive user interface elements or convincing
cartoon props that behave like their physical counterparts.
Alternatively, it is sometimes desirable for animation to move forwards in
distinct steps such as a segmented wheel that rotates such that the segments
always appear in the same position.
Similarly, controlling the rate of change of gradient interpolation can be
used to produce different visual effects such as suggesting a concave or convex
surface, or producing a striped effect.
[=Easing functions=] provide a means to transform such values by taking an
input progress value and producing a corresponding transformed output progress
value.
<figure>
<img class="easing-graph" src="images/easing-function-example.svg" width="535" height="510"
alt="Example of an easing function that produces an ease-in effect.">
<figcaption>
Example of an easing function that produces an ease-in effect.<br>
Given an input progress of 0.7, the easing function scales the
value to produce an output progress of 0.52.<br>
Applying this easing function to an animation would cause it to progress
more slowly at first but then gradually progress more quickly.
</figcaption>
</figure>
<h3 id="values">
Value Definitions</h3>
This specification uses the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]].
Combination with other CSS modules may expand the definitions of these value types.
<h2 id=easing-functions oldids=timing-functions>Easing functions</h2>
An <dfn export lt="easing function|timing function">easing function</dfn> takes
an [=input progress value=] and produces an [=output progress value=].
An [=easing function=] must be a pure function meaning that for a given set of
inputs, it always produces the same [=output progress value=].
The <dfn export for="easing function">input progress value</dfn> is a real number in the range [-∞,
∞].
Typically, the [=input progress value=] is in the range [0, 1] but this may
not be the case when [=easing functions=] are chained together.
<div class=note>
An example of when easing functions are chained together occurs in
Web Animations [[WEB-ANIMATIONS]]
where the output of the easing function specified on an animation effect
may become the input to an easing function specified on
one of the keyframes of a keyframe effect.
In this scenario,
the input to the easing function on the keyframe effect
may be outside the range [0, 1].
</div>
The <dfn export for="easing function">output progress value</dfn> is a real number in the
range [-∞, ∞].
Note: While CSS numbers have a theoretically infinite range
(see [[css-values-4#numeric-ranges]])
UAs will automatically clamp enormous numbers to a reasonable range.
If easing functions are used outside of the CSS context,
care must be taken to either correctly handle potential infinities
(including those produced by merely <em>very large</em> values
stored in a floating point number),
or clamp the [=output progress value=].
Some types of easing functions
also take an additional boolean <dfn export for="easing function">before flag</dfn>,
which indicates the easing has not yet started,
or is going in reverse and is past the finish.
(Some easing functions can have multiple possible [=output progress values=]
for a given [=input progress value=],
and generally favor the last one specified;
this flag instead causes those [=easing functions=]
to favor the first specified value
before the animation has started.)
This specification defines several types of easing functions:
<pre class="prod">
<dfn><easing-function></dfn> = <<linear-easing-function>>
| <<cubic-bezier-easing-function>>
| <<step-easing-function>>
</pre>
<wpt>
timing-functions-syntax-computed.html
timing-functions-syntax-invalid.html
timing-functions-syntax-valid.html
</wpt>
<!-- Big Text: linear
█▌ ████ █ █▌ █████▌ ███▌ ████▌
█▌ ▐▌ █▌ █▌ █▌ ▐█ ▐█ █▌ █▌
█▌ ▐▌ ██▌ █▌ █▌ █▌ █▌ █▌ █▌
█▌ ▐▌ █▌▐█ █▌ ████ █▌ █▌ ████▌
█▌ ▐▌ █▌ ██▌ █▌ █████▌ █▌▐█
█▌ ▐▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█
█████ ████ █▌ ▐▌ █████▌ █▌ █▌ █▌ █▌
-->
<h3 id=the-linear-easing-function>
Linear Easing Functions: ''linear'', ''linear()''</h3>
A <dfn export>linear easing function</dfn>
is an [=easing function=]
that interpolates linearly
between its [=linear()/control points=].
Each <dfn for="linear()">control point</dfn>
is a pair of numbers,
associating an [=input progress value=]
to an [=output progress value=].
<figure>
<img class="easing-graph" src="images/linear-easing-curve.svg" width="535" height="510"
alt="A linear curve used as an easing function.">
<figcaption>
''linear(0, .1 25%, .75 50%, 1)''<br>
The shape of the curve follows the [=linear()/control points=].<br>
Input progress values serve as <var ignore>x</var> values of the curve,
whilst the <var ignore>y</var> values are the output progress values.
</figcaption>
</figure>
A [=linear easing function=] has the following syntax:
<pre class="prod">
<dfn><linear-easing-function></dfn> = linear | <<linear()>>
<dfn>linear()</dfn> = linear( [ <<number>> && <<percentage>>{0,2} ]# )
</pre>
<wpt>
linear-timing-functions-syntax.html
</wpt>
: ''linear''
:: Equivalent to ''linear(0, 1)''
: ''linear()''
::
Specifies a [=linear easing function=].
Each comma-separated argument specifies one or two [=linear()/control points=],
with an [=input progress value=] equal to the specified <<percentage>>
(converted to a <<number>> between 0 and 1),
and an [=output progress value=] equal to the specified <<number>>.
When the argument has two <<percentage>>s,
it defines two [=linear()/control points=] in the specified order,
one per <<percentage>>.
If an argument lacks a <<percentage>>,
its [=input progress value=] is initially empty,
but that is immediately corrected by [=linear() canonicalization=] after parsing.
<div algorithm>
To <dfn export lt="linear() canonicalization|canonicalize a linear()">canonicalize a linear()</dfn> function's [=linear()/control points=],
perform the following:
1. If the first [=control point=] lacks an [=input progress value=],
set its [=input progress value=] to 0.
2. If the last [=control point=] lacks an [=input progress value=],
set its [=input progress value=] to 1.
3. If any [=control point=] has an [=input progress value=]
that is less than the [=input progress value=] of any preceding [=control point=],
set its [=input progress value=] to the largest [=input progress value=]
of any preceding [=control point=].
4. If any [=control point=] still lacks an [=input progress value=],
then for each contiguous run of such [=linear()/control points=],
set their [=input progress values=]
so that they are evenly spaced
between the preceding and following [=linear()/control points=]
with [=input progress values=].
After canonicalization,
every [=control point=] has an [=input progress value=],
and the [=input progress values=] are monotonically non-decreasing
along the list.
Note: Serialization relies on whether or not an [=input progress value=]
was originally supplied,
so that information should be retained
in the [=CSS/internal representation=].
It does not rely on whether a pair of [=linear()/control points=]
were specified as two percentages on a single argument
or as separate arguments.
</div>
<h4 id=linear-easing-function-serializing>
Serializing</h4>
The ''linear'' keyword is serialized as itself.
<div algorithm>
To <dfn export>serialize a linear() function</dfn>:
1. Let |s| be the string "linear(".
2. [=serialize a linear() control point|Serialize each control point=] of the function,
[=string/concatenate=] the results using the separator ", ",
and append the result to |s|.
3. Append ")" to |s|,
and return it.
</div>
<div algorithm>
To <dfn export>serialize a linear() control point</dfn>:
1. Let |s| be the serialization,
as a <<number>>,
of the [=control point's=] [=output progress value=].
2. If the [=control point=] originally lacked an [=input progress value=],
return |s|.
3. Otherwise, append " " (U+0020 SPACE) to |s|,
then serialize the [=control point's=] [=input progress value=]
as a <<percentage>>
and append it to |s|.
4. Return |s|.
</div>
<div class=example>
When serialized,
[=linear()/control points=] originally specified with two [=input progress values=]
are turned into two separate [=linear()/control points=],
and the [=input progress values=] are in strictly ascending order.
For example:
- ''linear(0, 0.25, 1)'' serializes as ''linear(0, 0.25, 1)''
- ''linear(0 20%, 0.5 10%, 1)'' serializes as ''linear(0 20%, 0.5 20%, 1)''
- ''linear(0, 0.25 25% 75%, 1)'' serializes as ''linear(0, 0.25 25%, 0.25 75%, 1)''
</div>
<h4 id=linear-easing-function-output>
Output</h4>
<div algorithm>
To <dfn export>calculate linear easing output progress</dfn>
for a given [=linear easing function=] |func|,
an [=input progress value=] |inputProgress|,
and an optional [=before flag=] (defaulting to false),
perform the following.
It returns an [=output progress value=].
1. Let |points| be |func|'s [=linear()/control points=].
2. If |points| holds only a single item,
return the [=output progress value=]
of that item.
3. If |inputProgress| matches the [=input progress value=]
of the first point in |points|,
and the [=before flag=] is true,
return the first point's [=output progress value=].
4. If |inputProgress| matches the [=input progress value=]
of at least one point in |points|,
return the [=output progress value=] of the last such point.
5. Otherwise, find two [=linear()/control points=] in |points|,
|A| and |B|,
which will be used for interpolation:
1. If |inputProgress| is smaller
than any [=input progress value=] in |points|,
let |A| and |B| be the first two items in |points|.
If |A| and |B| have the same [=input progress value=],
return |A|'s [=output progress value=].
2. Otherwise, if |inputProgress| is larger
than any [=input progress value=] in |points|,
let |A| and |B| be the last two items in |points|.
If |A| and |B| have the same [=input progress value=],
return |B|'s [=output progress value=].
3. Otherwise, let |A| be the last [=linear()/control point=]
whose [=input progress value=] is smaller than |inputProgress|,
and let |B| be the first [=linear()/control point=]
whose [=input progress value=] is larger than |inputProgress|.
6. Linearly interpolate (or extrapolate) |inputProgress|
along the line defined by |A| and |B|,
and return the result.
<wpt>
linear-timing-functions-output.html
</wpt>
</div>
<h4 id=linear-easing-function-examples>
Examples</h4>
<div class=example>
''linear()'' allows the definition of easing functions that interpolate linearly between a set of points.
For example, ''linear(0, 0.25, 1)'' produces an easing function
that moves linearly from 0, to 0.25, then to 1:
<figure>
<img class="easing-graph" src="images/simple-linear-example.svg" width="535" height="510"
alt="linear(0, 0.25, 1) plotted on a graph">
</figure>
<figure>
<table>
<thead>
<tr><th>Easing<th>Example
<tbody>
<tr><td>''linear''<td><div class=easing-track style="--easing:linear"></div>
<tr><td>''linear(0, .25, 1)''<td><div class=easing-track style="--easing:linear(0, .25, 1)"></div>
</table>
<figcaption>
An example of the above, with a plain ''linear'' for contrast.
</figcaption>
</figure>
</div>
<div class=example>
By default, values are spread evenly between entries that don't have an explicit "input".
Input values can be provided using a <<percentage>>.
For example, ''linear(0, 0.25 75%, 1)'' produces the following easing function,
which spends 75% of the time transitioning from ''0'' to ''.25'',
then the last 25% transitioning from ''.25'' to ''1'':
<figure>
<img class="easing-graph" src="images/linear-with-input-example.svg" width="535" height="510"
alt="linear(0, 0.25 75%, 1) plotted on a graph.
The graph has three points.
The first is at 0,0.
The second is at 0.75,0.25.
The third is at 1,1.">
</figure>
<figure>
<table>
<thead>
<tr><th>Easing<th>Example
<tbody>
<tr><td>''linear''<td><div class=easing-track style="--easing:linear"></div>
<tr><td>''linear(0, .25 75%, 1)''<td><div class=easing-track style="--easing:linear(0, .25 75%, 1)"></div>
</table>
<figcaption>
An example of the above, with a plain ''linear'' for contrast.
</figcaption>
</figure>
</div>
</div>
<div class=example>
If two input values are provided for a single output,
it results in two points with the same output,
causing the easing to "pause" between the two inputs.
For example, ''linear(0, 0.25 25% 75%, 1)''
is equivalent to ''linear(0, 0.25 25%, 0.25 75%, 1)'',
producing the following easing function:
<figure>
<img class="easing-graph" src="images/linear-with-double-input-example.svg" width="535" height="510"
alt="linear(0, 0.25 75%, 1) plotted on a graph.
The graph has four points.
The first is at 0,0.
The second is at 0.25,0.25.
The third is at 0.75,0.25.
The forth is at 1,1.">
</figure>
<figure>
<table>
<thead>
<tr><th>Easing<th>Example
<tbody>
<tr><td>''linear''<td><div class=easing-track style="--easing:linear"></div>
<tr><td>''linear(0, 0.25 25% 75%, 1)''<td><div class=easing-track style="--easing:linear(0, 0.25 25% 75%, 1)"></div>
</table>
<figcaption>
An example of the above, with a plain ''linear'' for contrast.
</figcaption>
</figure>
</div>
</div>
<div class=example>
If the input is outside the range provided,
the trajectory of the nearest two points is continued.
For example, here are the implicit values from the previous function:
<figure>
<img class="easing-graph" src="images/linear-with-double-input-example-continued.svg" width="535" height="510"
alt="linear(0, 0.25 75%, 1) plotted on a graph.
The graph has four points.
The first is at 0,0.
The second is at 0.25,0.25.
The third is at 0.75,0.25.
The forth is at 1,1.
The ends of the graph are extended at the angle of the nearest two lines.">
</figure>
</div>
<div class=example>
A typical use of ''linear()'' is to provide many points to create the illusion of a curve.
For example, here's how ''linear()'' could be used to create a reusable "bounce" easing function:
```css
:root {
--bounce: linear(
/* Start to 1st bounce */
0, 0.063, 0.25, 0.563, 1 36.4%,
/* 1st to 2nd bounce */
0.812, 0.75, 0.813, 1 72.7%,
/* 2nd to 3rd bounce */
0.953, 0.938, 0.953, 1 90.9%,
/* 3rd bounce to end */
0.984, 1 100% 100%
);
}
.example {
animation-timing-function: var(--bounce);
}
```
The definition ends `1 100% 100%` to create two final points,
so inputs greater than 1 always output 1.
<figure>
<img class="easing-graph" src="images/linear-bounce-example.svg" width="535" height="510"
alt="The graph of a rough bounce easing.">
</figure>
<figure>
<table>
<thead>
<tr><th>Easing<th>Example
<tbody>
<tr><td>''linear''<td><div class=easing-track style="--easing:linear"></div>
<tr><td>''linear(...)''<td><div class=easing-track style="--easing:linear(0, 0.063, 0.25, 0.563, 1 36.4%, 0.812, 0.75, 0.813, 1 72.7%, 0.953, 0.938, 0.953, 1 90.9%, 0.984, 1 100% 100% )"></div>
</table>
<figcaption>
An example of the above, with a plain ''linear'' for contrast.
</figcaption>
</figure>
More points could be used to create a smoother result,
which may be needed for slower animations.
</div>
<!-- Big Text: bezier
████▌ █████▌ █████▌ ████ █████▌ ████▌
█▌ █▌ █▌ ▐▌ ▐▌ █▌ █▌ █▌
█▌ █▌ █▌ ▐▌ ▐▌ █▌ █▌ █▌
█████ ████ █▌ ▐▌ ████ ████▌
█▌ █▌ █▌ █ ▐▌ █▌ █▌▐█
█▌ █▌ █▌ █ ▐▌ █▌ █▌ ▐█
████▌ █████▌ █████▌ ████ █████▌ █▌ █▌
-->
<h3 id=cubic-bezier-easing-functions oldids=cubic-bezier-timing-functions>
Cubic Bézier Easing Functions:
''ease'', ''ease-in'', ''ease-out'', ''ease-in-out'', ''cubic-bezier()''</h3>
A <dfn export>cubic Bézier easing function</dfn>
is an [=easing function=] that interpolates smoothly from 0 to 1
using a cubic polynomial,
influenced by two control points
that the curve will approach
but (usually) not actually reach.
(The "endpoints" of the cubic Bézier
are fixed at (0,0) and (1,1), respectively.)
<figure>
<img class="easing-graph" src="images/cubic-bezier-easing-curve.svg" width="535" height="510"
alt="A cubic Bezier curve used as an easing function.">
<figcaption>
A cubic Bézier curve used as an easing function.<br>
The shape of the curve is determined by the location of the control
points <var ignore>P1</var> and <var ignore>P2</var>.<br>
Input progress values serve as <var ignore>x</var> values of the curve,
whilst the <var ignore>y</var> values are the output progress values.
</figcaption>
</figure>
A <a>cubic Bézier easing function</a> has the following syntax:
<pre class="prod">
<dfn><cubic-bezier-easing-function></dfn> =
''ease'' | ''ease-in'' | ''ease-out'' | ''ease-in-out'' | <<cubic-bezier()>>
<dfn>cubic-bezier()</dfn> = cubic-bezier( [ <<number [0,1]>>, <<number>> ]#{2} )
</pre>
The meaning of each value is as follows:
<dl dfn-type="value" dfn-for="<cubic-bezier-easing-function>">
: <dfn>ease-in</dfn>
:: A function that starts slowly and smoothly, then quickly approaches the endpoint with an almost linear curve.
Equivalent to ''cubic-bezier(0.42, 0, 1, 1)''.
: <dfn>ease-out</dfn>
:: A function that starts quickly with an almost linear curve, then slowly and smoothly approaches the endpoint.
Equivalent to ''cubic-bezier(0, 0, 0.58, 1)''.
: <dfn>ease-in-out</dfn>
:: A function that starts and ends slowly and smoothly, quickly traversing the middle part.
Equivalent to ''cubic-bezier(0.42, 0, 0.58, 1)''.
: <dfn>ease</dfn>
:: Similar to ''ease-in-out'', but with a quicker start and a slower finish.
Equivalent to ''cubic-bezier(0.25, 0.1, 0.25, 1)''.
: ''cubic-bezier( x1, y1, x2, y2 )''
:: Specifies a <a>cubic Bézier easing function</a>.
The <var ignore>x1</var> and <var ignore>y1</var> arguments
specify the first control point,
and <var ignore>x2</var> and <var ignore>y2</var> arguments
specify the second control point.
Both <var ignore>x</var> values must be in the range [0, 1]
or the definition is invalid.
<details class=note>
<summary>Details on cubic Bézier curves</summary>
Note that this does <em>not</em> use the [=input progress value=] as the "t" value
commonly used to parametrize cubic Bézier curves
(producing a 2d point as the output),
but rather uses it as the "x" value on the graph
(producing a y value as the output).
This means that only the <em>shape</em> of the curve matters,
not the velocity along that curve.
For example, ''cubic-bezier(0, 0, 0, 0)'' and ''cubic-bezier(1, 1, 1, 1)''
produce exactly the same (linear) easing,
despite the first's <em>velocity</em> following a <code>t<sup>3</sup></code> curve,
while the second follows a <code>t<sup>1/3</sup></code> curve.
<em>In general</em>, cubic Bézier curves can have loops:
places where a single x value is associated with multiple y values.
The restriction placed on the control points
(that their x values be in the [0,1] range)
prevent this,
so the resulting easing function is well-defined.
</details>
</dl>
The keyword values listed above are illustrated below.
<figure>
<img class="easing-graph" src="images/curve-keywords.svg" width="500"
alt="The easing functions produced by keyword values.">
<figcaption>
The easing functions produced by each of the cubic Bézier easing
function keyword values.
</figcaption>
</figure>
<figure>
<table>
<thead>
<tr><th>Easing<th>Example
<tbody>
<tr><td>''linear''<td><div class=easing-track style="--easing:linear"></div>
<tr><td>''ease-in''<td><div class=easing-track style="--easing:ease-in"></div>
<tr><td>''ease-out''<td><div class=easing-track style="--easing:ease-out"></div>
<tr><td>''ease-in-out''<td><div class=easing-track style="--easing:ease-in-out"></div>
<tr><td>''ease''<td><div class=easing-track style="--easing:ease"></div>
</table>
<figcaption>
The above easing functions in action, each applied to a 3s animation of the circles' 'left' property. A ''linear'' easing is provided for contrast.
</figcaption>
</figure>
<h4 id="bezier-serialization">
Serializing</h4>
The ''ease-in'', ''ease-out'', ''ease-in-out'', and ''ease'' keywords
serialize as themselves.
<div algorithm>
To <dfn export>serialize a cubic-bezier() function</dfn>:
1. Let |s| be the string "cubic-bezier(".
2. Serialize the function's four arguments as <<number>>s,
[=concatenate=] the results using the separator ", ",
and append the result to |s|.
3. Append ")" to |s|, and return it.
</div>
<h4 id=cubic-bezier-algo>
Output</h4>
<div algorithm>
To <dfn export lt="calculate cubic Bézier easing output progress|calculate cubic Bezier easing output progress">calculate cubic Bézier easing output progress</dfn>
for a given [=cubic Bézier easing function=] |func|
and an [=input progress value=] |inputProgress|,
perform the following.
It returns an [=output progress value=].
1. Let |p0| be the point (0,0),
|p1| be the point given by |func|'s first two arguments,
|p2| be the point given by |func|'s second two arguments,
and |p3| be the point (1,1).
2. If |inputProgress| is within the range [0,1] (inclusive),
return the y value
corresponding to |inputProgress| as an x value
for the cubic Bézier curve
defined as having |p0| and |p3| as endpoints,
and |p1| and |p2| as control points.
The evaluation of this curve is covered in many sources,
such as [[FUND-COMP-GRAPHICS]].
3. Otherwise, the curve is extended infinitely,
using the tangent of the curve at the endpoints.
This tangent is defined as the line between two points,
|t1| and |t2|.
* If |inputProgress| is less than 0,
let |t1| be |p0|.
1. If the x value of |p1| is greater than 0,
let |t2| be |p1|.
2. Otherwise, if the x value of |p2| is greater than 0,
let |t2| be |p2|.
3. Otherwise, return 0.
* If |inputProgress| is greater than 1,
let |t2| be |p3|.
1. If the x value of |p2| is less than 1,
let |t1| be |p2|.
2. Otherwise, if the x value of |p1| is less than 1,
let |t1| be |p1|.
3. Otherwise, return 1.
Return the y value
corresponding to |inputProgress| as an x value
for the line passing through |t1| and |t2|.
<wpt>
cubic-bezier-timing-functions-output.html
</wpt>
</div>
<!-- Big Text: steps
███▌ █████▌ █████▌ ████▌ ███▌
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
█▌ █▌ █▌ █▌ █▌ █▌
███▌ █▌ ████ ████▌ ███▌
█▌ █▌ █▌ █▌ █▌
█▌ █▌ █▌ █▌ █▌ █▌ █▌
███▌ █▌ █████▌ █▌ ███▌
-->
<h3 id=step-easing-functions oldids=step-timing-functions>
Step Easing Functions:
''step-start'', ''step-end'', ''steps()''</h3>
A <dfn>step easing function</dfn> is an [=easing function=]
that divides the input time into a specified number of intervals that
are equal in length,
and holds the output steady within each of those intervals.
It is defined by a number of <dfn for=steps()>steps</dfn>, and a <dfn for=steps()>step position</dfn>.
It has the following syntax:
<pre class="prod">
<dfn><step-easing-function></dfn> = ''step-start'' | ''step-end'' | <<steps()>>
<dfn>steps()</dfn> = steps( <<integer>>, <<step-position>>?)
<dfn type><step-position></dfn> = ''jump-start'' | ''jump-end'' | ''jump-none'' | ''jump-both''
| ''start'' | ''end''
</pre>
<wpt>
step-timing-functions-syntax.html
</wpt>
The meaning of each value is as follows:
<dl dfn-type=value dfn-for="<step-easing-function>, steps()">
: <dfn>step-start</dfn>
:: Jumps from the starting to the ending value
at the start of the easing interval.
Computes to ''steps(1, start)''
: <dfn>step-end</dfn>
:: Jumps from the starting to the ending value
at the end of the easing interval.
Computes to ''steps(1, end)''
<figure>
<img class="easing-graph" src="images/step-easing-keyword-examples.svg" width="500"
alt="Example step easing keywords.">
<figcaption>
Example step easing function keyword values.
</figcaption>
</figure>
: ''steps( <integer>, <step-position>? )''
:: Divides the input interval into a number of equal steps
specified by the <<integer>>.
Within each interval, the [=output progress value=] is constant,
and is determined according to the <<step-position>> keyword.
If omitted, the <<step-position>> keyword defaults to ''end''.
If the <<step-position>> is ''jump-none'',
the <<integer>> must be at least 2,
or the function is invalid.
Otherwise,
the <<integer>> must be at least 1,
or the function is invalid.
The <<step-position>> keywords are:
<dl dfn-type=value dfn-for="<step-position>, steps()">
: <dfn>jump-start</dfn>
:: The first interval has an [=output progress value=] of <code>1/steps</code>,
and subsequent intervals rise by <code>1/steps</code>.
(It "jumps at the start", with no step returning 0.)
: <dfn>jump-end</dfn>
:: The first interval has an [=output progress value=] of <code>0</code>,
and subsequent intervals rise by <code>1/steps</code>.
(It "jumps at the end", with no step returning 1.)
: <dfn>jump-none</dfn>
:: The first interval has an [=output progress value=] of <code>0</code>,
and subsequent intervals rise by <code>1/(steps-1)</code>.
(It "never jumps", with steps returning both 0 and 1.)
: <dfn>jump-both</dfn>
:: The first interval has an [=output progress value=] of <code>1/(steps+1)</code>,
and subsequent intervals rise by <code>1/(steps+1)</code>.
(It "jumps at both ends", with no steps returning 0 or 1.)
: <dfn>start</dfn>
:: Behaves as ''jump-start''.
: <dfn>end</dfn>
:: Behaves as ''jump-end''.
</dl>
</dl>
The ''jump-*'' keywords values are illustrated below:
<figure>
<img class="easing-graph" src="images/step-easing-func-examples.svg" width="500"
alt="Example step easing functions.">
<figcaption>
Example step easing functions.
</figcaption>
</figure>
<figure>
<table>
<thead>
<tr><th>Easing<th>Example
<tbody>
<tr><td>''linear''<td><div class=easing-track style="--easing:linear"></div>
<tr><td>''steps(3, jump-start)''<td><div class=easing-track style="--easing:steps(3, jump-start)"></div>
<tr><td>''steps(3, jump-end)''<td><div class=easing-track style="--easing:steps(3, jump-end)"></div>
<tr><td>''steps(3, jump-none)''<td><div class=easing-track style="--easing:steps(3, jump-none)"></div>
<tr><td>''steps(3, jump-both)''<td><div class=easing-track style="--easing:steps(3, jump-both)"></div>
</table>
<figcaption style="max-width: 80%;">
The above easing functions in action, with a ''linear'' provided for comparison.
Each ''steps(3, ...)'' function divides the animation into three constant periods;
they differ only on what the value is within each period.
</figcaption>
</figure>
<h4 id=steps-serialization>
Serializing</h4>
Unlike the other [=easing function=] keywords,
''step-start'' and ''step-end'' <em>do not</em> serialize as themselves.
Instead, they serialize as "steps(1, start)" and "steps(1)", respectively.
<div algorithm>
To <dfn export>serialize a steps() functions</dfn>:
1. Let |s| be the string "steps(".
2. Serialize the function's [=steps()/steps=],
and append it to |s|.
3. If the function's [=steps()/step position=] is ''end'' or ''jump-end'',
append ")" to |s| and return |s|.
4. Otherwise, append ", " to |s|.
Serialize the [=steps()/step position=] as a keyword,
and append the result to |s|.
Append ")" to |s|.
Return |s|.
<wpt>
timing-functions-syntax-computed.html
</wpt>
</div>
<h4 id=step-easing-algo oldids=step-timing-function-algo>
Output</h4>
<div algorithm>
To <dfn export>calculate step easing output progress</dfn>
for a given [=step easing function=] |func|,
an [=input progress value=] |inputProgress|,
and an optional [=before flag=] (defaulting to false),
perform the following.
It returns an [=output progress value=].
1. If the [=before flag=] is true, return 0.
2. Let |steps| be |func|'s [=steps()/steps=],
and |position| be |func|'s [=steps()/step position=].
3. Divide the interval [-∞, ∞] into several segments,
each with an associated value,
as follows:
1. [-∞, 0) has the value 0.
2. [1, ∞] has the value 1.
3. [0, 1) is divided into |steps| half-open intervals,
[0, ...) to [..., 1)
with their values assigned as defined for the |position|
(see <<step-position>>).
Note: In other words,
at the boundary between intervals,
the associated value is the higher value.
4. Return the associated value
for the interval that |inputProgress| is in.
<wpt>
step-timing-functions-output.html
</wpt>
</div>
<h2 class=no-num id=privacy>Privacy Considerations</h2>
<!-- Horizontal review wants Security and Privacy sections to be separate. -->
No new privacy considerations have been reported on this specification.
This specification does not directly introduce any new capabilities to the
Web platform but rather provides common definitions that may be referenced by
other specifications.
<h2 class=no-num id=security>Security Considerations</h2>
Specifications referencing the features defined in this specification
should consider that while easing functions most commonly
take an [=input progress value=] in the range [0,1]
and produce an [=output progress value=] in the range [0, 1],
this is not always the case.
Applications of easing functions should
define the behavior for inputs and outputs outside this range
to ensure they do not introduce new security considerations.
Changes {#changes}
=======
<h3 id="changes-20240828">
Changes since the FPWD of <a href="https://www.w3.org/TR/2024/WD-css-easing-2-20240828/">28 August 2024</a>
</h3>
<ul>
<li></li>
</ul>
<h3 id="changes-L1">
Additions Since Level 1</h3>
- Added ''linear()'' function.
Acknowledgements {#acknowledgements}
================