Skip to content

CSS3 3D Transforms

CSS 3D transforms extend 2D transforms by allowing you to manipulate elements in three-dimensional space, adding depth and perspective.

You can rotate elements around the X, Y, or Z axes, and translate them along the Z-axis (towards or away from the viewer).

Compare 2D vs 3D rotation (imagine hovering over examples):

2D Rotate (Flat Spin)
3D Rotate (Tilted Spin)

3D transforms are well-supported in modern browsers. Vendor prefixes might be needed for some older versions but are generally unnecessary now.

PropertyInternet ExplorerChromeFirefoxSafariOpera
transform (3D functions)IE 10+ChromeFirefox 10+SafariOpera
perspectiveIE 10+ChromeFirefox 16+SafariOpera
transform-styleIE 11+ChromeFirefox 16+SafariOpera
backface-visibilityIE 10+ChromeFirefox 16+SafariOpera

To enable a true 3D context for child elements, you need to apply properties to the parent container:

  • perspective: Defines the strength of the perspective effect (how ‘deep’ the 3D space appears). Lower values mean more extreme perspective. Applied to the parent. Example: perspective: 1000px;.
  • perspective-origin: Sets the vanishing point position for the perspective effect. Default is center center. Applied to the parent.
  • transform-style: preserve-3d;: Allows child elements positioned in 3D space to maintain their 3D positions relative to each other. Applied to the parent (or any element containing 3D-transformed children).

Without these parent properties, 3D transforms on children might appear ‘flattened’.

These are applied using the transform property on the element you want to manipulate:

  • rotateX(angle): Rotates the element around the horizontal X-axis.
  • rotateY(angle): Rotates the element around the vertical Y-axis.
  • rotateZ(angle): Rotates the element around the Z-axis (similar to 2D rotate).
  • rotate3d(x, y, z, angle): Rotates around a custom 3D vector.
  • translateZ(distance): Moves the element along the Z-axis (closer or further).
  • translate3d(x, y, z): Moves the element in 3D space.
  • scaleZ(factor): Scales the element along the Z-axis.
  • scale3d(x, y, z): Scales the element in 3D space.
  • matrix3d(...): Combines all 3D transforms using a 4x4 matrix.

Rotates an element around its horizontal axis, like flipping it forwards or backwards.

[Imagine an element tilting forward]

Example: Rotate 60 degrees around the X-axis.

.container {
perspective: 500px; /* Needed for visible 3D effect */
}
.target-element {
transform: rotateX(60deg);
}

Rotates an element around its vertical axis, like opening a door.

[Imagine an element spinning like a revolving door]

Example: Rotate -45 degrees around the Y-axis.

.container {
perspective: 500px;
}
.target-element {
transform: rotateY(-45deg);
}

Rotates an element around the axis perpendicular to the screen (same as 2D rotate()).

[Imagine an element spinning flat on the screen]

Example: Rotate 90 degrees around the Z-axis.

.target-element {
transform: rotateZ(90deg); /* No perspective needed to see this */
}

Determines if the ‘back’ side of an element is visible when it’s rotated to face away from the viewer.

  • visible (default): The back face is shown (often mirrored).
  • hidden: The back face is hidden, making the element invisible when facing away.

Example: Hide element when rotated 180 degrees on Y-axis.

.card {
transform-style: preserve-3d; /* If card has front/back faces */
backface-visibility: hidden;
transform: rotateY(180deg);
}
PropertyDescription
transformApplies a 2D or 3D transformation to an element.
transform-originChanges the position of the origin point for transformations.
transform-styleSpecifies how nested elements are rendered in 3D space (flat or preserve-3d). Applied to parent.
perspectiveSets the perspective depth for 3D transforms. Applied to parent.
perspective-originSets the vanishing point position. Applied to parent.
backface-visibilityDefines whether the back face of an element is visible when rotated (visible or hidden).
FunctionDescription
matrix3d(…)Defines a 3D transformation using a 4x4 matrix of 16 values.
translate3d(x,y,z)Defines a 3D translation.
translateX(x)Defines translation along the X-axis (same as 2D).
translateY(y)Defines translation along the Y-axis (same as 2D).
translateZ(z)Defines translation along the Z-axis.
scale3d(x,y,z)Defines a 3D scale transformation.
scaleX(x)Defines scale along the X-axis (same as 2D).
scaleY(y)Defines scale along the Y-axis (same as 2D).
scaleZ(z)Defines scale along the Z-axis.
rotate3d(x,y,z,angle)Defines a 3D rotation around a custom vector.
rotateX(angle)Defines a 3D rotation along the X-axis.
rotateY(angle)Defines a 3D rotation along the Y-axis.
rotateZ(angle)Defines a 3D rotation along the Z-axis (same as 2D rotate).
perspective(n)Defines a perspective view directly on the element (less common than applying perspective to parent).