2D Transforms
transform changes how an element is drawn without affecting the layout of its neighbours. Functions include translate(x, y), rotate(45deg), scale(1.2) and skew(10deg). Combine several by separating them with spaces; they apply right to left.
transform-origin sets the pivot point, which defaults to the centre. Transforms are fast because they are handled by the graphics hardware.
Example
<style>
.row div { display: inline-block; width: 70px; height: 70px; margin: 24px; background: #0ea5e9; color: white; text-align: center; line-height: 70px; transition: transform 0.3s; }
.t:hover { transform: translateX(20px); }
.r { transform: rotate(20deg); }
.s { transform: scale(1.3); }
.k { transform: skew(15deg); }
</style>
<div class="row">
<div class="t">Move</div><div class="r">Spin</div><div class="s">Big</div><div class="k">Skew</div>
</div>Exercise
Rotate the box by 45 degrees.
.box { transform: (45deg); }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.