HTML & CSS - Mastery / Advanced CSS Features

Transforms: Scale, Rotate, Translate

๐Ÿค– CSS transform

CSS transform lets you visually manipulate elements โ€” move, rotate, resize, or skew them โ€” without affecting the document flow.


โœ… General Syntax

selector {
  transform: function(value);
}

Multiple transforms can be combined:

transform: scale(1.2) rotate(15deg) translateX(20px);

๐Ÿ”น Scale

Resizes the element โ€” larger or smaller, horizontally and/or vertically.

๐Ÿ“Œ Syntax

transform: scale(x);         /* uniform scale */
transform: scale(x, y);      /* scaleX and scaleY separately */

๐Ÿ“Œ Examples:


๐Ÿ”น Rotate

Rotates the element around its center (by default).

๐Ÿ“Œ Syntax:

transform: rotate(angle);
  • Angles in degrees (deg), radians (rad), turns (turn)

๐Ÿ“Œ Examples

<div class="box">Rotated</div>

๐Ÿ”นTranslate

Moves the element from its current position, without affecting layout.

๐Ÿ“Œ Syntax:

transform: translate(x, y);
transform: translateX(value);
transform: translateY(value);

๐Ÿ“Œ Examples:

<div class="container">
   <div class="box">โ†’ โ†“</div>
   <div class="box-left">โ†</div>
   <div class="box-up">โ†‘</div>
</div>

๐Ÿ”นCombining Multiple Transforms

You can chain multiple transform functions:

<body>
  <div class="box">Transform</div>
</body>

๐Ÿ”น Transform Origin

Change the pivot point (default is center):

transform-origin: top left;
<body>
  <div class="box">โ†ป</div>
</body>

๐Ÿ”น Transition (Smooth Movement)

You can use transition to animate transforms smoothly:

<body>
  <div class="box">Hover Me</div>
</body>

โœ… Summary Table

Transform

Description

Example

scale()

Resize the element

scale(1.5)

rotate()

Rotate the element

rotate(45deg)

translate()

Move the element

translate(50px, -20px)

transform

Combine multiple effects

scale(1.1) rotate(10deg)

origin

Set pivot point for transformations

transform-origin: top left