--- title: slug: Web/CSS/transform-function tags: - CSS - CSS Data Type - CSS Transforms - Layout - NeedsTranslation - Reference - TopicStub translation_of: Web/CSS/transform-function ---
{{CSSRef}}

The <transform-function> CSS data type denotes a function used to modify an element's appearance. A transform can usually be expressed by matrices, with the result determined by using matrix multiplication on each point.

Coordinates for 2D graphics

Various coordinate models can be used to describe any transformation. The most common are the Cartesian coordinate system and homogeneous coordinates.

Cartesian coordinates

In the Cartesian coordinate system each point of Euclidian space is described using two values: the abscissa and the ordinate. In CSS (and most computer graphics), the origin (0, 0) is the top-left corner of any element. Each point is mathematically described using the vector notation (x, y).

Each linear function is described using a 2x2 matrix like:

ac bd

By using matrix multiplication with the linear function and each point in question, a transformation is created:

.

Note that it is possible to apply several transformations in a row:

.
 

With this notation, it is possible to describe, and therefore composite, most common transformations: rotations, scaling, or skewing. In fact, all transformations that are linear functions can be described. Composite transforms are effectively applied in order from right to left. However, one major transformation is not linear and therefore must be special-cased when using this notation: translation. The translation vector (tx, ty) must be expressed separately, as two additional parameters.

Möbius' homogeneous coordinates in projective geometry leading to 3x3 transformation matrices, though more complex and unusual for non-specialists, doesn't suffer from the translation limitation as these can be expressed as linear functions in this algebra, removing the need for special cases.

Functions defining transformations

Several functions are available to describe transformations in CSS. Each one applies a geometric operation, in 2D or 3D:

