CSS 2D Transforms - Detailed Overview

Introduction to 2D Transforms

2D transforms in CSS allow you to manipulate elements in two-dimensional space. The main 2D transform functions include:

Rotate

The rotate() function rotates an element by a specified angle. Here is an example:

.rotate { transform: rotate(45deg); }
This element is rotated 5 degrees.

Scale

The scale() function scales an element up or down. The default scale factor is 1, so a factor greater than 1 will enlarge the element, and a factor less than 1 will shrink it. Here is an example:

.scale { transform: scale(1.5); }
This element is scaled 1.5 times its original size.

Translate

The translate() function moves an element from its current position. You can specify movement in the X and Y directions. Here is an example:

.translate { transform: translateX(50px); }
This element is moved 50px to the right.

Skew

The skew() function tilts an element along the X and Y axes. Here is an example:

.skew { transform: skew(20deg, 10deg); }




This element is skewed by 20 degrees along the X axis and 10 degrees along the Y axis.