Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS3 3D Transforms

CSS3 3D Transforms


3D Transforms

CSS3 allows you to format elements using 3D transforms.

In this chapter you will learn some of the 3D transform methods:

Click the element below to see the difference between 2D and 3D transforms:

2D rotate

3D rotate


Browser support

The numbers in the table indicate the first browser version that supports this property.

A number immediately before -webkit-, -ms-, or -moz- indicates the first browser version that supports that prefixed property.

property
transform 36.0
12.0 -webkit- 10.0 16.0
10.0 -moz- 4.0 -webkit- 23.0
15.0 -webkit-
transform-origin
(three-value syntax) 36.0
12.0 -webkit- 10.0 16.0
10.0 -moz- 4.0 -webkit- 23.0
15.0 -webkit-
transform-style 36.0
12.0 -webkit- 11.0 16.0
10.0 -moz- 4.0 -webkit- 23.0
15.0 -webkit-
perspective 36.0
12.0 -webkit- 10.0 16.0
10.0 -moz- 4.0 -webkit- 23.0
15.0 -webkit-
perspective-origin 36.0
12.0 -webkit- 10.0 16.0
10.0 -moz- 4.0 -webkit- 23.0
15.0 -webkit-
backface-visibility 36.0
12.0 -webkit- 10.0 16.0
10.0 -moz- 4.0 -webkit- 23.0
15.0 -webkit-

The rotateX() Method

The rotateX() method rotates an element around its X-axis by a given number of degrees.

Example

div

{

transform:

rotateX

(

120

deg

)

; -

webkit-transform:

rotateX

(

120

deg

)

;

/*

Safari and Chrome

*/

}

Try it »


The rotateY() Method

The rotateY() method rotates an element around its Y-axis by a given number of degrees.

Example

div

{

transform:

rotateY

(

130

deg

)

; -

webkit-transform:

rotateY

(

130

deg

)

;

/*

Safari and Chrome

*/

}

Try it »


Transform Properties

The following table lists all the transform properties:

property Description CSS
transform Applies a 2D or 3D transform to an element. 3
transform-origin Allows you to change the position of the transformed element. 3
transform-style Specifies how nested elements are displayed in 3D space. 3
perspective Specifies the perspective effect for a 3D element. 3
perspective-origin Specifies the bottom position of a 3D element. 3
backface-visibility Defines whether an element is visible when it is not facing the screen. 3

3D Transform Methods

function Description
matrix3d(n,n,n,n,n,n,
n,n,n,n,n,n,n,n,n,n) Defines a 3D transformation, using a 4x4 matrix of 16 values.
translate3d(x,y,z) Defines a 3D transform.
translateX(x) Defines a 3D transform, using values for the X-axis only.
translateY(y) Defines a 3D transform, using values for the Y-axis only.
translateZ(z) Defines a 3D transform, using values for the Z-axis only.
scale3d(x,y,z) Defines a 3D scaling transformation.
scaleX(x) Defines a 3D scaling transform, by giving a value for the X-axis.
scaleY(y) Defines a 3D scaling transform, by giving a value for the Y-axis.
scaleZ(z) Defines a 3D scaling transform, by giving a value for the Z-axis.
rotate3d(x,y,z,angle) Defines a 3D rotation.
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.
perspective(n) Defines the perspective view for a 3D transformed element.