Skip to main content

Master CSS 2D transforms to improve your web design with visual effects

CSS 2D Transforms are a set of properties that allow you to transform elements in 2D space. They can be used to translate, rotate, scale, skew, and apply other effects to elements on a web page.

Here are some of the most common CSS 2D Transform properties:

transform: translate(x, y)

This property allows you to move an element in the x and y directions. You can specify the amount of movement in pixels, percentages, or other units.

As an example:

Editor

Loading...

In this example:

  • The .box element is moved 50 pixels to the right and 20 pixels down.

transform: rotate(angle)

This property allows you to rotate an element around a specified angle. You can use degrees, radians, or other units to specify the angle.

As an example:

Editor

Loading...

In this example:

  • The .box element is rotated around its center by 45 degrees.

transform: scale(x, y)

This property allows you to resize an element in the x and y directions. You can specify the scaling factor as a decimal or percentage.

As an example:

Editor

Loading...

In this example:

  • The .box element is scaled to 1.5 times its original size in the x direction and 0.5 times its original size in the y direction.

transform: skew(x-angle, y-angle)

This property allows you to skew an element in the x and y directions. You can specify the amount of skew using degrees or radians.

As an example:

Editor

Loading...

In this example:

  • The .box element is skewed 30 degrees in the x direction and -15 degrees in the y direction.

transform-origin

This property allows you to specify the point around which an element is transformed. You can specify the origin using pixels, percentages, or other units.

As an example:

Editor

Loading...

In this example:

  • The .box element is transformed around its top-left corner.

Here's an example of how you can use CSS 2D Transforms to create a simple animation:

Editor

Loading...

In this example:

  • The .box element is moved horizontally using the translateX function, and the animation is created using the @keyframes rule.
  • The infinite keyword makes the animation loop indefinitely, and the alternate keyword makes the animation reverse direction each time it runs.