JavaScript Tutorial

CSS 2D Transformation

We can perform basic transform manipulations such as move, rotate, scale, and skew on elements in a two-dimensional space.

It is an effect that is used to change shape, size, and position. There are two types of transformation i.e. 2D and 3D transformation supported in CSS3.

A transformed element doesn't affect the surrounding elements but can overlap them, just like the absolutely positioned elements.

CSS 2D Transformation allows us to manipulate elements in a two-dimensional space by applying basic transformations such as move, rotate, scale, and skew.

These transformations can be used to change the shape, size, and position of elements. CSS3 supports both 2D and 3D transformations.

When applying a 2D transformation to an element, it doesn't affect the surrounding elements but can overlap them, similar to absolutely positioned elements.

By utilizing CSS 2D Transformation, we can create visually dynamic effects and animations on elements, enhancing the overall user experience of a webpage.

Transformation Method

This method is used to re-change the structure of the element as translate, rotate, scale and skew, etc.

Format

Description

translate(x,y)

used to transform the element along X-axis and Y-axis

translateX(n)

used to transform the element along X-axis

translateY(n)

used to transform the element along Y-axis.

Rotate()

used to rotate the element on the basis of an angle

scale(x,y)

used to change the width and height of an element

scaleX(n)

used to change the width of an element

scaleY(n)

used to change the height of an element

skewX()

specifies the skew transforms along with X-axis

skewY()

specifies the skew transforms along with Y-axis

matrix()

specifies matrix transforms

translate() method

This method is used to move an element from its current position according to the given parameters i.e. X-axis and Y-axis.

Input:-

 

Output:-

 

rotate() method

This method is used to rotate an element clockwise or anti-clockwise according to the given degree.

Input:-

 

Output:-

 

scale() method

This method is used to increase or decrease the size of an element according to the given width and height.

Input:-

 

Output:-

 

skewX() method

This method is used to skew an element along the X axis according to the given angle.

Input:-

 

Output:-

 

skewY() method

This method is used to skew an element along the Y axis according to the given angle.

Input:-

 

Output:-

 

skew() method

This method is used to skew an element along with X-axis and Y-axis according to the given angle.

Input:-

 

Output:-

 

matrix() method

This method combines all six 2D transform methods altogether. It allows you to rotate, scale, translate, and skew elements.

Input:-

 

Output:-

 

Go back to Previous Course