Transform
transform
transform moves, rotates, scales and skews an element. List several functions separated by spaces and they combine in order.
Syntax
none | <transform-list>
<transform-list> = <transform-function>+Preview
Presets
Drag the bottom-right corner to resize
Code
.box {
background: linear-gradient(
135deg,
#88d1c7,
#77a7d7,
#eaac3a
);
border-radius: 8px 32px;
transform: translateX(40px) rotate(15deg);
}Controls
translateX(40px)
<length-percentage>
rotate(15deg)
<angle>
Add a function
About
The functions
translate()moves the element. Percentages are relative to the element’s own size, not its parent. Leaving out the second value (y) means0.rotate()rotates; positive angles turn clockwise.scale()resizes.1(100%) leaves it as is, and negative values flip it. Leaving out the second value repeats the first.skew()slants the element. Leaving out the second value means0.- Functions ending in X or Y, such as
translateX(), work along one axis only.
Order matters
Functions apply from left to right, each one changing the direction and scale for the next. Rotate first and a later move goes in the rotated direction. Compare the “Move, then rotate” and “Rotate, then move” presets, or reorder the cards in the controls.
Layout stays put
A transformed element keeps its place in the layout, and its neighbors don’t move. The dashed outline in the preview shows where the element was before the transform. Change the center of rotation and scaling with transform-origin (by default the middle, 50% 50%).
Watch out
- Any value other than
nonemakes the element a stacking context and the containing block forposition: fixeddescendants. - The standalone
translate,rotateandscaleproperties also exist and apply beforetransform, in that order. - The controls cover the 2D functions only. Type
rotateX(),perspective()ormatrix()into the code and the preview still shows them.