The CSS visual formatting model describes a coordinate system within which each element is positioned. Positions and sizes in this coordinate space can be thought of as being expressed in pixels, starting in the upper left corner of the parent 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. A perspective transform can also be applied to give a sense of depth to the way elements are displayed. In two dimensions, the coordinate space behaves as described in the coordinate system transformations section of the SVG 1.1 specification. This is a coordinate system with two axes: the X axis increases horizontally to the right; the Y axis increases vertically downwards. In three dimensions, a Z axis is added, with positive z values conceptually rising perpendicularly out of the window toward the user and negative z values falling into the window away from the user.
Specifying a value other than 'none' for the 'transform' property establishes a new local coordinate system at the element that it is applied to. Transformations are cumulative. That is, elements establish their local coordinate system within the coordinate system of their parent. In this way, a 'transform' property effectively accumulates all the 'transform' properties of its ancestors. The accumulation of these transforms defines a current transformation matrix (CTM) for the element.
The transform property does not affect the flow of the content surrounding the transformed element. However, the value of the overflow area takes into account transformed elements. This behavior is similar to what happens when elements are translated 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.
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 though position: relative has been specified, but also acts as a containing block for fixed positioned descendants. The z position of a transformed element does not affect the order within a stacking context. With elements at the same z-index, objects are drawn in order of increasing z position.
Note that while 'transform' uses 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.
A 2D or 3D transformation is applied to an element through the 'transform' property. This property contains a list of transform functions. The final transformation value for an element is obtained by performing a matrix concatenation of each entry in the list. The set of transform functions is similar to those allowed by SVG. There are additional functions to support 3D transformations.
| Name: | transform |
| Value: | none | <transform-function> [ <transform-function> ]* |
| Initial: | none |
| Applies to: | block-level and inline-level elements |
| Inherited: | no |
| Percentages: | refer to the size of the element's box |
| Media: | visual |
| Computed value: | Same as specified value. |
The 'transform-origin' property establishes the origin of transformation for an element. This property is applied by first translating the element by the negated value of the property, then applying the element's transform, then translating by the property value. This effectively moves the desired transformation origin of the element to (0,0,0) in the local coordinate system, then applies the element's transform, then moves the element back to its original position.
| Name: | transform-origin |
| Value: |
[ [ <percentage> | <length>]{1,2} | [ <percentage> | <length>]{2} <length> | [top | center | bottom] || [left | center | right] ] ]
The z component can only be a length. Check BNF
|
| Initial: | 50% 50% 0 |
| Applies to: | block-level and inline-level elements |
| Inherited: | no |
| Percentages: | refer to the size of the element's box |
| Media: | visual |
| Computed value: | Same as specified value. |
The 'transform-style' property defines how nested elements are rendered in 3D space. If the 'transform-style' is 'flat', all children of this element are rendered flattened into the 2D plane of the element. Therefore, rotating the element about the X or Y axes will cause children positioned at positive or negative Z positions to appear on the element's plane, rather than in front of or behind it. If the 'transform-style' is 'preserve-3d', this flattening is not performed, so children maintain their position in 3D space.
This flattening takes place at each element, so preserving a hierarchy of elements in 3D space requires that each ancestor in the hierarchy have the value 'preserve-3d' for 'transform-style'. But since 'transform-style' affects only an element's children, the leaf nodes in a hierarchy do not require the perspective style.
| Name: | transform-style |
| Value: | flat | preserve-3d |
| Initial: | flat |
| Applies to: | block-level and inline-level elements |
| Inherited: | no |
| Percentages: | N/A |
| Media: | visual |
| Computed value: | Same as specified value. |
For some effects, the author will have to ensure that an ancestor element to a subtree using 'preserve-3d' has a 'transform-style' of 'flat' (or the default). Otherwise, the elements in the 3D tree may be located behind ancestor elements and, thus, invisible (hidden behind an ancestor's background).
Note that while 'preserve-3d' can be specified on an element, the effect may not be possible. Elements that have 'overflow' set to 'hidden' are unable to keep their children in 3D. In this case the element will behave as if the property was set to 'flat'.
The 'perspective' property applies the same transform as the perspective(<number>) transform function, except that it applies only to the positioned or transformed children of the element, not to the transform on the element itself.
If the value is 'none' no perspective transform is applied.
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.
| Name: | perspective |
| Value: | none | <number> |
| Initial: | none |
| Applies to: | block-level and inline-level elements |
| Inherited: | no |
| Percentages: | N/A |
| Media: | visual |
| Computed value: | Same as specified value. |
The 'perspective-origin' property establishes the origin for the perspective property. It effectively sets the X and Y position at which the viewer appears to be looking at the children of the element.
| Name: | perspective-origin |
| Value: | [ [ <percentage> | <length>]{1,2} | [top | center | bottom] | [left | center | right] ] | inherit |
| Initial: | 50% 50% |
| Applies to: | block-level and inline-level elements |
| Inherited: | no |
| Percentages: | refer to the size of the box itself |
| Media: | visual |
| Computed value: | Same as specified value. |
The 'backface-visibility' property determines whether or not the "back" side of a transformed element is visible when facing the viewer. With an identity transform, the front side of an element faces the viewer. Applying a rotation about Y of 180 degrees (for instance) would cause the back side of the element to face the viewer.
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 the inside faces of the box. This is useful when creating the backdrop for a 3 dimensional stage.
| Name: | backface-visibility |
| Value: | visible | hidden |
| Initial: | visible |
| Applies to: | block-level and inline-level elements |
| Inherited: | no |
| Percentages: | N/A |
| Media: | visual |
| Computed value: | Same as specified value. |
The value of the transform property is a list of <transform-functions>, applied in the order provided. The individual transform functions are separated by whitespace. The following is a list of allowed transform functions. In this list the type <translation-value> is defined as a <length> or <percentage> value, and the <angle> type is defined as a <number> followed by a required angle unit identifier. Angle unit identifiers are:
The <translation-value> values are defined as [<percentage> | <length>]. All other value types are described as CSS types. If a list of transforms is provided, then the net effect is as if each transform had been specified separately in the order provided. For example,
<div style="transform:translate(-10px,-20px) scale(2) rotate(45deg) translate(5px,10px)"/>
is functionally equivalent to:
<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>
div {
transform: translate(100px, 100px);
}
Move the element by 100 pixels in both the X and Y directions.
div {
height: 100px; width: 100px;
transform: translate(80px, 80px) scale(1.5, 1.5) rotate(45deg);
}
Move the element by 80 pixels in both the X and Y directions, then scale the element by 150%, then rotate it 45 degrees clockwise about the Z axis. Note that the scale and rotate operate about the center of the element, since the element has the default transform-origin of 50% 50%.
This section describes the interfaces and functionality added to the DOM to support runtime access to the functionality described above.
The Point interface represents a point in two-dimensional space.
interface Point {
attribute float x;
attribute float y;
};
x of type float
y of type float
The following 2 functions are added to the Window interface. They provide conversions between the page and node coordinate spaces.
interface Window {
...
Point convertPointFromPageToNode(in Node node, in Point point);
Point convertPointFromNodeToPage(in Node node, in Point point);
...
};
convertPointFromPageToNode
convertPointFromPageToNode method returns a point in the coordinate space of the
passed Node that is at the same location in the page as the passed point, which is in the coordinate
space of the page.
node of type Node
point of type Point
Point
convertPointFromNodeToPage
convertPointFromNodeToPage method returns a point in the coordinate space
of the page that is at the same location in the page as the passed point, which is in
the coordinate space of the passed Node.
node of type Node
point of type Point
Point
The CSSMatrix interface represents a 4x4 homogeneous matrix.
interface CSSMatrix {
attribute float m11;
attribute float m12;
attribute float m13;
attribute float m14;
attribute float m21;
attribute float m22;
attribute float m23;
attribute float m24;
attribute float m31;
attribute float m32;
attribute float m33;
attribute float m34;
attribute float m41;
attribute float m42;
attribute float m43;
attribute float m44;
void setMatrixValue(in DOMString string);
CSSMatrix multiply(in CSSMatrix secondMatrix);
CSSMatrix inverse();
CSSMatrix translate(in float x, in float y, in float z);
CSSMatrix scale(in float scaleX, in float scaleY, in float scaleZ);
CSSMatrix rotate(in float rotX, in float rotY, in float rotZ);
CSSMatrix rotateAxisAngle(in float x, in float y, in float z, in float angle);
};
m11-m44 of type float
setMatrixValue
setMatrixValue method replaces the existing matrix with one computed from parsing the passed string
as though it had been assigned to the transform property in a CSS style rule.
string of type DOMString
multiply
multiply method returns a new CSSMatrix which is the result of this matrix multiplied by the passed matrix, with the passed matrix to the right. This matrix is not modified.
secondMatrix of type CSSMatrix
CSSMatrix
inverse
inverse method returns a new matrix which is the inverse of this matrix. This matrix is not modified.
CSSMatrix
translate
translate method returns a new matrix which is this matrix post multiplied by a translation matrix containing the passed values. If the z component is undefined, a 0 value is used in its place. This matrix is not modified.
x of type float
y of type float
z of type float
CSSMatrix
scale
scale method returns a new matrix which is this matrix post multiplied by a scale matrix containing the passed values. If the z component is undefined, a 1 value is used in its place. If the y component is undefined, the x component value is used in its place. This matrix is not modified.
scaleX of type float
scaleY of type float
scaleZ of type float
CSSMatrix
rotate
rotate method returns a new matrix which is this matrix post multiplied by each of 3 rotation matrices about the major axes, first X, then Y, then Z. If the y and z components are undefined, the x value is used to rotate the object about the z axis, as though the vector (0,0,x) were passed. All rotation values are in degrees. This matrix is not modified.
rotX of type float
rotY of type float
rotZ of type float
CSSMatrix
rotateAxisAngle
rotateAxisAngle method returns a new matrix which is this matrix post multiplied by a rotation matrix with the given axis and angle. The right-hand rule is used to determine the direction of rotation. All rotation values are in degrees. This matrix is not modified.
x of type float
y of type float
z of type float
angle of type float
CSSMatrix
The CSSTransformValue interface represents one transform function in the transform property. The
operationType defines which operation is represented. The object also contains a list of values,
which are the parameters of the function, in the same order in which they appear in the transform functions.
interface CSSTransformValue : CSSValueList {
// OperationTypes
const unsigned short CSS_UNKNOWN = 0;
const unsigned short CSS_MATRIX = 1;
const unsigned short CSS_MATRIX3D = 2;
const unsigned short CSS_ROTATE = 3;
const unsigned short CSS_ROTATE3D = 4;
const unsigned short CSS_TRANSLATE = 5;
const unsigned short CSS_TRANSLATE3D = 6;
const unsigned short CSS_SCALE = 7;
const unsigned short CSS_SCALE3D = 8;
const unsigned short CSS_SKEWX = 9;
const unsigned short CSS_SKEWY = 10;
const unsigned short CSS_PERSPECTIVE = 11;
const unsigned short CSS_ROTATEX = 12;
const unsigned short CSS_ROTATEY = 13;
const unsigned short CSS_ROTATEZ = 14;
const unsigned short CSS_TRANSLATEX = 15;
const unsigned short CSS_TRANSLATEY = 16;
const unsigned short CSS_TRANSLATEZ = 17;
const unsigned short CSS_SCALEX = 18;
const unsigned short CSS_SCALEY = 29;
const unsigned short CSS_SCALEZ = 20;
attribute unsigned short operationType;
};
operationType of type unsigned short
In addition to the interfaces listed above, the getComputedStyle method of the Window
object has been updated. The transform property of the style object returned by
getComputedStyle contains a single CSSTransformValue with a type of CSS_MATRIX3D. The 16 parameters
represent the 4x4 matrix that is the result of applying the individual functions listed in the
transform property.