8000 csswg-drafts/css-transforms/Overview.bs at 322217fbbb764aeb0543cd477e55f00e3d7da3a2 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
2474 lines (1968 loc) · 133 KB

File metadata and controls

2474 lines (1968 loc) · 133 KB
<h1>CSS Transforms Module Level 1</h1>
<pre class='metadata'>
Status: ED
Work Status: Refining
ED: http://dev.w3.org/csswg/css-transforms/
TR: http://www.w3.org/TR/css3-transforms/
Previous Version: http://www.w3.org/TR/2012/WD-css3-transforms-20120911/
Previous Version: http://www.w3.org/TR/2012/WD-css3-transforms-20120403/
Shortname: css-transforms
Link Defaults: svg (property) to/stroke/fill, css-flexbox-1 (property) display, css-masking-1 (property) clip/clip-path, filters-1 (property) filter
Level: 1
Group: fxtf
Editor: Simon Fraser, Apple Inc http://www.apple.com/, simon.fraser@apple.com
Editor: Dean Jackson, Apple Inc http://www.apple.com/, dino@apple.com
Editor: Edward O'Connor, Apple Inc http://www.apple.com/, eoconnor@apple.com
Editor: Dirk Schulze, Adobe Systems Inc http://www.adobe.com/, dschulze@adobe.com
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 or three-dimensional space. This specification is the convergence of the <a href="http://www.w3.org/TR/css3-2d-transforms/">CSS 2D transforms</a>, <a href="http://www.w3.org/TR/css3-3d-transforms/">CSS 3D transforms</a> and <a href="http://www.w3.org/TR/2009/WD-SVG-Transforms-20090320/">SVG transforms</a> specifications.
!Issues List: <a href="https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&product=CSS&component=Transforms&resolution=---&cmdtype=doit">in Bugzilla</a>
Use <I> Autolinks: yes
</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>
<h2 id="intro">Introduction</h2>
<em>This section is not normative.</em>
The CSS <a href="http://www.w3.org/TR/REC-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 in two or three dimensional space.
Additional properties make working with transforms easier, and allow the author to control how nested three-dimensional transforms interact.
<ul>
<li>
The 'transform-origin' property provides a convenient way to control the origin about which transforms on an element are applied.
</li>
<li>
The 'perspective' property allows the author to make child elements with three-dimensional transforms appear as if they live in a common three-dimensional space. The 'perspective-origin' property provides control over the origin at which perspective is applied, effectively changing the location of the "vanishing point".
</li>
<li>
The 'transform-style' property allows 3D-transformed elements and their 3D-transformed descendants to share a common three-dimensional space, allowing the construction of hierarchies of three-dimensional objects.
</li>
<li>
The 'backface-visibility' property comes into play when an element is flipped around via three-dimensional transforms such that its reverse side is visible to the viewer. In some situations it is desirable to hide the element in this situation, which is possible using the value of ''hidden'' for this property.
</li>
</ul>
Note: While some values of the 'transform' property allow an element to be transformed in a three-dimensional coordinate system, the elements themselves are not three-dimensional objects. Instead, they exist on a two-dimensional plane (a flat surface) and have no depth.
<h2 id="module-interactions">Module Interactions</h2>
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="http://www.w3.org/TR/CSS2/visuren.html">Visual formatting model</a> from [[!CSS21]]. Some values of these properties result in the creation of a <a href="http://www.w3.org/TR/CSS2/visuren.html#containing-block">containing block</a>, and/or the creation of a <a spec="css21">stacking context</a>.
Three-dimensional transforms can also affect the visual layering of elements, and thus override the back-to-front painting order described in <a href="http://www.w3.org/TR/CSS2/zindex.html">Appendix E</a> of [[!CSS21]].
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="http://www.w3.org/TR/cssom-view/#dom-element-getclientrects">getClientRects()</a> and <a href="http://www.w3.org/TR/cssom-view/#dom-element-getboundingclientrect">getBoundingClientRect()</a>, which are specified in [[CSSOM-VIEW]].
<h2 id="css-values">CSS Values</h2>
This specification follows the <a href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property definition conventions</a> from [[!CSS21]]. Value types not defined in these specifications are defined in CSS Values and Units Module Level 3 [[!CSS3VAL]].
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the <a href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">inherit</a> keyword as their property value. For readability it has not been repeated explicitly.
<!--
/$$$$$$$$
|__ $$__/
| $$ /$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$$
| $$ /$$__ $$ /$$__ $$| $$_ $$_ $$ /$$_____/
| $$| $$$$$$$$| $$ \__/| $$ \ $$ \ $$| $$$$$$
| $$| $$_____/| $$ | $$ | $$ | $$ \____ $$
| $$| $$$$$$$| $$ | $$ | $$ | $$ /$$$$$$$/
|__/ \_______/|__/ |__/ |__/ |__/|_______/
-->
<h2 id="terminology">Terminology</h2>
When used in this specification, terms have the meanings assigned in this section.
<dl>
<dt><dfn>transformable element</dfn></dt>
<dd>
A transformable element is an element in one of these categories:
<ul>
<li>
an element whose layout is governed by the CSS box model which is either a <a href="http://www.w3.org/TR/CSS2/visuren.html#block-level">block-level</a> or <a href="http://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'' [[!CSS21]]
</li>
<li>
an element in the SVG namespace and not governed by the CSS box model which has the attributes 'transform', <a>'patternTransform'</a> or <a>'linearGradient/gradientTransform'</a> [[!SVG11]].
</li>
</ul>
</dd>
<dt><dfn>transformed element</dfn></dt>
<dd>
An element with a computed value other than ''none'' for the 'transform' property.
</dd>
<dt><dfn>3D-transformed element</dfn></dt>
<dd>
An element whose computed value for the 'transform' property includes one of the <a href="#three-d-transform-functions">3D transform functions</a>
</dd>
<dt><dfn export>user coordinate system</dfn></dt>
<dt><dfn export>local coordinate system</dfn></dt>
<dd>
<p>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.</p>
<p>The current user coordinate system has its origin at the top-left of a <i>reference box</i> specified by the 'transform-box' property. Percentage values are relative to the dimension of this reference box. One unit equals one CSS pixel.</p>
</dd>
<dt><dfn>perspective matrix</dfn></dt>
<dd>
A matrix computed from the values of the 'perspective' and 'perspective-origin' properties as described <a href="#perspective-matrix-computation">below</a>.
</dd>
<dt><dfn>transformation matrix</dfn></dt>
<dd>
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>.
</dd>
<dt><dfn>current transformation matrix (CTM)</dfn></dt>
<dd>
A matrix that defines the mapping from the local coordinate system into the viewport coordinate system.
</dd>
<dt><dfn>accumulated 3D transformation matrix</dfn></dt>
<dd>
A matrix computed for an element relative to the root of its <i>3D rendering context</i>, as described <a href="#accumulated-3d-transformation-matrix-computation">below</a>.
</dd>
<dt><dfn>2D matrix</dfn></dt>
<dd>
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''.
</dd>
<dt><dfn>3D matrix</dfn></dt>
<dd>
A 4x4 matrix which does not fulfill the requirements of an <i>2D matrix</i>.
</dd>
<dt><dfn>identity transform function</dfn></dt>
<dd>
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)'', ''translate3d(0, 0, 0)'', ''translateX(0)'', ''translateY(0)'', ''translateZ(0)'', ''scale(1)'', ''scaleX(1)'', ''scaleY(1)'', ''scaleZ(1)'', ''rotate(0)'', ''rotate3d(1, 1, 1, 0)'', ''rotateX(0)'', ''rotateY(0)'', ''rotateZ(0)'', ''skew(0, 0)'', ''skewX(0)'', ''skewY(0)'', ''matrix(1, 0, 0, 1, 0, 0)'' and ''matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)''. A special case is perspective: ''perspective(infinity)''. The value of m<sub>34</sub> becomes infinitesimal small and the transform function is therefore assumed to be equal to the identity matrix.
</dd>
<dt><dfn>3D rendering context</dfn></dt>
<dd>
A set of elements with a common ancestor which share a common three-dimensional coordinate system, as described <a href="#3d-rendering-contexts">below</a>.
</dd>
</dl>
<!--
/$$$$$$ /$$$$$$$ /$$$$$$ /$$
/$$__ $$| $$__ $$ /$$__ $$ | $$
|__/ \ $$| $$ \ $$ | $$ \__/ /$$ /$$| $$$$$$$
/$$$$$$/| $$ | $$ /$$$$$$| $$$$$$ | $$ | $$| $$__ $$
/$$____/ | $$ | $$|______/ \____ $$| $$ | $$| $$ \ $$
| $$ | $$ | $$ /$$ \ $$| $$ | $$| $$ | $$
| $$$$$$$$| $$$$$$$/ | $$$$$$/| $$$$$$/| $$$$$$$/
|________/|_______/ \______/ \______/ |_______/
-->
<h2 id="two-dimensional-subset">Two Dimensional Subset</h2>
UAs may not always be able to render three-dimensional transforms and then just support a two-dimensional subset of this specification. In this case <a href="#three-d-transform-functions">three-dimensional transforms</a> and the properties 'transform-style', 'perspective', 'perspective-origin' and 'backface-visibility' must not be supported. Section <a href="#3d-transform-rendering">3D Transform Rendering</a> does not apply. Matrix decomposing uses the technique taken from the "unmatrix" method in "Graphics Gems II, edited by Jim Arvo", simplified for the 2D case. Section <a href="#mathematical-description">Mathematical Description of Transform Functions</a> is still effective but can be reduced by using a 3x3 transformation matrix where <em>a</em> equals m<sub>11</sub>, <em>b</em> equals m<sub>12</sub>, <em>c</em> equals m<sub>21</sub>, <em>d</em> equals m<sub>22</sub>, <em>e</em> equals m<sub>41</sub> and <em>f</em> equals m<sub>42</sub> (see <a href="#MatrixDefined">A 2D 3x2 matrix with six parameter</a>).
<div class="figure">
<img src="images/3x3matrix.png" alt="3x3 matrix" title="\begin{bmatrix} a & c & e \\ b
& d & f \\ 0 & 0 & 1 \end{bmatrix}" width="82" height="79">
<p class="caption">
3x3 matrix for two-dimensional transformations.
</p>
</div>
<div class="example">
Authors can easily provide a fallback if UAs do not provide support for three-dimensional transforms. The following example has two property definitions for 'transform'. The first one consists of two two-dimensional transform functions. The second one has a two-dimensional and a three-dimensional transform function.
<pre>div {
transform: scale(2) rotate(45deg);
transform: scale(2) rotate3d(0, 0, 1, 45deg);
}</pre>
With 3D support, the second definition will override the first one. Without 3D support, the second definition is invalid and a UA falls back to the first definition.
</div>
<!--
/$$$$$$$ /$$
| $$__ $$ | $$
| $$ \ $$ /$$$$$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$
| $$$$$$$/ /$$__ $$| $$__ $$ /$$__ $$ /$$__ $$ /$$__ $$
| $$__ $$| $$$$$$$$| $$ \ $$| $$ | $$| $$$$$$$$| $$ \__/
| $$ \ $$| $$_____/| $$ | $$| $$ | $$| $$_____/| $$
| $$ | $$| $$$$$$$| $$ | $$| $$$$$$$| $$$$$$$| $$
|__/ |__/ \_______/|__/ |__/ \_______/ \_______/|__/
-->
<h2 id="transform-rendering">The Transform Rendering Model</h2>
<em>This section is normative.</em>
Specifying a value other than ''none'' for the 'transform' property establishes a new <i>local coordinate system</i> 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 <i>transformation matrix</i>. 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 <i>current transformation matrix (CTM)</i> 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. Three-dimensional transform functions extend this coordinate space into three dimensions, adding a Z axis perpendicular to the plane of the screen, that increases towards the viewer.
<div class="figure">
<img src="images/coordinates.svg" width="270" height="240" alt="Demonstration of the initial coordinate space">
<p class="caption">
Demonstration of the initial coordinate space.
</p>
</div>
<p id="transformation-matrix-computation">
The <i>transformation matrix</i> is computed from the 'transform' and 'transform-origin' properties as follows:
<ol>
<li>Start with the identity matrix.</li>
<li>Translate by the computed X, Y and Z values of 'transform-origin'</li>
<li>Multiply by each of the transform functions in 'transform' property from left to right</li>
<li>Translate by the negated computed X, Y and Z values of 'transform-origin'</li>
</ol>
</p>
Transforms apply to <i>transformable elements</i>.
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="http://www.w3.org/TR/cssom-view/#dom-element-getclientrects">getClientRects()</a> and <a href="http://www.w3.org/TR/cssom-view/#dom-element-getboundingclientrect">getBoundingClientRect()</a>, which are specified in [[CSSOM-VIEW]].
<div class="example">
<pre>
div {
transform: translate(100px, 100px);
}</pre>
<p>
This transform moves the element by 100 pixels in both the X and Y directions.
</p>
<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&deg; 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 transform moves the element by 80 pixels in both the X and Y directions, then scales the element by 150%, then rotates it 45&deg; clockwise about the Z axis. Note that the scale and rotation operate about the center of the element, since the element has the default transform-origin of ''50% 50%''.
<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>
&lt;div style="transform: translate(80px, 80px)"&gt;
&lt;div style="transform: scale(1.5, 1.5)"&gt;
&lt;div style="transform: rotate(45deg)"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</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 ''scroll'' or ''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 ''none'' for the transform results in the creation of both a stacking context and a containing block. The object acts as a containing block for fixed positioned descendants.
Issue: Is this effect on ''position: fixed'' necessary? If so, need to go into more detail here about why fixed positioned objects should do 1898 this, i.e., that it's much harder to implement otherwise. See <a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=16328">Bug 16328</a>.
<a href="http://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 ''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="http://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.
<h3 id="3d-transform-rendering">3D Transform Rendering</h3>
Normally, elements render as flat planes, and are rendered into the same plane as their containing block. Often this is the plane shared by the rest of the page. Two-dimensional transform functions can alter the appearance of an element, but that element is still rendered into the same plane as its containing block.
Three-dimensional transforms can result in transformation matrices with a non-zero Z component (where the Z axis projects out of the plane of the screen). This can result in an element rendering on a different plane than that of its containing block. This may affect the front-to-back rendering order of that element relative to other elements, as well as causing it to intersect with other elements.
<div class="example">
This example shows the effect of three-dimensional transform applied to an element.
<pre>
&lt;style&gt;
div {
height: 150px;
width: 150px;
}
.container {
border: 1px solid black;
}
.transformed {
transform: rotateY(50deg);
}
&lt;/style&gt;
&lt;div class="container"&gt;
&lt;div class="transformed"&gt;&lt;/div&gt;
&lt;/div&gt;</pre>
<div class="figure">
<img src="examples/simple-3d-example.png" width="210" height="190" alt="Div with a rotateY transform.">
</div>
The transform is a 50&deg; rotation about the vertical, Y axis. Note how this makes the blue box appear narrower, but not three-dimensional.
</div>
<h4 id="perspective">Perspective</h4>
The 'perspective' and 'perspective-origin' properties can be used to add a feeling of depth to a scene by making elements higher on the Z axis (closer to the viewer) appear larger, and those further away to appear smaller. The scaling is proportional to <var>d</var>/(<var>d</var> &minus; <var>Z</var>) where <var>d</var>, the value of 'perspective', is the distance from the drawing plane to the the assumed position of the viewer's eye.
<div class="figure">
<img alt="Diagram of scale vs. Z position" src="images/perspective_distance.png">
<p class="caption">
Diagrams showing how scaling depends on the 'perspective' property and Z position. In the top diagram, <var>Z</var> is half of <var>d</var>. In order to make it appear that the original circle (solid outline) appears at <var>Z</var> (dashed circle), the circle is scaled up by a factor of two, resulting in the light blue circle. In the bottom diagram, the circle is scaled down by a factor of one-third to make it appear behind the original position.
</p>
</div>
Normally the assumed position of the viewer's eye is centered on a drawing. This position can be moved if desired &ndash; for example, if a web page contains multiple drawings that should share a common perspective &ndash; by setting 'perspective-origin'.
<div class="figure">
<img alt="Diagram of different perspective-origin" src="images/perspective_origin.png">
<p class="caption">
Diagram showing the effect of moving the perspective origin upward.
</p>
</div>
<p id="perspective-matrix-computation">
The <i>perspective matrix</i> is computed as follows:
<ol>
<li>Start with the identity matrix.</li>
<li>Translate by the computed X and Y values of 'perspective-origin'</li>
<li>Multiply by the matrix that would be obtained from the ''perspective()'' transform function, where the length is provided by the value of the 'perspective' property</li>
<li>Translate by the negated computed X and Y values of 'perspective-origin'</li>
</ol>
</p>
<div class="example">
This example shows how perspective can be used to cause three-dimensional transforms to appear more realistic.
<pre>
&lt;style&gt;
div {
height: 150px;
width: 150px;
}
.container {
perspective: 500px;
border: 1px solid black;
}
.transformed {
transform: rotateY(50deg);
}
&lt;/style&gt;
&lt;div class="container"&gt;
&lt;div class="transformed"&gt;&lt;/div&gt;
&lt;/div&gt;</pre>
<div class="figure">
<img src="examples/simple-perspective-example.png" width="210" height="190" alt="Div with a rotateY transform, and perspective on its container">
</div>
The inner element has the same transform as in the previous example, but its rendering is now influenced by the perspective property on its parent element. Perspective causes vertices that have positive Z coordinates (closer to the viewer) to be scaled up in X and Y, and those further away (negative Z coordinates) to be scaled down, giving an appearance of depth.
</div>
<h4 id="3d-rendering-contexts">3D Rendering Contexts</h4>
This section specifies the rendering model for content that uses 3D-transforms and the ''transform-style'' property. In order to describe this model, we introduce the concept of a "3D rendering context".
A <i>3D rendering context</i> is a set of elements rooted in a common ancestor that, for the purposes of 3D-transform rendering, are considered to share a common three-dimensional coordinate system. The front-to-back rendering of elements in the a 3D rendering context depends on their z-position in that three-dimensional space, and, if the 3D transforms on those elements cause them to intersect, then they are rendered with intersection.
A 3D rendering context is established by an element which has a used value for transform-style of "flat". Descendant elements with a used value for transform-style of "auto" or "preserve-3d" share their enclosing 3D rendering context. A descendant with a used value for transform-style of "flat" participates in its containing 3D rendering context, but establishes a new 3D rendering context for its descendants. For the purposes of rendering in its containing 3D rendering context, it behaves like a flat plane.
Note: This is conceptually similar to CSS stacking contexts. A positioned element with explicit z-index establishes a stacking context, while participating in the stacking context of an ancestor. Similarly, an element can establish a 3D rendering context for its descendants, while participating in the 3D rendering context of an ancestor. Just as elements within a stacking context render in z-index order, elements in a 3D-rendering context render in z-depth order and can intersect.
Some CSS properties have values that are considered to force "grouping": they require that their element and its descendants are rendered as a group before being composited with other elements; these include opacity, filters and properties that affect clipping. The relevant property values are listed under <a href="#grouping-property-values">grouping property values</a>. These grouping property values force the used value for transform-style to be "flat", and such elements are referred to as <dfn>flattening elements</dfn>. Consequently, they always establish a new 3D rendering context. The root element always has a used value of "flat" for transform-style.
The rendering of elements in a 3D rendering context is as follows (numbers refer to items in <a href="http://www.w3.org/TR/CSS2/zindex.html#painting-order">CSS 2.1, Appendix E, Section E.2 Painting Order</a>):
<ol style="list-style-type: upper-alpha;">
<li>The background, borders and other box decorations of the establishing element are rendered (steps 1 and 2)</li>
<li>The content and descendant elements without 3D transforms, ordered according to steps 3—7, are rendered into a plane at z=0 relative to to the establishing element.</li>
<li>3D-transformed elements are each rendered into their own plane, transformed by the <a href="#accumulated-3d-transformation-matrix-computation">accumulated 3D transformation matrix</a>.</li>
<li>Intersection is performed between the set of planes generated by steps B and C, according to <a href="http://en.wikipedia.org/wiki/Newell%27s_algorithm">Newell's algorithm</a>.</li>
<li>The resulting set of planes is rendered on top of the backgrounds and box decorations rendered in this step A. Coplanar 3D transformed elements are rendered in painting order.</li>
</ol>
Issue: is it OK to not pop 2D-transformed elements into their own planes?
Issue: requiring intersection with non-transformed content and descendants requires UAs to allocate additional textures (possibly doubling memory use). Would be more efficient to simply render content and untransformed descendants along with background and borders.
Note that elements with transforms which have a negative z-component will render behind the content and untransformed descendants of the establishing element, and that 3D transformed elements may interpenetrate with content and untransformed elements.
Note: Because the 3D-transformed elements in a 3D rendering context can all depth-sort and intersect with each other, they are effectively rendered as if they were siblings. The effect of transform-style: preserve-3d can then be thought of as causing all the 3D transformed elements in a 3D rendering context to be hoisted up into the establishing element, but still rendered with their <a href="#accumulated-3d-transformation-matrix-computation">accumulated 3D transformation matrix</a>.
<div class="example">
<pre>
&lt;style&gt;
.container {
background-color: rgba(0, 0, 0, 0.3);
perspective: 500px;
}
.container > div {
position: absolute;
left: 0;
}
.container > :first-child {
transform: rotateY(45deg);
background-color: orange;
top: 10px;
height: 135px;
}
.container > :last-child {
transform: translateZ(40px);
background-color: rgba(0, 0, 255, 0.6);
top: 50px;
height: 100px;
}
&lt;/style&gt;
&lt;div class="container"&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;</pre>
This example shows show elements in a 3D rendering context can intersect. The container element establishes a 3D rendering context for itself and its two children. The children intersect with each other, and the orange element also intersects with the container.
<div class="figure">
<img src="examples/3d-intersection.png" width="210" height="198" alt="Intersecting sibling elements.">
</div>
</div>
The ''perspective'' property can be used to ensure that 3D transformed elements in the resulting 3D rendering context appear to live in a common three-dimensional space with depth, by suppling a common perspective matrix to descendant transformed members of its 3D rendering context, which is taken into account in the <a href="#accumulated-3d-transformation-matrix-computation">accumulated 3D matrix computation</a>.
By default, elements with value for ''perspective'' other than ''none'' are flattening, and thus establish a 3D rendering context. However, setting ''transform-style'' to ''preserve-3d'' allows the perspective element to extend its containing 3D rendering context (provided no other <a href="#grouping-property-values">grouping property values</a> are in effect).
<div class="example">
<pre>
&lt;style&gt;
div {
height: 150px;
width: 150px;
}
.container {
perspective: 500px;
border: 1px solid black;
}
.transformed {
transform: rotateY(50deg);
background-color: blue;
}
.child {
transform-origin: top left;
transform: rotateX(40deg);
background-color: lime;
}
&lt;/style&gt;
&lt;div class="container"&gt;
&lt;div class="transformed"&gt;
&lt;div class="child"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</pre>
This example shows how nested 3D transforms are rendered. The blue div is transformed as in the previous example, with its rendering influenced by the perspective on its parent element. The lime element also has a 3D transform, which is a rotation about the X axis (anchored at the top, by virtue of the transform-origin). However, the lime element is being rendered into the plane of its parent because it is not a member of the same 3D rendering context; the parent is "flattening". Thus the lime element only appears shorter; it does not "pop out" of the blue element.
<div class="figure">
<img src="examples/3d-rendering-context-flat.png" width="240" height="200" alt="Nested 3D transforms, with flattening">
</div>
</div>
<h4 id="transformed-element-hierarchies">Transformed element hierarchies</h4>
By default, <i>transformed elements</i> are flattening, and thus establish a <i>3D rendering context</i>. However, since it is useful to construct hierarchies of transformed objects that share a common 3-dimensional space, this flattening behavior may be overridden by specifying a value of ''preserve-3d'' for the ''transform-style'' property, provided no other <a href="#grouping-property-values">grouping property values</a> are in effect. This allows descendants of the transformed element to share the same 3D rendering context. Non-3D-transformed descendants of such elements are rendered into the plane of the element in step C above, but 3D-transformed elements in the same 3D rendering context will "pop out" into their own planes.
<div class="example">
<pre>
&lt;style&gt;
div {
height: 150px;
width: 150px;
}
.container {
perspective: 500px;
border: 1px solid black;
}
.transformed {
<b>transform-style: preserve-3d</b>;
transform: rotateY(50deg);
background-color: blue;
}
.child {
transform-origin: top left;
transform: rotateX(40deg);
background-color: lime;
}
&lt;/style&gt;</pre>
This example is identical to the previous example, with the addition of ''transform-style: preserve-3d'' on the blue element. The blue element now extends the 3D rendering context of its container. Now both blue and lime elements share a common three-dimensional space, so the lime element renders as tilting out from its parent, influenced by the perspective on the container.
<div class="figure">
<img src="examples/3d-rendering-context-3d.png" width="240" height="200" alt="Nested 3D transforms, with preserve-3d.">
</div>
</div>
<h4 id="accumulated-3d-transformation-matrix-computation">Accumulated 3D Transformation Matrix Computation</h4>
The final value of the transform used to render an element in a <i>3D rendering context</i> is computed by accumulating an <i>accumulated 3D transformation matrix</i> as follows:
1. Let <var>transform</var> be the identity matrix.
1. Let <var>current element</var> be the transformed element.
1. Let <var>ancestor block</var> be the element that establishes the transformed element's containing block.
1. While <var>current element</var> is not the element that establishes the transformed element's <i>3D rendering context</i>:
1. If <var>current element</var> has a value for 'transform' which is not ''none'', pre-multiply <var>current element</var>'s <i>transformation matrix</i> with the <var>transform</var>.
1. Compute a translation matrix which represents the offset of <var>current element</var> from its <var>ancestor block</var>, and pre-multiply that matrix into the <var>transform</var>.
1. If <var>ancestor block</var> has a value for 'perspective' 67F6 ; which is not ''none'', pre-multiply the <var>ancestor block</var>'s <i>perspective matrix</i> into the <var>transform</var>.
1. Let <var>ancestor block</var> be the element that establishes the <var>current element</var>'s containing block.
1. Let <var>current element</var> be the <var>ancestor block</var>.
Note: as described here, the <i>accumulated 3D transformation matrix</i> takes into account offsets generated by the <a href="http://www.w3.org/TR/REC-CSS2/visuren.html">visual formatting model</a> on the transformed element, and elements in the ancestor chain between the transformed element and the element that establishes the its <i>3D rendering context</i>.
<h4 id="backface-visibility">Backface Visibility</h4>
Using three-dimensional transforms, it's possible to transform an element such that its reverse side is visible. 3D-transformed elements show the same content on both sides, so the reverse side looks like a mirror-image of the front side (as if the element were projected onto a sheet of glass). Normally, elements whose reverse side is towards the viewer remain visible. However, the 'backface-visibility' property allows the author to make an element invisible when its reverse side is towards the viewer. This behavior is "live"; if an element with ''backface-visibility: hidden'' were animating, such that its front and reverse sides were alternately visible, then it would only be visible when the front side were towards the viewer.
Visibility of the reverse side of an element is considered using the <i>accumulated 3D transformation matrix</i>, and is thus relative to the enclosing flattening element.
Note: This property is useful when you place two elements back-to-back, as you would to create a playing card. Without this property, the front and back elements could switch places at times during an animation to flip the card. Another example is creating a box out of 6 elements, but where you want to see only the inside faces of the box.
<div class="example">
This example shows how to make a "card" element that flips over when clicked. Note the "transform-style: preserve-3d" on #card which is necessary to avoid flattening when flipped.
<pre>&lt;style&gt;
.body { perspective: 500px; }
#card {
position: relative;
height: 300px; width: 200px;
transition: transform 1s;
transform-style: preserve-3d;
}
#card.flipped {
transform: rotateY(180deg);
}
.face {
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
background-color: silver;
border-radius: 40px;
backface-visibility: hidden;
}
.back {
transform: rotateY(180deg);
}
&lt;/style&gt;
&lt;div id="card" onclick="this.classList.toggle('flipped')"&gt;
&lt;div class="front face"&gt;Front&lt;/div&gt;
&lt;div class="back face"&gt;Back&lt;/div&gt;
&lt;/div&gt;
</pre>
</div>
Issue: what is the impact of backface-visibility on non-transformed or 2D-transformed elements? Do they get popped into their own planes and intersect?
<h3 id="processing-of-perspective-transformed-boxes">
Processing of Perspective-Transformed Boxes
</h3>
Issue: This is a first pass at an attempt to precisely specify how exactly to transform elements using the provided matrices. It might not be ideal, and implementer feedback is encouraged. See <a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=15605">bug 15605</a>.
The <i>accumulated 3D transformation matrix</i> is affected both by the ''perspective'' property, and by any perspective() transform function present in the value of the ''transform'' property.
This <i>accumulated 3D transformation matrix</i> is a 4&times;4 matrix, while the objects to be transformed are two-dimensional boxes. To transform each corner (<var>a</var>, <var>b</var>) of a box, the matrix must first be applied to (<var>a</var>, <var>b</var>, 0, 1), which will result in a four-dimensional point (<var>x</var>, <var>y</var>, <var>z</var>, <var>w</var>). This is transformed back to a three-dimensional point (<var>x</var>&prime;, <var>y</var>&prime;, <var>z</var>&prime;) as follows:
If <var>w</var> &gt; 0, (<var>x</var>&prime;, <var>y</var>&prime;, <var>z</var>&prime;) = (<var>x</var>/<var>w</var>, <var>y</var>/<var>w</var>, <var>z</var>/<var>w</var>).
If <var>w</var> = 0, (<var>x</var>&prime;, <var>y</var>&prime;, <var>z</var>&prime;) = (<var>x</var> &sdot; <var>n</var>, <var>y</var> &sdot; <var>n</var>, <var>z</var> &sdot; <var>n</var>). <var>n</var> is an implementation-dependent value that should be chosen so that <var>x</var>&prime; or <var>y</var>&prime; is much larger than the viewport size, if possible. For example, (5px, 22px, 0px, 0) might become (5000px, 22000px, 0px), with <var>n</var> = 1000, but this value of <var>n</var> would be too small for (0.1px, 0.05px, 0px, 0). This specification does not define the value of <var>n</var> exactly. Conceptually, (<var>x</var>&prime;, <var>y</var>&prime;, <var>z</var>&prime;) is <a href="http://en.wikipedia.org/wiki/Plane_at_infinity">infinitely far</a> in the direction (<var>x</var>, <var>y</var>, <var>z</var>).
If <var>w</var> &lt; 0 for all four corners of the transformed box, the box is not rendered.
If <var>w</var> &lt; 0 for one to three corners of the transformed box, the box must be replaced by a polygon that has any parts with <var>w</var> &lt; 0 cut out. This will in general be a polygon with three to five vertices, of which exactly two will have <var>w</var> = 0 and the rest <var>w</var> &gt; 0. These vertices are then transformed to three-dimensional points using the rules just stated. Conceptually, a point with <var>w</var> &lt; 0 is "behind" the viewer, so should not be visible.
<div class="example">
<pre>&lt;style&gt;
.transformed {
height: 100px;
width: 100px;
background: lime;
transform: perspective(50px) translateZ(100px);
}
&lt;/style&gt;</pre>
All of the box's corners have <var>z</var>-coordinates greater than the perspective. This means that the box is behind the viewer and will not display. Mathematically, the point (<var>x</var>, <var>y</var>) first becomes (<var>x</var>, <var>y</var>, 0, 1), then is translated to (<var>x</var>, <var>y</var>, 100, 1), and then applying the perspective results in (<var>x</var>, <var>y</var>, 100, &minus;1). The <var>w</var>-coordinate is negative, so it does not display. An implementation that doesn't handle the <var>w</var> &lt; 0 case separately might incorrectly display this point as (&minus;<var>x</var>, &minus;<var>y</var>, &minus;100), dividing by &minus;1 and mirroring the box.
</div>
<div class="example">
<pre>&lt;style&gt;
.transformed {
height: 100px;
width: 100px;
background: radial-gradient(yellow, blue);
transform: perspective(50px) translateZ(50px);
}
&lt;/style&gt;</pre>
Here, the box is translated upward so that it sits at the same place the viewer is looking from. This is like bringing the box closer and closer to one's eye until it fills the entire field of vision. Since the default transform-origin is at the center of the box, which is yellow, the screen will be filled with yellow.
Mathematically, the point (<var>x</var>, <var>y</var>) first becomes (<var>x</var>, <var>y</var>, 0, 1), then is translated to (<var>x</var>, <var>y</var>, 50, 1), then becomes (<var>x</var>, <var>y</var>, 50, 0) after applying perspective. Relative to the transform-origin at the center, the upper-left corner was (&minus;50, &minus;50), so it becomes (&minus;50,
&minus;50, 50, 0). This is transformed to something very far to the upper left, such as (&minus;5000, &minus;5000, 5000). Likewise the other corners are sent very far away. The radial gradient is stretched over the whole box, now enormous, so the part that's visible without scrolling should be the color of the middle pixel: yellow. However, since the box is not actually infinite, the user can still scroll to the edges to see the blue parts.
</div>
<div class="example">
<pre>&lt;style&gt;
.transformed {
height: 50px;
width: 50px;
background: lime;
border: 25px solid blue;
transform-origin: left;
transform: perspective(50px) rotateY(-45deg);
}
&lt;/style&gt;</pre>
The box will be rotated toward the viewer, with the left edge staying fixed while the right edge swings closer. The right edge will be at about <var>z</var> = ''70.7px'', which is closer than the perspective of ''50px''. Therefore, the rightmost edge will vanish ("behind" the viewer), and the visible part will stretch out infinitely far to the right.
Mathematically, the top right vertex of the box was originally (100, &minus;50), relative to the transform-origin. It is first expanded to (100, &minus;50, 0, 1). After applying the transform specified, this will get mapped to about (70.71, &minus;50, 70.71, &minus;0.4142). This has <var>w</var> = &minus;0.4142 &lt; 0, so we need to slice away the part of the box with <var>w</var> &lt; 0. This results in the new top-right vertex being (50, &minus;50, 50, 0). This is then mapped to some faraway point in the same direction, such as (5000, &minus;5000, 5000), which is up and to the right from the transform-origin. Something similar is done to the lower right corner, which gets mapped far down and to the right. The resulting box stretches far past the edge of the screen.
Again, the rendered box is still finite, so the user can scroll to see the whole thing if he or she chooses. However, the right part has been chopped off. No matter how far the user scrolls, the rightmost ''30px'' or so of the original box will not be visible. The blue border was only ''25px'' wide, so it will be visible on the left, top, and bottom, but not the right.
The same basic procedure would apply if one or three vertices had <var>w</var> &lt; 0. However, in that case the result of truncating the <var>w</var> &lt; 0 part would be a triangle or pentagon instead of a quadrilateral.
</div>
<!--
/$$ /$$$$$$
| $$ /$$__ $$
/$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$$| $$ \__//$$$$$$ /$$$$$$
|_ $$_/ /$$__ $$|____ $$| $$__ $$ /$$_____/| $$$$ /$$__ $$ /$$__ $$
| $$ | $$ \__/ /$$$$$$$| $$ \ $$| $$$$$$ | $$_/ | $$ \ $$| $$ \__/
| $$ /$$| $$ /$$__ $$| $$ | $$ \____ $$| $$ | $$ | $$| $$
| $$$$/| $$ | $$$$$$$| $$ | $$ /$$$$$$$/| $$ | $$$$$$/| $$
\___/ |__/ \_______/|__/ |__/|_______/ |__/ \______/ |__/
/$$$$$$/$$$$
| $$_ $$_ $$
| $$ \ $$ \ $$
| $$ | $$ | $$
| $$ | $$ | $$
|__/ |__/ |__/
-->
<h2 id="transform-property">The 'transform' Property</h2>
A transformation is applied to the coordinate system an element renders in 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: <i>transformable elements</i>
Inherited: no
Percentages: refer to the size of <i>reference box</i>
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 ''none'' for the transform results in the creation of both a stacking context and a containing block. The object acts as a containing block for fixed positioned descendants.
<pre class=prod><dfn>&lt;transform-list></dfn> = <<transform-function>>+</pre>
<h3 id="serialization-of-transform-functions">Serialization of <<transform-function>>s</h3>
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.
<h3 id="serialization-of-the-computed-value">Serialization of the <i>computed value</i> of <<transform-list>></h3>
A <<transform-list>> for the <i>computed value</i> is serialized to either one <<matrix()>> or one <<matrix3d()>> function by the following algorithm:
<ol class="algorithm">
<li>Let <var>transform</var> be a 4x4 matrix initialized to the identity matrix. The elements <var>m11</var>, <var>m22</var>, <var>m33</var> and <var>m44</var> of <var>transform</var> must be set to ''1'' all other elements of <var>transform</var> must be set to ''0''.
<li>Post-multiply all <<transform-function>>s in <<transform-list>> to <var>transform</var>.</li>
<li>Chose between <<matrix()>> or <<matrix3d()>> serialization:
<dl class="switch">
<dt>If <var>transform</var> is a <i>2D matrix</i></dt>
<dd>Serialize <var>transform</var> to a <<matrix()>> function.</dd>
<dt>Otherwise</dt>
<dd>Serialize <var>transform</var> to a <<matrix3d()>> function.</dd>
</dl>
</li>
</ol>
<!--
/$$ /$$$$$$
| $$ /$$__ $$
/$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$$| $$ \__//$$$$$$ /$$$$$$
|_ $$_/ /$$__ $$|____ $$| $$__ $$ /$$_____/| $$$$ /$$__ $$ /$$__ $$
| $$ | $$ \__/ /$$$$$$$| $$ \ $$| $$$$$$ | $$_/ | $$ \ $$| $$ \__/
| $$ /$$| $$ /$$__ $$| $$ | $$ \____ $$| $$ | $$ | $$| $$
| $$$ 2334 $/| $$ | $$$$$$$| $$ | $$ /$$$$$$$/| $$ | $$$$$$/| $$
\___/ |__/ \_______/|__/ |__/|_______/ |__/ \______/ |__/
/$$ /$$
|__/ |__/
/$$$$$$/$$$$ /$$$$$$ /$$$$$$ /$$ /$$$$$$ /$$ /$$$$$$$
| $$_ $$_ $$ /$$$$$$ /$$__ $$ /$$__ $$| $$ /$$__ $$| $$| $$__ $$
| $$ \ $$ \ $$|______/| $$ \ $$| $$ \__/| $$| $$ \ $$| $$| $$ \ $$
| $$ | $$ | $$ | $$ | $$| $$ | $$| $$ | $$| $$| $$ | $$
| $$ | $$ | $$ | $$$$$$/| $$ | $$| $$$$$$$| $$| $$ | $$
|__/ |__/ |__/ \______/ |__/ |__/ \____ $$|__/|__/ |__/
/$$ \ $$
| $$$$$$/
\______/
-->
<h2 id="transform-origin-property">The 'transform-origin' Property</h2>
<pre class='propdef'>
Name: transform-origin
Value: &nbsp;&nbsp;[ left | center | right | top | bottom | <<percentage>> | <<length>> ]<br> | <br>&nbsp;&nbsp;[ left | center | right | <<percentage>> | <<length>> ]<br>&nbsp;&nbsp;[ top | center | bottom | <<percentage>> | <<length>> ] <<length>>?<br> |<br>&nbsp;&nbsp;[[ center | left | right ] && [ center | top | bottom ]] <<length>>?
Initial: 50% 50%
Applies to: <i>transformable elements</i>
Inherited: no
Percentages: refer to the size of <i>reference box</i>
Computed value: For <<length>> the absolute value, otherwise a percentage
Media: visual
Animatable: as <a href="http://dev.w3.org/csswg/css3-transitions/#animtype-simple-list">simple list</a> of <a href="http://dev.w3.org/csswg/css3-transitions/#animtype-lpcalc">length, percentage, or calc</a>
</pre>
The initial <i>used value</i> for SVG elements without associated CSS layout box is ''0 0''.
The values of the 'transform' and 'transform-origin' properties are used to compute the <i>transformation matrix</i>, 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">
<dt><<percentage>></dt>
<dd>
A percentage for the horizontal offset is relative to the width of the <i>reference box</i>. A percentage for the vertical offset is relative to the height of the <i>reference box</i>. The value for the horizontal and vertical offset represent an offset from the top left corner of the <i>reference box</i>.
</dd>
<dt><<length>></dt>
<dd>
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 <i>reference box</i>.
</dd>
<dt><dfn>top</dfn>
<dd>Computes to ''0%'' for the vertical position.
<dt><dfn>right</dfn>
<dd>Computes to ''100%'' for the horizontal position.
<dt><dfn>bottom</dfn>
<dd>Computes to ''100%'' for the vertical position.
<dt><dfn>left</dfn>
<dd>Computes to ''0%'' for the horizontal position.
<dt><dfn>center</dfn>
<dd>
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>
The <a href="http://www.w3.org/TR/cssom/#resolved-value">resolved value</a> of 'transform-origin' is the <a href="http://www.w3.org/TR/CSS21/cascade.html#used-value">used value</a> (i.e., percentages are resolved to absolute lengths).
<h2 id="transform-box">Transform reference box: the 'transform-box' property</h2>
<pre class='propdef'>
Name: transform-box
Value: border-box | fill-box | view-box
Initial: border-box
Applies to: <i>transformable elements</i>
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 dimension of one of the following <dfn>reference box</dfn>es:
<dl dfn-for=transform-box>
<dt><dfn dfn-type=value>border-box</dfn></dt>
<dd>
Uses the border box as reference box. The reference box of a table is the border box of its <a href="http://www.w3.org/TR/CSS21/tables.html#model">table wrapper box</a>, not its table box.
</dd>
<dt><dfn dfn-type=value>fill-box</dfn></dt>
<dd>
Uses the <a>object bounding box</a> as reference box.
</dd>
<dt><dfn dfn-type=value>view-box</dfn></dt>
<dd>
<p>Uses the nearest <a href="http://www.w3.org/TR/SVG11/intro.html#TermSVGViewport">SVG viewport</a> as reference box.</p>
<p>If a <a>'viewBox'</a> attribute is specified for the <a href="http://www.w3.org/TR/SVG11/intro.html#TermSVGViewport">SVG viewport</a> creating element:
<ul>
<li>The reference box is positioned at the origin of the coordinate system established by the <a>'viewBox'</a> attribute.</li>
<li>The dimension of the reference box is set to the <em>width</em> and <em>height</em> values of the <a>'viewBox'</a> attribute.</li>
</ul>
</p>
</dd>
</dl>
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 <i>used value</i> 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 <i>used value</i> 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>.
<!--
/$$ /$$$$$$
| $$ /$$__ $$
/$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$$| $$ \__//$$$$$$ /$$$$$$
|_ $$_/ /$$__ $$|____ $$| $$__ $$ /$$_____/| $$$$ /$$__ $$ /$$__ $$
| $$ | $$ \__/ /$$$$$$$| $$ \ $$| $$$$$$ | $$_/ | $$ \ $$| $$ \__/
| $$ /$$| $$ /$$__ $$| $$ | $$ \____ $$| $$ | $$ | $$| $$
| $$$$/| $$ | $$$$$$$| $$ | $$ /$$$$$$$/| $$ | $$$$$$/| $$
\___/ |__/ \_______/|__/ |__/|_______/ |__/ \______/ |__/
/$$ /$$
| $$ | $$
/$$$$$$/$$$$ /$$$$$$$ /$$$$$$ /$$ /$$| $$ /$$$$$$
| $$_ $$_ $$ /$$$$$$ /$$_____/|_ $$_/ | $$ | $$| $$ /$$__ $$
| $$ \ $$ \ $$|______/| $$$$$$ | $$ | $$ | $$| $$| $$$$$$$$
| $$ | $$ | $$ \____ $$ | $$ /$$| $$ | $$| $$| $$_____/
| $$ | $$ | $$ /$$$$$$$/ | $$$$/| $$$$$$$| $$| $$$$$$$
|__/ |__/ |__/ |_______/ \___/ \____ $$|__/ \_______/
/$$ | $$
| $$$$$$/
\______/
-->
<h2 id="transform-style-property">The 'transform-style' Property</h2>
<pre class='propdef'>
Name: transform-style
Value: auto | flat | preserve-3d
Initial: auto
Applies to: <i>transformable elements</i>
Inherited: no
Percentages: N/A
Computed value: Same as specified value.
Media: visual
Animatable: no
</pre>
A value of "flat" for 'transform-style' establishes a stacking context, and establishes a <i>3D rendering context</i>. Elements with a used value of "auto" are ignored for the purposes of 3D rendering context computation, and those with a used value of "preserve-3d" extend the 3D rendering context to which they belong, even if values for the ''transform'' or ''perspective'' properties would otherwise cause flattening. A value of "preserve-3d" establishes a stacking context, and a containing block.
<h3 id="grouping-property-values">Grouping property values</h3>
The following CSS property values require the user agent to create a flattened representation of the descendant elements before they can be applied, and therefore force the used value of ''transform-style'' to ''flat'':
* 'overflow': any value other than ''visible''.
* 'opacity': any value less than 1.
* 'filter': any value other than ''none''.
* 'clip': any value other than ''auto''.
* 'clip-path': any value other than ''none''.
* 'isolation': used value of ''isolate''.
* 'mask-image': any value other than ''none''.
* 'mask-border-source': any value other than ''none''.
* 'mix-blend-mode': any value other than ''normal''.
The following CSS property values cause an ''auto'' value of ''transform-style'' to become ''flat'':
* 'transform': any value other than ''none''.
* 'perspective': any value other than ''none''.
In both cases the computed value of 'transform-style' is not affected.
Issue: Having overflow imply transform-style: flat causes every element with non-visible overflow to become
a stacking context, which is unwanted. See <a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=28252">Bug 28252</a>.
<!--
/$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$
/$$__ $$ /$$__ $$ /$$__ $$ /$$_____/ /$$__ $$ /$$__ $$ /$$_____/
| $$ \ $$| $$$$$$$$| $$ \__/| $$$$$$ | $$ \ $$| $$$$$$$$| $$
| $$ | $$| $$_____/| $$ \____ $$| $$ | $$| $$_____/| $$
| $$$$$$$/| $$$$$$$| $$ /$$$$$$$/| $$$$$$$/| $$$$$$$| $$$$$$$
| $$____/ \_______/|__/ |_______/ | $$____/ \_______/ \_______/
| $$ | $$
| $$ | $$
|__/ |__/
/$$ /$$
| $$ |__/
/$$$$$$ /$$ /$$ /$$ /$$$$$$
|_ $$_/ | $$| $$ /$$//$$__ $$
| $$ | $$ \ $$/$$/| $$$$$$$$
| $$ /$$| $$ \ $$$/ | $$_____/
| $$$$/| $$ \ $/ | $$$$$$$
\___/ |__/ \_/ \_______/
-->
<h2 id="perspective-property">The 'perspective' Property</h2>
<pre class='propdef'>
Name: perspective
Value: none | <<length>>
Initial: none
Applies to: <i>transformable elements</i>
Inherited: no
Percentages: N/A
Computed value: Absolute length or "none".
Media: visual
Animatable: as <a href="http://dev.w3.org/csswg/css3-transitions/#animtype-length">length</a>
</pre>
Where <<length>> values must be positive.
<dl dfn-for="perspective">
<dt><<length>></dt>
<dd>
<p>Distance to the center of projection.
Issue: Verify that projection is the distance to the center of projection.
</dd>
<dt><dfn>none</dfn></dt>
<dd>
No perspective transform is applied. The effect is mathematically similar to an infinite <<length>> value. All objects appear to be flat on the canvas.
</dd>
</dl>
The use of this property with any value other than ''none'' establishes a stacking context. It also establishes a containing block (somewhat similar to ''position: relative''), just like the 'transform' property does.
The values of the 'perspective' and 'perspective-origin' properties are used to compute the <i>perspective matrix</i>, as described above.
<!--
/$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$
/$$__ $$ /$$__ $$ /$$__ $$ /$$_____/ /$$__ $$ /$$__ $$ /$$_____/
| $$ \ $$| $$$$$$$$| $$ \__/| $$$$$$ | $$ \ $$| $$$$$$$$| $$
| $$ | $$| $$_____/| $$ \____ $$| $$ | $$| $$_____/| $$
| $$$$$$$/| $$$$$$$| $$ /$$$$$$$/| $$$$$$$/| $$$$$$$| $$$$$$$
| $$____/ \_______/|__/ |_______/ | $$____/ \_______/ \_______/
| $$ | $$
| $$ | $$
|__/ |__/
/$$ /$$ /$$
| $$ |__/ |__/
/$$$$$$ /$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$$$$$
|_ $$_/ | $$| $$ /$$//$$__ $$ /$$$$$$ /$$__ $$ /$$__ $$| $$ /$$__ $$