CSS: Transform

By Xah Lee. Date: . Last updated: .

What is css transform

CSS property transform lets you apply a geometric transformation on HTML element. e.g. translate, rotate, scale.

transform changes the rendering, after all other CSS properties (e.g. margin, padding, width, height, etc.) are calculated.

transform does not effect rest element's layout.

Function: translate

Function: scale, scalex, scaley

transform: scale(1, 3);
.x {
 transform: scale(1, 3);
}

Function: rotate

transform: rotate(10deg);
.x {
 transform: rotate(10deg);
}

Function: skew

transform: skew(10deg);
.x {
 transform: skew(20deg);
}
transform: skewY(10deg);

Example. combine transforms

the transform order applied is right to left.

transform: skew(10deg) scale(1, 0.8) rotate(2deg) translate(16px, 0);
.x {
 transform: skew(10deg) scale(1, 0.8) rotate(2deg) translate(16px, 0);
}

Transform matrix function

you can specify a transform matrix directly.

/* matrix(a, b, c, d, tx, ty) */
.x {
 transform: matrix(1, 0, 0, 1, 50, 50);
 /* identity + translate */
}

Property transform-origin

transform-origin property defines the point around which a transformation is applied.

By default, this origin is set to the center of the element (50% 50%).

You can specify the origin using keywords, percentages, or length values for the X and Y axes, and optionally the Z axis for 3D transforms:

transform-origin: 0 0; transform: rotate(45deg);
.x {
 /* top-left corner */
 transform-origin: 0 0;
 transform: rotate(45deg);
}

CSS. Transform, Animation