Transform Function
The tranform function data type represents a transformation (e.g. rotation, scaling, skewings) to an element.
The origin point for transformation(s) can be set by the transform-origin property.
Types of Transform Function
Rotation
rotate(a)
Rotates the element around the transform-origin on the 2D plane as far as a (clockwise).
div {
transform: rotate(120deg);
}
rotate3d(x, y, z, a)
Rotates an element around a fixed axis in 3D space as far as a (clockwise).
The axis of rotation is the vector that passes through transform-origin and the [x, y, z] vector.
div {
transform: rotate3d(1, -2, 0, 120deg);
}
rotateX(a)
Rotates around the x-axis, equivalent to rotate3d(1, 0, 0, a).
rotateY(a)
Rotates around the y-axis, equivalent to rotate3d(0, 1, 0, a).
rotateZ(a)
Rotates around the z-axis, equivalent to rotate3d(0, 0, 1, a).
Scaling
scale(sx, sy)
Scales an element up or down on the 2D plane.
scale3d(sx, sy, sz)
Scales an element up or down in 3D space.
scaleX(sx)
Scales an element along the x-axis, equivalent to scale3d(sx, 1, 1).
scaleY(sy)
Scales an element along the y-axis, equivalent to scale3d(1, sy, 1).
scaleZ(sz)
Scales an element along the z-axis, equivalent to scale3d(1, 1, sz).
Skewing
skew(ax, ay)
Skews an element on the 2D plane, ax and ay are in degrees. (Value of 90º will skew the image infinitely.)
skewX(ax)
Equivalent to skewX(ax, 0).
skewY(ay)
Equivalent to skewY(0, ay).
Translation
translate(tx, ty)
Translates an element on the 2D plane. You can specify a length or a percentage for the tx and ty values.
(Percentage values will be relative to the width/height of the reference box defined by the transform-box property.)
translate3d(tx, ty, tz)
Translates an element in 3D space. You can specify a length or a percentage for the tx and ty values,
but tz must be in length.
translateX(tx)
Equivalent to translate3d(tx, 0, 0).
translateY(ty)
Equivalent to translate3d(0, ty, 0).
translateZ(tz)
Equivalent to translate3d(0, 0, tz).
Perspective
perspective(d)
Sets the distance between the user and the z = 0 plane.
This is applied to the element itself, unlike perspective and perspective-origin properties
which are attached to the container (parent) of elements being transformed in 3D space.
div {
transform: perspective(800px);
}
Matrix Transformation
matrix(...)
Defines a homogeneous 2D transformation matrix:
Specify the following 6 values in order: a, b, c, d, tx, ty (unitless), where:
a,b,c,drepresent the linear transformation (scaling and skewing),tx,tyrepresent the translation.
matrix3d(...)
Defines a 3D transformation as a 4×4 homogeneous matrix:
Specify the following 16 values in order:
a1, b1, c1, d1, a2, b2, c2, d2,
a3, b3, c3, d3, a4, b4, c4, d4 (unitless),
where:
a1,b1,c1,d1, ...,a3,b3,c3,d3represent the linear transformation (scaling and skewing),a4,b4,c4,d4represent the translation.
See Also
- Homogeneous Coordinates (songho.ca) — http://www.songho.ca/math/homogeneous/homogeneous.html
References
- <transform-function> (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function
- rotate() (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate()
- rotate3d() (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate3d()
- scale() (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scale()
- skew() (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skew()
- translate() (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/translate()
- translate3d() (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/translate3d()
- perspective() (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/perspective()
- matrix() (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix()
- matrix3d() (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d()