</> Code Corner

CSS · CSS Advanced · Lesson 47

CSS 2D Transforms

translate, rotate, scale and skew.

CSS transforms allow you to move, rotate, scale and skew elements.

Example

<style>
.b { width: 120px; height: 60px; background: #04AA6D; color: white; margin: 30px; display: inline-block; text-align: center; line-height: 60px; font-family: Arial; }
.t { transform: translate(20px, 10px); }
.r { transform: rotate(20deg); }
.s { transform: scale(1.3); }
.k { transform: skewX(20deg); }
</style>
<div class="b t">translate</div>
<div class="b r">rotate</div>
<div class="b s">scale</div>
<div class="b k">skew</div>
Function Effect
translate(x, y) Moves the element
rotate(deg) Rotates clockwise (negative = counter-clockwise)
scale(x, y) Increases or decreases size
skew(x, y) Skews along the X and Y axes
matrix() Combines all 2D transforms

Keep reading “CSS 2D Transforms”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