-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
1147 lines (818 loc) · 65.6 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 Transforms Module Level 1
Status: ED
Work Status: Refining
ED: https://drafts.csswg.org/css-transforms/
TR: https://www.w3.org/TR/css-transforms-1/
Previous Version: https://www.w3.org/TR/2012/WD-css3-transforms-20120911/
Previous Version: https://www.w3.org/TR/2012/WD-css3-transforms-20120403/
Shortname: css-transforms
Link Defaults: svg (property) to/stroke/fill, css-masking-1 (property) clip/clip-path, filters-1 (property) filter, css-backgrounds-3 (value) fixed, html (element) a
Level: 1
Group: fxtf
Editor: Simon Fraser, Apple Inc http://www.apple.com/, simon.fraser@apple.com, w3cid 44066
Editor: Dean Jackson, Apple Inc http://www.apple.com/, dino@apple.com, w3cid 42080
Editor: Theresa O'Connor, Apple Inc http://www.apple.com/, eoconnor@apple.com
Editor: Dirk Schulze, Adobe Systems Inc http://www.adobe.com/, dschulze@adobe.com, w3cid 51803
Former Editor: David Hyatt, Apple Inc http://www.apple.com/, hyatt@apple.com
Former Editor: Chris Marrin, Apple Inc http://www.apple.com/, cmarrin@apple.com
Former Editor: Aryeh Gregor, Mozilla http://www.mozilla.org/, ayg@aryeh.name
Abstract: CSS transforms allows elements styled with CSS to be transformed in two-dimensional space. This specification is the convergence of the <a href="https://www.w3.org/TR/css3-2d-transforms/">CSS 2D transforms</a> and <a href="https://www.w3.org/TR/2009/WD-SVG-Transforms-20090320/">SVG transforms</a> specifications.
!Issues List: <a href="https://github.com/w3c/csswg-drafts/issues?q=is%3Aissue+is%3Aopen+label%3Acss-transforms-1">in GitHub</a>
Ignored terms: calcMode, viewBox, baseVal, animVal
</pre>
<pre class=anchors>
text: transform; type: element-attr; for: ; spec: svg1.1; url: https://www.w3.org/TR/SVG11/coords.html#TransformAttribute
text: patternTransform; type: element-attr; for: pattern; spec: svg1.1; url: https://www.w3.org/TR/SVG11/pservers.html#PatternElementPatternTransformAttribute
text: patternUnits; type: element-attr; for: pattern; spec: svg1.1; url: https://www.w3.org/TR/SVG/pservers.html#PatternElementPatternUnitsAttribute
text: gradientTransform; type: element-attr; for: linearGradient; spec: svg1.1; url: https://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementGradientTransformAttribute
text: gradientUnits; type: element-attr; for: linearGradient; spec: svg1.1; url: https://www.w3.org/TR/SVG/pservers.html#LinearGradientElementGradientUnitsAttribute
</pre>
<pre class='link-defaults'>
spec: css-text-3; type: property
text: text-align
text: letter-spacing
text: word-spacing
spec:css-display-3; type:property
text: display
spec:css-display-3; type:value; for:display
text: table-row
text: table-row-group
text: table-header-group
text: table-footer-group
text: table-cell
text: table-caption
spec:css-backgrounds-3; type:property
text: background-attachment
</pre>
<style type="text/css">
.example {
clear:both
}
th {
text-align:left
}
.pseudo-code {
font-family:monospace
}
.pseudo-code > ol {
list-style-type:decimal
}
.pseudo-code > ol > li > ol {
list-style-type:lower-latin
}
.pseudo-code > ol > li > ol > li > ol {
list-style-type:lower-roman
}
.pseudo-code ul {
list-style-type:disc
}
dd > p:nth-child(1) {
margin-top:0
}
</style>
Introduction {#intro}
=====================
<em>This section is not normative.</em>
The CSS <a href="https://www.w3.org/TR/CSS2/visuren.html">visual formatting model</a> describes a coordinate system within each element is positioned. Positions and sizes in this coordinate space can be thought of as being expressed in pixels, starting in the origin of point with positive values proceeding to the right and down.
This coordinate space can be modified with the 'transform' property. Using transform, elements can be translated, rotated and scaled.
Module Interactions {#module-interactions}
------------------------------------------
This module defines a set of CSS properties that affect the visual rendering of elements to which those properties are applied; these effects are applied after elements have been sized and positioned according to the <a href="https://www.w3.org/TR/CSS2/visuren.html">visual formatting model</a> from [[!CSS2]]. Some values of these properties result in the creation of a <a href="https://www.w3.org/TR/CSS2/visuren.html#containing-block">containing block</a>, and/or the creation of a <a spec="css21">stacking context</a>.
Transforms affect the rendering of backgrounds on elements with a value of ''fixed'' for the 'background-attachment' property, which is specified in [[!CSS3BG]].
Transforms affect the client rectangles returned by the Element Interface Extensions <a href="https://www.w3.org/TR/cssom-view/#dom-element-getclientrects">getClientRects()</a> and <a href="https://www.w3.org/TR/cssom-view/#dom-element-getboundingclientrect">getBoundingClientRect()</a>, which are specified in [[CSSOM-VIEW]].
Transforms affect the computation of the <a href="https://www.w3.org/TR/css-overflow-3/#scrollable-overflow-region">scrollable overflow region</a> as described by [[CSS-OVERFLOW-3]].
CSS Values {#css-values}
------------------------
This specification follows the <a href="https://www.w3.org/TR/CSS21/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]].
Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]].
Other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> keywords as their property value.
For readability they have not been repeated explicitly.
Terminology {#terminology}
==========================
When used in this specification, terms have the meanings assigned in this section.
: <dfn>transformable element</dfn>
:: A transformable element is an element in one of these categories:
* an element whose layout is governed by the CSS box model which is either a <a href="https://www.w3.org/TR/CSS2/visuren.html#block-level">block-level</a> or <a href="https://www.w3.org/TR/CSS2/visuren.html#x13">atomic inline-level element</a>, or whose 'display' property computes to ''table-row'', ''table-row-group'', ''table-header-group'', ''table-footer-group'', ''table-cell'', or ''table-caption'' [[!CSS2]]
* an element in the SVG namespace and not governed by the CSS box model which has the attributes <a element-attr for>transform</a>, <{pattern/patternTransform}> or <{linearGradient/gradientTransform}> [[!SVG11]].
Issue(w3c/csswg-drafts#2033): Too restrictive and replace black list with white list?
Issue(w3c/csswg-drafts#908): How do transforms apply to inlines?
Issue(w3c/csswg-drafts#358): Adapte SVG2's content model for transformable elements.
: <dfn>transformed element</dfn>
:: An element with a computed value other than ''transform/none'' for the 'transform' property.
: <dfn export>user coordinate system</dfn>
: <dfn export>local coordinate system</dfn>
:: In general, a coordinate system defines locations and distances on the current canvas. The current local coordinate system (also user coordinate system) is the coordinate system that is currently active and which is used to define how coordinates and lengths are located and computed, respectively, on the current canvas.
The current user coordinate system has its origin at the top-left of a [=reference box=] specified by the 'transform-box' property. Percentage values are relative to the dimension of this reference box. One unit equals one CSS pixel.
: <dfn>transformation matrix</dfn>
:: A matrix that defines the mathematical mapping from one coordinate system into another. It is computed from the values of the 'transform' and 'transform-origin' properties as described <a href="#transformation-matrix-computation">below</a>.
: <dfn>current transformation matrix</dfn> (CTM)
:: A matrix that defines the mapping from the [=local coordinate system=] into the [=viewport coordinate system=].
: <dfn>2D matrix</dfn>
:: A 3x2 transformation matrix with 6 items or a 4x4 matrix with 16 items, where the items m<sub>31</sub>, m<sub>32</sub>, m<sub>13</sub>, m<sub>23</sub>, m<sub>43</sub>, m<sub>14</sub>, m<sub>24</sub>, m<sub>34</sub> are equal to ''0'' and m<sub>33</sub>, m<sub>44</sub> are equal to ''1''.
Issue(w3c/csswg-drafts#2186): should this spec mention 4x4 matrices?
: <dfn>identity transform function</dfn>
:: A <a href="#transform-functions">transform function</a> that is equivalent to a identity 4x4 matrix (see <a href="#mathematical-description">Mathematical Description of Transform Functions</a>). Examples for identity transform functions are ''translate(0)'', ''translateX(0)'', ''translateY(0)'', ''scale(1)'', ''scaleX(1)'', ''scaleY(1)'', ''rotate(0)'', ''skew(0, 0)'', ''skewX(0)'', ''skewY(0)'' and ''matrix(1, 0, 0, 1, 0, 0)''.
The Transform Rendering Model {#transform-rendering}
====================================================
<em>This section is normative.</em>
Specifying a value other than ''transform/none'' for the 'transform' property establishes a new [=local coordinate system=] at the element that it is applied to. The mapping from where the element would have rendered into that local coordinate system is given by the element's [=transformation matrix=]. Transformations are cumulative. That is, elements establish their local coordinate system within the coordinate system of their parent. From the perspective of the user, an element effectively accumulates all the 'transform' properties of its ancestors as well as any local transform applied to it. The accumulation of these transforms defines a [=current transformation matrix=] for the element.
The coordinate space is a coordinate system with two axes: the X axis increases horizontally to the right; the Y axis increases vertically downwards.
<p id="transformation-matrix-computation">
The [=transformation matrix=] is computed from the 'transform' and 'transform-origin' properties as follows:
1. Start with the identity matrix.
2. Translate by the computed X and Y of 'transform-origin'
3. Multiply by each of the transform functions in 'transform' property from left to right
4. Translate by the negated computed X and Y values of 'transform-origin'
Transforms apply to [=transformable elements=].
Note: Transformations do affect the visual rendering, but have no affect on the CSS layout other than affecting overflow. Transforms are also taken into account when computing client rectangles exposed via the Element Interface Extensions, namely <a href="https://www.w3.org/TR/cssom-view/#dom-element-getclientrects">getClientRects()</a> and <a href="https://www.w3.org/TR/cssom-view/#dom-element-getboundingclientrect">getBoundingClientRect()</a>, which are specified in [[CSSOM-VIEW]].
Issue(w3c/csswg-drafts#901): Overflow bounds that are computed at the end of layout can increase (but not decrease) by paint-level effects such as transforms.
<div class="example">
<pre>
div {
transform: translate(100px, 100px);
}</pre>
This transform moves the element by 100 pixels in both the X and Y directions.
<div class="figure">
<img src="examples/translate1.svg" alt="The 100px translation in X and Y"
width="470" height="250">
</div>
</div>
<div class="example">
<pre>
div {
height: 100px; width: 100px;
transform-origin: 50px 50px;
transform: rotate(45deg);
}
</pre>
The 'transform-origin' property moves the point of origin by 50 pixels in both the X and Y directions. The transform rotates the element clockwise by 45° about the point of origin. After all transform functions were applied, the translation of the origin gets translated back by -50 pixels in both the X and Y directions.
<div class="figure">
<img alt="The point of origin gets translated temporary" src="examples/origin1.svg" width="735" height="250">
</div>
</div>
<div class="example">
<pre>
div {
height: 100px; width: 100px;
transform: translate(80px, 80px) scale(1.5, 1.5) rotate(45deg);
}
</pre>
This transformation translates the local coordinate system by 80 pixels in both the X and Y directions, then applies a 150% scale, then a 45° clockwise rotation about the Z axis. The impact on the rendering of the element can be intepreted as an application of these transforms in reverse order: the elements is rotated, then scaled, then translated.
<div class="figure">
<img src="examples/compound_transform.svg" alt="The transform specified above" width="270" height="270">
</div>
Note that an identical rendering can be obtained by nesting elements with the equivalent transforms:
<pre>
<div style="transform: translate(80px, 80px)">
<div style="transform: scale(1.5, 1.5)">
<div style="transform: rotate(45deg)"></div>
</div>
</div>
</pre>
</div>
For elements whose layout is governed by the CSS box model, the transform property does not affect the flow of the content surrounding the transformed element. However, the extent of the overflow area takes into account transformed elements. This behavior is similar to what happens when elements are offset via relative positioning. Therefore, if the value of the 'overflow' property is ''overflow/scroll'' or ''overflow/auto'', scrollbars will appear as needed to see content that is transformed outside the visible area.
For elements whose layout is governed by the CSS box model, any value other than ''transform/none'' for the transform results in the creation of a stacking context. Implementations must paint the layer it creates, within its parent stacking context, at the same stacking order that would be used if it were a positioned element with ‘z-index: 0’. If an element with a transform is positioned, the ‘z-index’ property applies as described in [[!CSS2]], except that ‘auto’ is treated as ‘0’ since a new stacking context is always created
For elements whose layout is governed by the CSS box model, any value other than ''transform/none'' for the transform also causes the element to become a containing block, and the object acts as a containing block for fixed positioned descendants.
Issue(w3c/csswg-drafts#913): Is this effect on ''position: fixed'' necessary? If so, need to go into more detail here about why fixed positioned objects should do this, i.e., that it's much harder to implement otherwise.
<a href="https://www.w3.org/TR/css3-background/#fixed0">Fixed backgrounds</a> on the root element are affected by any transform specified for that element. For all other elements that are effected by a transform (i.e. have a transform applied to them, or to any of their ancestor elements), a value of ''fixed'' for the 'background-attachment' property is treated as if it had a value of ''background-attachment/scroll''. The computed value of 'background-attachment' is not affected.
Note: If the root element is transformed, the transformation applies to the entire canvas, including any background specified for the root element. Since <a href="https://www.w3.org/TR/css3-background/#special-backgrounds">the background painting area for the root element</a> is the entire canvas, which is infinite, the transformation might cause parts of the background that were originally off-screen to appear. For example, if the root element's background were repeating dots, and a transformation of ''scale(0.5)'' were specified on the root element, the dots would shrink to half their size, but there will be twice as many, so they still cover the whole viewport.
The 'transform' Property {#transform-property}
==============================================
A transformation is applied to the coordinate system an element renders into through the 'transform' property. This property contains a list of <a href="#transform-functions">transform functions</a>. The final transformation value for a coordinate system is obtained by converting each function in the list to its corresponding matrix like defined in <a href="#mathematical-description">Mathematical Description of Transform Functions</a>, then multiplying the matrices.
<pre class='propdef'>
Name: transform
Value: none | <<transform-list>>
Initial: none
Applies to: [=transformable elements=]
Inherited: no
Percentages: refer to the size of [=reference box=]
Computed value: As specified, but with relative lengths converted into absolute lengths.
Media: visual
Animatable: as <a href="#interpolation-of-transforms">transform</a>
</pre>
Any computed value other than ''transform/none'' for the transform affects containing block and stacking context, as described in [[#transform-rendering]].
<pre class=prod><dfn><transform-list></dfn> = <<transform-function>>+</pre>
Serialization of <<transform-function>>s {#serialization-of-transform-functions}
----------------------------------------
To serialize the <<transform-function>>s, serialize as per their individual grammars, in the order the grammars are written in, avoiding <<calc()>> expressions where possible, avoiding <<calc()>> transformations, omitting components when possible without changing the meaning, joining space-separated tokens with a single space, and following each serialized comma with a single space.
Serialization of the computed value of <<transform-list>> {#serialization-of-the-computed-value}
----------------------------------------------------------------
A <<transform-list>> for the computed value is serialized to one <<matrix()>> function by the following algorithm:
Issue(w3c/csswg-drafts#2186): keep 4x4 matrix here and below?
<ol class="algorithm">
1. Let <var>transform</var> be a 4x4 matrix initialized to the identity matrix. The elements <var ignore> m11</var>, <var ignore>m22</var>, <var ignore>m33</var> and <var ignore>m44</var> of <var>transform</var> must be set to ''1'' all other elements of <var>transform</var> must be set to ''0''.
2. Post-multiply all <<transform-function>>s in <<transform-list>> to <var>transform</var>.
3. Chose between <<matrix()>> or <<matrix3d()>> serialization:
<dl class="switch">
<dt>If <var>transform</var> is a [=2D matrix=]
<dd>Serialize <var>transform</var> to a <<matrix()>> function.
<dt>Otherwise
<dd>Serialize <var>transform</var> to a <<matrix3d()>> function.
</dl>
</ol>
The 'transform-origin' Property {#transform-origin-property}
============================================================
<pre class='propdef'>
Name: transform-origin
Value: [ left | center | right | top | bottom | <<length-percentage>> ]<br> | <br> [ left | center | right | <<length-percentage>> ]<br> [ top | center | bottom | <<length-percentage>> ] <<length>>?<br> |<br> [[ center | left | right ] && [ center | top | bottom ]] <<length>>?
Initial: 50% 50%
Applies to: [=transformable elements=]
Inherited: no
Percentages: refer to the size of [=reference box=]
Computed value: For <<length>> the absolute value, otherwise a percentage
Media: visual
Animatable: as <a href="https://drafts.csswg.org/css3-transitions/#animtype-simple-list">simple list</a> of <a href="https://drafts.csswg.org/css3-transitions/#animtype-lpcalc">length, percentage, or calc</a>
</pre>
The values of the 'transform' and 'transform-origin' properties are used to compute the [=transformation matrix=], as described above.
If only one value is specified, the second value is assumed to be <a value for=transform-origin>center</a>. If one or two values are specified, the third value is assumed to be ''0px''.
If two or more values are defined and either no value is a keyword, or the only used keyword is <a value for=transform-origin>center</a>, then the first value represents the horizontal position (or offset) and the second represents the vertical position (or offset). A third value always represents the Z position (or offset) and must be of type <<length>>.
<dl dfn-for="transform-origin" dfn-type="value">
: <<length-percentage>>
:: A percentage for the horizontal offset is relative to the width of the [=reference box=]. A percentage for the vertical offset is relative to the height of the [=reference box=]. The value for the horizontal and vertical offset represent an offset from the top left corner of the [=reference box=].
: <<length>>
:: A length value gives a fixed length as the offset. The value for the horizontal and vertical offset represent an offset from the top left corner of the [=reference box=].
: <dfn>top</dfn>
:: Computes to ''0%'' for the vertical position.
: <dfn>right</dfn>
:: Computes to ''100%'' for the horizontal position.
: <dfn>bottom</dfn>
:: Computes to ''100%'' for the vertical position.
: <dfn>left</dfn>
:: Computes to ''0%'' for the horizontal position.
: <dfn>center</dfn>
:: Computes to ''50%'' (''left 50%'') for the horizontal position if the horizontal position is not otherwise specified, or ''50%'' (''top 50%'') for the vertical position if it is.
</dl>
For SVG elements without associated CSS layout box the initial [=used value=] is ''0 0'' as if the user agent style sheet contained:
<pre>
*:not(svg), *:not(foreignObject) > svg {
transform-origin: 0 0;
}
</pre>
The 'transform-origin' property is a <a>resolved value special case</a> property like 'height'. [[!CSSOM]]
Transform reference box: the 'transform-box' property {#transform-box}
======================================================================
<pre class='propdef'>
Name: transform-box
Value: border-box | fill-box | view-box
Initial: view-box
Applies to: [=transformable elements=]
Inherited: no
Percentages: N/A
Computed value: Same as specified value.
Media: visual
Animatable: no
</pre>
All transformations defined by the 'transform' and 'transform-origin' property are relative to the position and dimensions of the <dfn>reference box</dfn> of the element. The [=reference box=] is specified by one of the following:
<dl dfn-for=transform-box>
: <dfn dfn-type=value>border-box</dfn>
:: Uses the border box as reference box. The reference box of a table is the border box of its <a href="https://www.w3.org/TR/CSS21/tables.html#model">table wrapper box</a>, not its table box.
: <dfn dfn-type=value>fill-box</dfn>
:: Uses the <a>object bounding box</a> as reference box.
: <dfn dfn-type=value>view-box</dfn>
:: Uses the nearest <a href="https://www.w3.org/TR/SVG11/intro.html#TermSVGViewport">SVG viewport</a> as reference box.
If a {{viewBox}} attribute is specified for the <a href="https://www.w3.org/TR/SVG11/intro.html#TermSVGViewport">SVG viewport</a> creating element:
* The reference box is positioned at the origin of the coordinate system established by the {{viewBox}} attribute.
* The dimension of the reference box is set to the <em>width</em> and <em>height</em> values of the {{viewBox}} attribute.
Issue(w3c/csswg-drafts#999): Follow used value definition of Fill and Stroke specs/SVG2?
</dl>
Issue(w3c/csswg-drafts#892): Clarify what the reference box of paint servers, <a element>clipPath</a> and <a element>mask</a> is.
A reference box adds an additional offset to the origin specified by the 'transform-origin' property.
For SVG elements without an associated CSS layout box, the [=used value=] for <a value for=transform-box>border-box</a> is <a value for=transform-box>view-box</a>.
For elements with an associated CSS layout box, the [=used value=] for <a value for=transform-box>fill-box</a> and <a value for=transform-box>view-box</a> is <a value for=transform-box>border-box</a>.
The SVG <a element-attr for>transform</a> Attribute {#svg-transform}
=============================
The SVG 1.1 specification did not specify the attributes <a element-attr for>transform</a>, <{linearGradient/gradientTransform}> or <{pattern/patternTransform}> as <a>presentation attributes</a> [[!SVG11]]. In order to improve the integration of SVG and HTML, this specification makes these SVG attributes presentation attributes and makes the 'transform' property one that applies to [=transformable elements=] in the SVG namespace.
Issue(w3c/csswg-drafts#919) Can patternTransform or gradientTransform or transform attributes apply to one element? If yes, which is the most significant?
This specification will also introduce the new presentation attribute 'transform-origin'. Values on this presentation attribute get parsed following the syntax rules on <a href="#svg-data-types">SVG Data Types</a> [[!SVG11]].
SVG <a element-attr for>transform</a> attribute specificity {#transform-attribute-specificity}
-------------------------------------
Since the previously named SVG attributes become presentation attributes, their participation in the CSS cascade is determined by the specificity of <a>presentation attributes</a> in the SVG specification.
<div class="example">
This example shows the combination of the 'transform' style property and the <a element-attr for>transform</a> presentation attribute.
<pre>
<svg xmlns="http://www.w3.org/2000/svg">
<style>
.container {
transform: translate(100px, 100px);
}
</style>
<g class="container" transform="translate(200 200)">
<rect width="100" height="100" fill="blue" />
</g>
</svg>
</pre>
<div class="figure">
<img src="examples/svg-translate1.svg" width="470" height="240" alt="Translated SVG container element.">
</div>
Because of the participation to the CSS cascade, the 'transform' style property overrides the <a element-attr for>transform</a> presentation attribute. Therefore the container gets translated by ''100px'' in both the horizontal and the vertical directions, instead of ''200px''.
</div>
Syntax of the SVG <a element-attr for>transform</a> attribute {#svg-syntax}
---------------------------------------
To provide backwards compatibility, the syntax of the <a element-attr for>transform</a> presentation attribute differs from the syntax of the 'transform' style property as shown in the example above. However, the syntax used for the 'transform' style property can be used for a '<a element-attr for>transform</a> presentation attribute value. Authors are advised to follow the rules of CSS Values and Units Module [[!CSS-VALUES-3]]. Therefore an author should write ''transform="translate(200px, 200px)"'' instead of ''transform="translate (200 200)"'' because the second example with the spaces before the ''('', the missing comma between the arguments and the values without the explicit unit notation would be valid for the attribute only.
### Transform List ### {#svg-transform-list}
The value for the <a element-attr for>transform</a> attribute consists of a transform list with zero or more transform functions using <a href="#svg-functional-notation">functional notation</a>. If the transform list consists of more than one transform function, these functions are separated by optional whitespace, an optional comma ('','') and optional whitespace. The transform list can have optional whitespace characters before and after the list.
### Functional Notation ### {#svg-functional-notation}
The syntax starts with the name of the function followed by a left parenthesis followed by optional whitespace followed by the argument(s) to the notation followed by optional whitespace followed by a right parenthesis. If a function takes more than one argument, the arguments are either separated by a comma ('','') with optional whitespace characters before and after the comma, or by one or more whitespace characters.
Note: Unlike SVG 1.1, this specification does not allow optional whitespace between the name of the function and the left parenthesis.
### SVG Data Types ### {#svg-data-types}
Arguments on all new introduced presentation attributes consist of data types in the sense of CSS Values and Units Module [[!CSS-VALUES-3]]. The definitions of data types in CSS Values and Units Module are enhanced as follows:
#### The <<length>> type #### {#svg-transform-value}
A <<length>> can be a <<number>> without an unit identifier. In this case the <a href="#svg-number">number</a> gets interpreted as "user unit". A user unit in the the <a href="https://www.w3.org/TR/2003/REC-SVG11-20030114/coords.html#InitialCoordinateSystem">initial coordinate system</a> is equivalent to the parent environment's notion of a pixel unit.
#### The <<angle>> type #### {#svg-angle}
An angle can be a <<number>> without an unit identifier. In this case the <a href="#svg-number">number</a> gets interpreted as a value in degrees.
#### The <<number>> type #### {#svg-number}
SVG supports scientific notations for numbers. Therefore a number gets parsed like described in SVG <a href="https://www.w3.org/TR/SVG/types.html#DataTypeNumber">Basic data types</a> for SVG attributes.
The SVG <{linearGradient/gradientTransform}> and <{pattern/patternTransform}> attributes {#svg-gradient-transform-pattern-transform}
----------------------------------------------------------------------------------------
SVG specifies the attributes <{linearGradient/gradientTransform}> and <{pattern/patternTransform}>. This specification makes both attributes presentation attributes. Both attributes use the same <a href="#svg-syntax">syntax</a> as the SVG <a element-attr for>transform</a> attribute. This specification does not introduce corresponding CSS style properties. Both the <{linearGradient/gradientTransform}> and the <{pattern/patternTransform}> attribute are presentation attributes for the 'transform' property.
SVG transform functions {#svg-transform-functions}
-----------------------
For backwards compatibility with existing SVG content, this specification supports all transform functions defined by <a href="https://www.w3.org/TR/SVG/coords.html#TransformAttribute">the ‘transform’ attribute</a> in [[SVG11]]. Therefore the two-dimensional transform function ''rotate(<angle>)'' is extended as follows:
<dl>
<dt id="rotate-three-function">
<pre class='prod'>''rotate()'' = rotate( <<angle>> [, <<length>>, <<length>>]? )</pre>
<dd>specifies a <a href="#RotateDefined">2D rotation</a> by the angle specified in the parameter about the origin of the element, as defined by the 'transform-origin' property. If the optional translation values are specified, the transform origin is translated by that amount (using the [=current transformation matrix=]) for the duration of the rotate operation. For example ''rotate(90deg, 100px, 100px)'' would cause elements to appear rotated one-quarter of a turn in the clockwise direction after a translation of the transform-origin of 100 pixel in the horizontal and vertical directions.
</dl>
User agents are just required to support the two optional arguments for translation on elements in the SVG namespace.
User coordinate space {#svg-user-coordinate-space}
---------------------
For the <{pattern}>, <{linearGradient}>, <{radialGradient}> and <{clipPath}> elements the <a element-attr for>transform</a>, <{pattern/patternTransform}>, <{linearGradient/gradientTransform}> presentation attributes represents values in the current user coordinate system in place at the time when these elements are referenced (i.e., the user coordinate system for the element referencing the <{pattern}> element via a 'fill' or 'stroke' property). Percentage values are relative to the [=reference box=] of the referencing element.
In particular the <{pattern/patternUnits}>, <{linearGradient/gradientUnits}> and <{mask/maskUnits}> attributes don't affect the user coordinate system used for transformations [[SVG11]].
For all other [=transformable elements=] the <a element-attr for>transform</a> presentation attribute represents values in the current user coordinate system of the parent. All percentage values of the <a element-attr for>transform</a> presentation attribute are relative to the element's [=reference box=].
Issue(w3c/csswg-drafts#893): User coordinate space statement breaks SVG.
<div class="example">
The 'transform-origin' property on the pattern in the following example specifies a ''50%'' translation of the origin in the horizontal and vertical dimension. The 'transform' property specifies a translation as well, but in absolute lengths.
<pre>
<svg xmlns="http://www.w3.org/2000/svg">
<style>
pattern {
transform: rotate(45deg);
transform-origin: 50% 50%;
}
</style>
<defs>
<pattern id="pattern-1">
<rect id="rect1" width="100" height="100" fill="blue" />
</pattern>
</defs>
<rect width="200" height="200" fill="url(#pattern-1)" />
</svg>
</pre>
An SVG <{pattern}> element doesn't have a bounding box. The [=reference box=] of the referencing <{rect}> element is used instead to solve the relative values of the 'transform-origin' property. Therefore the point of origin will get translated by 100 pixels temporarily to rotate the user space of the <{pattern}> elements content.
</div>
SVG DOM interface for the <a element-attr for>transform</a> attribute {#transform-attribute-dom}
-----------------------------------------------
The SVG specification defines the "<a href="https://www.w3.org/TR/2011/REC-SVG11-20110816/coords.html#InterfaceSVGAnimatedTransformList">SVGAnimatedTransformList</a>" interface in the SVG DOM to provide access to the animated and the base value of the SVG <a element-attr for>transform</a>, <{linearGradient/gradientTransform}> and <{pattern/patternTransform}> attributes. To ensure backwards compatibility, this API must still be supported by user agents.
The 'transform' property contributes to the CSS cascade. According to SVG 1.1 user agents conceptually insert a <a href="https://www.w3.org/TR/SVG/styling.html#UsingPresentationAttributes">new author style sheet</a> for presentation attributes, which is the first in the author style sheet collection. {{baseVal}} gives the author the possibility to access and modify the values of the SVG <a element-attr for>transform</a> attribute. To provide the necessary backwards compatibility to the SVG DOM, {{baseVal}} must reflect the values of this author style sheet. All modifications to SVG DOM objects of {{baseVal}} must affect this author style sheet immediately.
{{animVal}} represents the computed style of the 'transform' property. Therefore it includes all applied <a href="https://www.w3.org/TR/css3-transitions/">CSS3 Transitions</a>, <a href="https://www.w3.org/TR/css3-animations/">CSS3 Animations</a> or <a href="#svg-animation">SVG Animations</a> if any of those are underway. The computed style and SVG DOM objects of {{animVal}} can not be modified.
The attribute "<a href="https://www.w3.org/TR/SVG/coords.html#__svg__SVGTransform__type">type</a>" of '<a href="https://www.w3.org/TR/SVG/coords.html#InterfaceSVGTransform">SVGTransform</a>" must return "<a href="https://www.w3.org/TR/SVG/coords.html#__svg__SVGTransform__SVG_TRANSFORM_UNKNOWN">SVG_TRANSFORM_UNKNOWN</a>" for <a href="#transform-functions">Transform Functions</a> or unit types that are not supported by this interface. If a two-dimensional transform function is not supported, the attribute "<a href="https://www.w3.org/TR/SVG/coords.html#__svg__SVGTransform__matrix">matrix</a>" must return a 3x2 "<a href="https://www.w3.org/TR/SVG/coords.html#InterfaceSVGMatrix">SVGMatrix</a>" with the corresponding values as described in the section <a href="#mathematical-description">Mathematical Description of Transform Functions</a>.
SVG Animation {#svg-animation}
=============
The <{animate}> and <{set}> element {#svg-animate-element}
-----------------------------------
With this specification, the <{animate}> element and the <{set}> element can animate the data type <<transform-list>>.
The animation effect is post-multiplied to the underlying value for additive <{animate}> animations (see below) instead of added to the underlying value, due to the specific behavior of <<transform-list>> animations.
Issue(w3c/csswg-drafts#909) Clarify post-/pre-multiply column-/row-major order.
<var ignore=''>From-to</var>, <var ignore=''>from-by</var> and <var ignore=''>by</var> animations are defined in SMIL to be equivalent to a corresponding <var>values</var> animation. However, <var ignore=''>to</var> animations are a mixture of additive and non-additive behavior [[SMIL3]].
<var ignore=''>To</var> animations on <{animate}> provide specific functionality to get a smooth change from the underlying value to the <var ignore=''>to</var> attribute value, which conflicts mathematically with the requirement for additive transform animations to be post-multiplied. As a consequence, the behavior of <var ignore=''>to</var> animations for <{animate}> is undefined. Authors are suggested to use <var ignore=''>from-to</var>, <var ignore=''>from-by</var>, <var ignore=''>by</var> or <var ignore=''>values</var> animations to achieve any desired transform animation.
The value "paced" is undefined for the attribute <{animate/calcMode}> on <{animate}> for animations of the data type <<transform-list>>. If specified, UAs may choose the value "linear" instead. Future versions of this specification may define how paced animations can be performed on <<transform-list>>.
Note: The following paragraphs extend <a href="https://www.w3.org/TR/SVG/animate.html#complexDistances">Elements, attributes and properties that can be animated</a> [[SVG11]].
The introduced presentation attributes <a element-attr for>transform</a> and 'transform-origin' are animatable.
With this specification the SVG basic data type <<transform-list>> is equivalent to a list of <<transform-function>>s. <<transform-list>> is animatable and additive. The data type can be animated using the SVG <{animate}> element and the SVG <{set}> element. SVG animations must run the same animation steps as described in section <a href="#interpolation-of-transforms">Transitions and Animations between Transform Values</a>.
<table class="data">
<caption>Animatable data types</caption>
<thead>
<tr>
<th>Data type
<th>Additive?
<th><{animate}>
<th><{set}>
<th><{animateColor}>
<th><{animateTransform}>
<th>Notes
</thead>
<tbody>
<tr>
<th><<transform-list>>
<td>yes
<td>yes
<td>yes
<td>no
<td>yes
<td>Additive for <{animateTransform}> means that a transformation is post-multiplied to the base set of
transformations.
</tbody>
</table>
Neutral element for addition {#neutral-element}
----------------------------
Some animations require a neutral element for addition. For transform functions this is a scalar or a list of scalars of 0. Examples of neutral elements for transform functions are ''translate(0)'', ''translateX(0)'', ''translateY(0)'', ''scale(0)'', ''scaleX(0)'', ''scaleY(0)'', ''rotate(0)'', ''skew(0, 0)'', ''skewX(0)'', ''skewY(0)'' and ''matrix(0, 0, 0, 0, 0, 0)''.
Note: Animations to or from the neutral element of additions <<matrix()>> fall back to discrete animations (See [[#matrix-interpolation]]).
Issue(w3c/csswg-drafts#932): Replace text and simply refer to `null` value?
<div class="example">
A <var>by</var> animation with a by value v<sub>b</sub> is equivalent to the same animation with a values list with 2 values, the neutral element for addition for the domain of the target attribute (denoted 0) and v<sub>b</sub>, and ''additive="sum"''. [[SMIL3]]
<pre>
<rect width="100" height="100">
<animateTransform attributeName="transform" attributeType="XML"
type="scale" by="1" dur="5s" fill="freeze"/>
</rect>
</pre>
The neutral element for addition when performing a <var>by</var> animation with ''type="scale"'' is the value 0. Thus, performing the animation of the example above causes the rectangle to be invisible at time 0s (since the animated transform list value is ''scale(0)''), and be scaled back to its original size at time 5s (since the animated transform list value is ''scale(1)'').
</div>
The SVG '<a href="https://www.w3.org/TR/SVG/animate.html#TargetAttributes">attributeName</a>' attribute {#svg-attribute-name}
-------------------------------------------------------------------------------------------------------
<a href="https://www.w3.org/TR/SVG/animate.html">SVG 1.1 Animation</a> defines the "<a href="https://www.w3.org/TR/SVG/animate.html#TargetAttributes">attributeName</a>" attribute to specify the name of the target attribute. For the presentation attributes <{linearGradient/gradientTransform}> and <{pattern/patternTransform}> it will also be possible to use the value 'transform'. The same 'transform' property will get animated.
<div class="example">
In this example the gradient transformation of the linear gradient gets animated.
<pre><linearGradient gradientTransform="scale(2)">
<animate attributeName="gradientTransform" from="scale(2)" to="scale(4)"
dur="3s" additive="sum"/>
<animate attributeName="transform" from="translate(0, 0)" to="translate(100px, 100px)"
dur="3s" additive="sum"/>
</linearGradient></pre>
The <{linearGradient}> element specifies the <{linearGradient/gradientTransform}> presentation attribute. The two <{animate}> elements address the target attribute <{linearGradient/gradientTransform}> and 'transform'. Even so all animations apply to the same gradient transformation by taking the value of the <{linearGradient/gradientTransform}> presentation attribute, applying the scaling of the first animation and applying the translation of the second animation one after the other.
</div>
The Transform Functions {#transform-functions}
==============================================
The value of the 'transform' property is a list of <dfn><transform-function></dfn>.
The set of allowed transform functions is given below.
In the following functions,
a <<zero>> behaves the same as ''0deg''
("unitless 0" angles are preserved for legacy compat).
A percentage for horizontal translations is relative to the width of the [=reference box=].
A percentage for vertical translations is relative to the height of the [=reference box=].
2D Transform Functions {#two-d-transform-functions}
----------------------
<dl dfn-for=transform>
: <span class='prod'><dfn>matrix()</dfn> = matrix( <<number>> [, <<number>> ]{5,5} )</span>
:: specifies a 2D transformation in the form of a <a href="#MatrixDefined">transformation matrix</a> of the six values a, b, c, d, e, f.
: <span class='prod'><dfn>translate()</dfn> = translate( <<length-percentage>> [, <<length-percentage>> ]? )</span>
:: specifies a <a href="#TranslateDefined">2D translation</a> by the vector [tx, ty], where tx is the first translation-value parameter and ty is the optional second translation-value parameter. If <em><ty></em> is not provided, ty has zero as a value.
: <span class='prod'><dfn>translateX()</dfn> = translateX( <<length-percentage>> )</span>
:: specifies a <a href="#TranslateDefined">translation</a> by the given amount in the X direction.
: <span class='prod'><dfn>translateY()</dfn> = translateY( <<length-percentage>> )</span>
:: specifies a <a href="#TranslateDefined">translation</a> by the given amount in the Y direction.
: <span class='prod'><dfn>scale()</dfn> = scale( <<number>> [, <<number>> ]? )</span>
:: specifies a <a href="#ScaleDefined">2D scale</a> operation by the [sx,sy] scaling vector described by the 2 parameters. If the second parameter is not provided, it takes a value equal to the first. For example, scale(1, 1) would leave an element unchanged, while scale(2, 2) would cause it to appear twice as long in both the X and Y axes, or four times its typical geometric size.
: <span class='prod'><dfn>scaleX()</dfn> = scaleX( <<number>> )</span>
:: specifies a <a href="#ScaleDefined">2D scale</a> operation using the [sx,1] scaling vector, where sx is given as the parameter.
: <span class='prod'><dfn>scaleY()</dfn> = scaleY( <<number>> )</span>
:: specifies a <a href="#ScaleDefined">2D scale</a> operation using the [1,sy] scaling vector, where sy is given as the parameter.
: <span class='prod'><dfn>rotate()</dfn> = rotate( [ <<angle>> | <<zero>> ] )</span>
:: specifies a <a href="#RotateDefined">2D rotation</a> by the angle specified in the parameter about the origin of the element, as defined by the 'transform-origin' property. For example, ''rotate(90deg)'' would cause elements to appear rotated one-quarter of a turn in the clockwise direction.
: <span class='prod'><dfn>skew()</dfn> = skew( [ <<angle>> | <<zero>> ] [, [ <<angle>> | <<zero>> ] ]? )</span>
:: specifies a <a href="#SkewDefined">2D skew</a> by [ax,ay] for X and Y. If the second parameter is not provided, it has a zero value.
Advisement: ''skew()'' exists for compatibility reasons, and should not be used in new content. Use ''skewX()'' or ''skewY()'' instead, noting that the behavior of ''skew()'' is different from multiplying ''skewX()'' with ''skewY()''.
: <span class='prod'><dfn>skewX()</dfn> = skewX( [ <<angle>> | <<zero>> ] )</span>
:: specifies a <a href="#SkewXDefined">2D skew transformation along the X axis</a> by the given angle.
: <span class='prod'><dfn>skewY()</dfn> = skewY( [ <<angle>> | <<zero>> ] )</span>
:: specifies a <a href="#SkewYDefined">2D skew transformation along the Y axis</a> by the given angle.
</dl>
The Transform Function Lists {#transform-function-lists}
========================================================
If a list of <<transform-function>> is provided, then the net effect is as if each transform function had been specified separately in the order provided. For example,
<pre>
<div style="transform:translate(-10px,-20px) scale(2) rotate(45deg) translate(5px,10px)"/>
</pre>
is functionally equivalent to:
<pre>
<div style="transform:translate(-10px,-20px)">
<div style="transform:scale(2)">
<div style="transform:rotate(45deg)">
<div style="transform:translate(5px,10px)">
</div>
</div>
</div>
</div>
</pre>
That is, in the absence of other styling that affects position and dimensions, a nested set of transforms is equivalent to a single list of transform functions, applied from the outside in. The resulting transform is the matrix multiplication of the list of transforms.
If a transform function causes the [=current transformation matrix=] of an object to be non-invertible, the object and its content do not get displayed.
<div class="example">
The object in the following example gets scaled by 0.
<pre>
<style>
.box {
transform: scale(0);
}
</style>
<div class="box">
Not visible
</div>
</pre>
The scaling causes a non-invertible CTM for the coordinate space of the div box. Therefore neither the div box, nor the text in it get displayed.
</div>
Interpolation of Transforms {#interpolation-of-transforms}
==========================================================
When animating or transitioning transforms, the transform function lists must be interpolated. For interpolation between one transform <em>from-transform</em> and a second transforms <em>to-transform</em>, the rules described below are applied.
<ul>
<li id="none-none-animation">
If both the <em>from-</em> and <em>to-transform</em> are ''transform/none'':
* There is no interpolation necessary. The computed value stays ''transform/none''.
<li id="none-transform-animation">
If one of the <em>from-</em> or <em>to-transforms</em> is ''transform/none''.
* The value ''transform/none'' is replaced by an equivalent [=identity transform function=] list for the corresponding transform function list. Both transform function lists get interpolated following the next rule.
<div class="example">
For example, if <em>from-transform</em> is ''scale(2)'' and <em>to-transform</em> is ''transform/none'' then the value ''scale(1)'' will be used for <em>to-transform</em> and animation will proceed using the next rule. Similarly, if <em>from-transform</em> is ''transform/none'' and <em>to-transform</em> is ''scale(2) rotate(50deg)'' then the animation will execute as if <em>from-transform</em> is ''scale(1) rotate(0)''.
</div>
<li id="transform-transform-animation">
If <em>from-</em> and <em>to-transform</em> have the same number of transform functions, each transform function pair has either the same name, or is a derivative of the same <a href="#transform-primitives">primitive</a>.
* Interpolate each transform function pair as described in <a href="#interpolation-of-transform-functions">Interpolation of transform functions</a>. The computed value is the resulting transform function list.
<div class="example">
For example, if <em>from-transform</em> is ''scale(1) translate(0)'' and <em>to-transform</em> is ''translate(100px) scale(2)'' then ''scale(1)'' and ''translate(100px)'' as well as ''translate(0)'' and ''scale(2)'' don't share a common primitive and therefore can not get interpolated following this rule.
</div>
<li id="other-animation">
In all other cases:
* The transform functions of each transform function list on the <em>from-</em> and <em>to-transform</em> get post multiplied and converted into 4x4 matrices. Each of the matrices gets interpolated following the instructions in <a href="#matrix-interpolation">Interpolation of matrices</a>. The computed value is the transform function ''matrix'' if both initial matrices can be represented by a correlating 3x2 matrix and ''matrix3d'' otherwise.
</ul>
In some cases, an animation might cause a transformation matrix to be singular or non-invertible. For example, an animation in which scale moves from 1 to -1. At the time when the matrix is in such a state, the transformed element is not rendered.
Issue(w3c/csswg-drafts#927): Use proposed tranform interpolation from GitHub issue.
Transform function primitives and derivatives {#transform-primitives}
=====================================================================
Some transform functions can be represented by more generic transform functions. These transform functions are called derived transform functions, the generic transform functions primitives. Primitives for two-dimensional and three-dimensional transform functions are listed below.
Two-dimensional primitives with derived transform functions are:
<dl>
<dt id="translate-primitive">''translate()''
<dd>for <<translateX()>>, <<translateY()>> and <<translate()>>.
<dt id="rotate-three-primitive">''rotate()'' with three arguments
<dd>for <<rotate()>> with one or three arguments if <a href="#svg-transform-functions">rotate with three arguments</a> is supported.
<dt id="scale-primitive">''scale()''
<dd>for <<scaleX()>>, <<scaleY()>> and <<scale()>>.
</dl>
Issue(w3c/csswg-drafts#2186): Move the following lines to CSS-Transforms-2.
Three-dimensional primitives with derived transform functions are:
<dl>
<dt id="translate3d-primitive">''translate3d()''
<dd>for <<translateX()>>, <<translateY()>>, ''translateZ()'' and <<translate()>>.
<dt id="scale3d-primitive">''scale3d()''
<dd>for <<scaleX()>>, <<scaleY()>>, ''scaleZ()'' and <<scale()>>.
<dt id="rotate3d-primitive">''rotate3d()''
<dd>for <<rotate()>>, ''rotateX()'', ''rotateY()'' and ''rotateZ()''.
</dl>
<p id="interpolation-two-three-dimensional-function">
For derived transform functions that have a two-dimensional primitive and a three-dimensional primitive, the context decides about the used primitive. See <a href="#interpolation-of-transform-functions">Interpolation of primitives and derived transform functions</a>.
Interpolation of primitives and derived transform functions {#interpolation-of-transform-functions}
===================================================================================================
Two transform functions with the same name and the same number of arguments are interpolated numerically without a former conversion. The calculated value will be of the same transform function type with the same number of arguments. Special rules apply to <<matrix()>>.
<div class="example">
The two transform functions ''translate(0)'' and ''translate(100px)'' are of the same type, have the same number of arguments and therefore can get interpolated numerically. ''translateX(100px)'' is not of the same type and ''translate(100px, 0)'' does not have the same number of arguments, therefore these transform functions can not get interpolated without a former conversion step.
</div>
Two different types of transform functions that share the same primitive, or transform functions of the same type with different number of arguments can be interpolated. Both transform functions need a former conversion to the common primitive first and get interpolated numerically afterwards. The computed value will be the primitive with the resulting interpolated arguments.
<div class="example">
The following example describes a transition from ''translateX(100px)'' to ''translateY(100px)'' in 3 seconds on hovering over the div box. Both transform functions derive from the same primitive ''translate()''
and therefore can be interpolated.
<pre>
div {
transform: translateX(100px);
}
div:hover {
transform: translateY(100px);
transition: transform 3s;
}
</pre>
For the time of the transition both transform functions get transformed to the common primitive. ''translateX(100px)'' gets converted to ''translate(100px, 0)'' and ''translateY(100px)'' gets converted to ''translate(0, 100px)''. Both transform functions can then get interpolated numerically.
</div>
If both transform functions share a primitive in the two-dimensional space, both transform functions get converted to the two-dimensional primitive. If one or both transform functions are three-dimensional transform functions, the common three-dimensional primitive is used.
<div class="example">
In this example a two-dimensional transform function gets animated to a three-dimensional transform function. The common primitive is ''translate3d()''.
<pre>
div {
transform: translateX(100px);
}
div:hover {
transform: translateZ(100px);
transition: transform 3s;
}
</pre>
First ''translateX(100px)'' gets converted to ''translate3d(100px, 0, 0)'' and ''translateZ(100px)'' to ''translate3d(0, 0, 100px)'' respectively. Then both converted transform functions get interpolated numerically.
</div>
Interpolation of Matrices {#matrix-interpolation}
=================================================
When interpolating between two matrices, each matrix is decomposed into the corresponding translation, rotation, scale, skew. Each corresponding component of the decomposed matrices gets interpolated numerically and recomposed back to a matrix in a final step.
In the following example the element gets translated by 100 pixel in both the X and Y directions and rotated by 1170° on hovering. The initial transformation is 45°. With the usage of transition, an author might expect a animated, clockwise rotation by three and a quarter turns (1170°).
<div class="example">
<pre>
<style>
div {
transform: rotate(45deg);
}
div:hover {
transform: translate(100px, 100px) rotate(1215deg);
transition: transform 3s;
}
</style>
<div></div>
</pre>
</div>
The number of transform functions on the source transform ''rotate(45deg)'' differs from the number of transform functions on the destination transform ''translate(100px, 100px) rotate(1125deg)''. According to the last rule of <a href="#interpolation-of-transforms">Interpolation of Transforms</a>, both transforms must be interpolated by matrix interpolation. With converting the transformation functions to matrices, the information about the three turns gets lost and the element gets rotated by just a quarter turn (90°).
To achieve the three and a quarter turns for the example above, source and destination transforms must fulfill the third rule of <a href="#interpolation-of-transforms">Interpolation of Transforms</a>. Source transform could look like ''translate(0, 0) rotate(45deg)'' for a linear interpolation of the transform functions.
In the following we differ between the <a href="#interpolation-of-2d-matrices">interpolation of two 2D matrices</a> and the interpolation of two matrices where at least one matrix is not a [=2D matrix=].
If one of the matrices for interpolation is non-invertible, the used animation function must fall-back to a discrete animation according to the rules of the respective animation specification.
<h3 id="supporting-functions">Supporting functions</h3>
The pseudo code in the next subsections make use of the following supporting functions:
<pre>
Supporting functions (point is a 3 component vector, matrix is a 4x4 matrix, vector is a 4 component vector):
double determinant(matrix) returns the 4x4 determinant of the matrix
matrix inverse(matrix) returns the inverse of the passed matrix
matrix transpose(matrix) returns the transpose of the passed matrix
point multVecMatrix(point, matrix) multiplies the passed point by the passed matrix
and returns the transformed point
double length(point) returns the length of the passed vector
point normalize(point) normalizes the length of the passed point to 1
double dot(point, point) returns the dot product of the passed points
double sqrt(double) returns the root square of passed value
double max(double y, double x) returns the bigger value of the two passed values
double dot(vector, vector) returns the dot product of the passed vectors
vector multVector(vector, vector) multiplies the passed vectors
double sqrt(double) returns the root square of passed value
double max(double y, double x) returns the bigger value of the two passed values
double min(double y, double x) returns the smaller value of the two passed values
double cos(double) returns the cosines of passed value
double sin(double) returns the sine of passed value
double acos(double) returns the inverse cosine of passed value
double abs(double) returns the absolute value of the passed value
double rad2deg(double) transforms a value in radian to degree and returns it
double deg2rad(double) transforms a value in degree to radian and returns it
Decomposition also makes use of the following function:
point combine(point a, point b, double ascl, double bscl)
result[0] = (ascl * a[0]) + (bscl * b[0])
result[1] = (ascl * a[1]) + (bscl * b[1])
result[2] = (ascl * a[2]) + (bscl * b[2])
return result
</pre>
<h3 id="interpolation-of-2d-matrices">Interpolation of 2D matrices</h3>
<h4 id="decomposing-a-2d-matrix">Decomposing a 2D matrix</h4>
The pseudo code below is based upon the "unmatrix" method in "Graphics Gems II, edited by Jim Arvo".
Issue(w3c/csswg-drafts#924): Clarify column/row order for matrix in pseudo code.
Issue(w3c/csswg-drafts#483): Incorrect indices for matrix?
<pre>
Input: matrix ; a 4x4 matrix
Output: translation ; a 2 component vector
scale ; a 2 component vector
angle ; rotation
m11 ; 1,1 coordinate of 2x2 matrix
m12 ; 1,2 coordinate of 2x2 matrix
m21 ; 2,1 coordinate of 2x2 matrix
m22 ; 2,2 coordinate of 2x2 matrix
Returns false if the matrix cannot be decomposed, true if it can
double row0x = matrix[0][0]
double row0y = matrix[0][1]
double row1x = matrix[1][0]
double row1y = matrix[1][1]
translate[0] = matrix[3][0]
translate[1] = matrix[3][1]
scale[0] = sqrt(row0x * row0x + row0y * row0y)
scale[1] = sqrt(row1x * row1x + row1y * row1y)
// If determinant is negative, one axis was flipped.
double determinant = row0x * row1y - row0y * row1x
if (determinant < 0)
// Flip axis with minimum unit vector dot product.
if (row0x < row1y)
scale[0] = -scale[0]
else
scale[1] = -scale[1]
// Renormalize matrix to remove scale.
if (scale[0])
row0x *= 1 / scale[0]
row0y *= 1 / scale[0]
if (scale[1])
row1x *= 1 / scale[1]
row1y *= 1 / scale[1]
// Compute rotation and renormalize matrix.
angle = atan2(row0y, row0x);
if (angle)
// Rotate(-angle) = [cos(angle), sin(angle), -sin(angle), cos(angle)]
// = [row0x, -row0y, row0y, row0x]
// Thanks to the normalization above.
double sn = -row0y
double cs = row0x
double m11 = row0x
double m12 = row0y
double m21 = row1x
double m22 = row1y
row0x = cs * m11 + sn * m21
row0y = cs * m12 + sn * m22
row1x = -sn * m11 + cs * m21
row1y = -sn * m12 + cs * m22
m11 = row0x
m12 = row0y
m21 = row1x
m22 = row1y
// Convert into degrees because our rotation functions expect it.
angle = rad2deg(angle)
return true
</pre>
<h4 id="interpolation-of-decomposed-2d-matrix-values">
Interpolation of decomposed 2D matrix values
</h4>
Before two decomposed 2D matrix values can be interpolated, the following