CSS 2D Transforms

CSS3 supports transform property. This transform property facilitates you to translate, rotate, scale, and skews elements.

Transformation is an effect that is used to change shape, size and position.

There are two type of transformation i.e. 2D and 3D transformation supported in CSS3.

Transform is a process in which elements are visually modified by different transformation method on Web page elements, This makes the webpage even more real and live. We can apply 2D and 3D transformation property on any element. Here we can know about CSS 2D transforms method.

CSS 2D Transforms

following are the 2D transformation methods

  • 1. Translate()
  • 2. scale()
  • 3. rotate()
  • 4. skew()
  • 5. matrix()

The CSS 2D transforms are used to re-change the structure of the element as translate, rotate, scale and skew etc.

  • translate(x,y): It is used to transform the element along X-axis and Y-axis.
  • translateX(n): It is used to transform the element along X-axis.
  • translateY(n): It is used to transform the element along Y-axis.
  • rotate(): It is used to rotate the element on the basis of an angle.
  • scale(x,y): It is used to change the width and height of an element.
  • scaleX(n): It is used to change the width of an element.
  • scaleY(n): It is used to change the height of an element.
  • skewX(): It specifies the skew transforms along with X-axis.
  • skewY():It specifies the skew transforms along with Y-axis.
  • matrix(): It specifies matrix transforms.

The translate() Method

The CSS translate() method is used to move an element from its current position according to the given parameters i.e. X-axis and Y-axis.

Let's take an example to translate a element 50 pixels right, and 100 pixels down from its current position.

Example -

The scale() Method

This method is use to increase and decrease the size of the elements.Let’s understand with the help of example.

Example -

The rotate() Method

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

Example -

The skewX() Method

The skewX() method skews an element along the X-axis by the given angle.

The following example skews the

element 20 degrees along the X-axis:

Example -

The matrix() Method

This method is the combination of all 2D tranformation methods. Here is the syntax of matrix().The matrix() method combines all the 2D transform methods into one.The matrix() method take six parameters, containing mathematic functions, which allows you to rotate, scale, move (translate), and skew elements.The parameters are as follow: matrix(scaleX(),skewY(),skewX(),scaleY(),translateX(),translateY())

CSS Transform Properties

The following table lists all the 2D transform properties:

PropertyDescription
transformApplies a 2D or 3D transformation to an element
transform-originAllows you to change the position on transformed elements

2D Transform Methods

FunctionDescription
matrix(n,n,n,n,n,n)Defines a 2D transformation, using a matrix of six values
translate(x,y)Defines a 2D translation, moving the element along the X- and the Y-axis
translateX(n)Defines a 2D translation, moving the element along the X-axis
translateY(n)Defines a 2D translation, moving the element along the Y-axis
scale(x,y)Defines a 2D scale transformation, changing the elements width and height
scaleX(n)Defines a 2D scale transformation, changing the element's width
scaleY(n)Defines a 2D scale transformation, changing the element's height
rotate(angle)Defines a 2D rotation, the angle is specified in the parameter
skew(x-angle,y-angle)Defines a 2D skew transformation along the X- and the Y-axis
skewX(angle)Defines a 2D skew transformation along the X-axis
skewY(angle)Defines a 2D skew transformation along the Y-axis