CSS: Transform

By Xah Lee. Date: . Last updated: .

What is CSS transform

CSS 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.

Translate

“translate” in geometry means moving it to a different place.

value can be percentage.

transform: translate(1rem, 0);
.x {
 transform: translate(1rem, 0);
}

Scale

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

Rotate

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

Skew

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

Combined

the transform order applied is right to left.

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

transform matrix

you can specify a transform matrix directly.

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

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);
}
xtodo

3D Transform

CSS. Transform, Animation

CSS Position