{{cssxref("transform-function/matrix","matrix()")}}
The matrix() CSS function specifies a homogeneous 2D transformation matrix comprised of the specified six values. The constant values of such matrices are implied and not passed as parameters; the other parameters are described in the column-major order.
matrix(a, b, c, d, tx, ty) is a shorthand for matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1).
{{cssxref("transform-function/matrix3d","matrix3d()")}}
The matrix3d() CSS function describes a 3D transform as a 4x4 homogeneous matrix. The 16 parameters are described in the column-major order.
{{cssxref("transform-function/perspective","perspective()")}}
The perspective() CSS function defines the distance between the z=0 plane and the user in order to give to the 3D-positioned element some perspective. Each 3D element with z>0 becomes larger; each 3D-element with z<0 becomes smaller. The strength of the effect is determined by the value of this property.
{{cssxref("transform-function/rotate","rotate()")}}
The rotate() CSS function defines a transformation that moves the element around a fixed point (as specified by the {{ Cssxref("transform-origin") }} property) without deforming it. The amount of movement is defined by the specified angle; if positive, the movement will be clockwise, if negative, it will be counter-clockwise. A rotation by 180° is called point reflection.
{{cssxref("transform-function/rotate3d","rotate3d()")}}
The rotate3d() CSS function defines a transformation that moves the element around a fixed axis without deforming it. The amount of movement is defined by the specified angle; if positive, the movement will be clockwise, if negative, it will be counter-clockwise.In opposition to rotations in the plane, the composition of 3D rotations is usually not commutative; it means that the order in which the rotations are applied is crucial.
{{cssxref("transform-function/rotateX","rotateX()")}}
The rotateX() CSS function defines a transformation that moves the element around the abscissa without deforming it. The amount of movement is defined by the specified angle; if positive, the movement will be clockwise, if negative, it will be counter-clockwise. The axis of rotation passes by the origin, defined by {{ cssxref("transform-origin") }} CSS property.
rotateX(a)is a shorthand for rotate3D(1, 0, 0, a).
{{cssxref("transform-function/rotateY","rotateY()")}}
The rotateY() CSS function defines a transformation that moves the element around the ordinate without deforming it. The amount of movement is defined by the specified angle; if positive, the movement will be clockwise, if negative, it will be counter-clockwise. The axis of rotation passes by the origin, defined by {{ cssxref("transform-origin") }} CSS property.
rotateY(a)is a shorthand for rotate3D(0, 1, 0, a).
{{cssxref("transform-function/rotateZ","rotateZ()")}}
The rotateZ() CSS function defines a transformation that moves the element around the z-axis without deforming it. The amount of movement is defined by the specified angle; if positive, the movement will be clockwise, if negative, it will be counter-clockwise. The axis of rotation passes by the origin, defined by {{ cssxref("transform-origin") }} CSS property.
rotateZ(a)is a shorthand for rotate3D(0, 0, 1, a).
{{cssxref("transform-function/scale","scale()")}}
The scale() CSS function modifies the size of the element. It can either augment or decrease its size and as the amount of scaling is defined by a vector, it can do so more in one direction than in another one. This transformation is characterized by a vector whose coordinates define how much scaling is done in each direction. If both coordinates of the vector are equal, the scaling is uniform, or isotropic, and the shape of the element is preserved. In that case, the scaling function defines a homothetic transformation.
{{cssxref("transform-function/scale3d","scale3d()")}}
The scale3d() CSS function modifies the size of an element. Because the amount of scaling is defined by a vector, it can resize different dimensions at different scales. This transformation is characterized by a vector whose coordinates define how much scaling is done in each direction. If all three coordinates of the vector are equal, the scaling is uniform, or isotropic, and the shape of the element is preserved. In that case, the scaling function defines a homothetic transformation.
{{cssxref("transform-function/scaleX","scaleX()")}}
The scaleX() CSS function modifies the abscissa of each element point by a constant factor, except if this scale factor is 1, in which case the function is the identity transform. The scaling is not isotropic and the angles of the element are not conserved. scaleX(-1) defines an axial symmetry with a vertical axis passing by the origin (as specified by the {{cssxref("transform-origin")}} property).
scaleX(sx) is a shorthand for scale(sx, 1) or for scale3d(sx, 1, 1).
{{cssxref("transform-function/scaleY","scaleY()")}}
The scaleY() CSS function modifies the ordinate of each element point by a constant factor except if this scale factor is 1, in which case the function is the identity transform. The scaling is not isotropic and the angles of the element are not conserved. scaleY(-1) defines an axial symmetry with a horizontal axis passing by the origin (as specified by the {{cssxref("transform-origin")}} property).
scaleY(sy) is a shorthand for scale(1, sy) or for scale3d(1, sy, 1).
{{cssxref("transform-function/scaleZ","scaleZ()")}}
The scaleZ() CSS function modifies the z-coordinate of each element point by a constant factor, except if this scale factor is 1, in which case the function is the identity transform. The scaling is not isotropic and the angles of the element are not conserved. scaleZ(-1) defines an axial symmetry along the z-axis passing by the origin (as specified by the {{cssxref("transform-origin")}} property).
scaleZ(sz) is a shorthand for scale3d(1, 1, sz).
{{cssxref("transform-function/skew","skew()")}}
The skew() CSS function is a shear mapping, or transvection, distorting each point of an element by a certain angle in each direction. It is done by increasing each coordinate by a value proportionate to the specified angle and to the distance to the origin. The more far from the origin, the more away the point is, the greater will be the value added to it.
{{cssxref("transform-function/skewX","skewX()")}}
The skewX() CSS function is a horizontal shear mapping distorting each point of an element by a certain angle in the horizontal direction. It is done by increasing the abscissa coordinate by a value proportionate to the specified angle and to the distance to the origin. The more far from the origin, the more away the point is, the greater will be the value added to it.
{{cssxref("transform-function/skewY","skewY()")}}
The skewY() CSS function is a vertical shear mapping distorting each point of an element by a certain angle in the vertical direction. It is done by increasing the ordinate coordinate by a value proportionate to the specified angle and to the distance to the origin. The more far from the origin, the more away the point is, the greater will be the value added to it.
{{cssxref("transform-function/translate","translate()")}}
The translate() CSS function moves the position of the element on the plane. This transformation is characterized by a vector whose coordinates define how much it moves in each direction.
{{cssxref("transform-function/translate3d","translate3d()")}}
The translate3d() CSS function moves the position of the element in the 3D space. This transformation is characterized by a 3-dimension vector whose coordinates define how much it moves in each direction.
{{cssxref("transform-function/translateX","translateX()")}}
The translateX() CSS function moves the element horizontally on the plane. This transformation is characterized by a {{cssxref("<length>")}} defining how much it moves horizontally.
translateX(tx) is a shorthand for translate(tx, 0).
{{cssxref("transform-function/translateY","translateY()")}}
The translateY() CSS function moves the element vertically on the plane. This transformation is characterized by a {{cssxref("<length>")}} defining how much it moves vertically.
translateY(ty) is a shorthand for translate(0, ty).
{{cssxref("transform-function/translateZ","translateZ()")}}
The translateZ() CSS function moves the element along the z-axis of the 3D space. This transformation is characterized by a {{cssxref("<length>")}} defining how much it moves.
translateZ(tz) is a shorthand for translate3d(0, 0, tz).

Specifications

Specification Status Comment
{{SpecName('CSS3 Transforms', '#transform-property', 'transform')}} {{Spec2('CSS3 Transforms')}} Initial definition.

Browser compatibility

{{Compat("css.types.transform-function")}}

See also