CSS 2D Transform

CSS 2D Transform is used to change the structure of an element. You can change the shape, size and position of an element using 2D transform. Here are some common values which are used in 2D transforms:

  • translate()
  • rotate()
  • scale()
  • skewX()
  • skewY()
  • skew()
  • matrix()

The translate() Method

The translate() method is used to move the element from its actual position to along the X-axis and Y-axis.

Example:

div {
  transform: translate(30px, 50px);
}


Run Example

The rotate() Method

The rotate() method rotates an element clockwise or counter-clockwise according to a given degree.

Example:

div {
  transform: rotate(15deg);
}


Run Example

You have to use negative values to rotate the element counter-clockwise.

Example:

div {
  transform: rotate(-15deg);
}


Run Example

The scale() Method

The scale() method is used to increase or decrease the size of an element according to the parameter given for the width and height. The given example increases the element two times of its actual width, and three times of its actual height:

Example:

div {
  transform: scale(2, 3);
}


Run Example

The skewX() Method

The skewX() method is used to skew an element in the given angle along the X-axis.

Example:

div {
  transform: skewX(15deg);
}


Run Example

The skewY() Method

The skewY() method is used to skew an element in the given angle along the Y-axis.

Example:

div {
  transform: skewY(15deg);
}


Run Example

The skew() Method

The skew() method is used to skew an element in the given angle along the X-axis and the Y-axis. The following example skews the element 20 degrees along the X-axis, and 10 degrees along the Y-axis:

Example:

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


Run Example

The matrix() Method

The matrix() method combines all the 2D transform property into a single property. The matrix transform property accepts six parameters are as follow: matrix( scaleX(), skewY(), skewX(), scaleY(), translateX(), translateY() )

Example:

div {
  transform: matrix(1, -0.3, 0, 1, 0, 0);
}


Run Example

Browser Support

Attribute Firefox Chrome IE Opera Safari
transform 16.0 36.0 10.0 23.0 9.0