2D Transforms
suggest changeThe transform property changes how an element is rendered without changing the space reserved for it in normal layout.
| Function | Purpose |
|---|---|
translate(x, y) |
Move along the x- and y-axes. |
translateX(x), translateY(y) |
Move along one axis. |
rotate(angle) |
Rotate around the transform origin. |
scale(x, y) |
Scale along one or both axes. |
skew(x, y) |
Apply a shear transformation. |
matrix(a, b, c, d, tx, ty) |
Express a 2D transform as a matrix. |
.preview {
transform: translate(1rem, 20%) rotate(0.125turn) scale(1.1);
transform-origin: center;
}
Positive x values move toward the physical right in the usual coordinate system, and positive y values move downward. Percentages in a translation are relative to the transformed element's reference box.
Transform functions are order-sensitive:
.first {
transform: translateX(5rem) rotate(30deg);
}
.second {
transform: rotate(30deg) translateX(5rem);
}
These rules generally produce different results. Modern browsers support 2D transforms without vendor prefixes.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents