Skip to main content

CSS 3D Transforms

Through the transform property, an element can be moved, rotated, scaled or skewed, in 2D as well as 3D.


CSS 3D Transforms Functions

For 3D transformations, transform takes the functions below:

  • rotateX()
  • rotateY()
  • rotateZ()

The CSS rotateX() Function

Spinning around the X-axis is the job of rotateX(), which takes the amount of rotation in degrees.

Example

Prompt
Create a page with a div element styled with a background color. Apply a CSS 3D transform using rotateX(150deg) to rotate it around the X-axis.
Output: complete HTML page

The CSS rotateY() Function

Pass a degree value to rotateY() and the element turns around its Y-axis by that much.

Example

Prompt
Create a page with a div element styled with a background color. Apply a CSS 3D transform using rotateY(150deg) to rotate it around the Y-axis.
Output: complete HTML page

The CSS rotateZ() Function

With rotateZ(), the axis of rotation is the element's Z-axis, and the angle is again given in degrees.

Example

Prompt
Create a page with a div element styled with a background color. Apply a CSS 3D transform using rotateZ(90deg) to rotate it around the Z-axis.
Output: complete HTML page