The rotate() function and its derivatives.
Summary of characteristics of the rotate()
function
Description of the function: rotateX()
, rotateY()
and rotateZ()
.
These three functions, used with the transform
property, cause the element to rotate around one of the axes.
Rotations around the Z axis keep the element in the plane of the screen (2D transformation), while rotations around
of the X or Y axes are 3D transformations.
3D space is defined by three axes, X
, Y
, and Z
, as shown below.
The X
and Y
axes are in the plane of the screen, while the Z
axis is directed towards the reader's eyes.
Circular arrows indicate the direction of rotation for a positive angle value.
Description if the rotate()
function.
The rotate()
function is exactly equivalent to rotateZ()
: it defines a rotation around the Z axis, i.e.
in the plane of the screen (2D transformation).
Description of the rotate3d()
function.
rotate3d()
calculates a rotation in the 3D plane. This rotation can then be applied to an element by the transform
property.
rotate3d()
is not a simple shorthand for the other three rotation functions because it allows you to define a rotation axis
other than one of the three standard axes.
rotate3d()
can however replace the three elementary rotation functions rotateX()
,rotateY()
and rotateZ()
,
at the cost of a slight complication of the syntax for writing parameters.
Note: In order for the rotations around the X and Y axes to be visible, you must also apply an effect of perspective()
otherwise the element
seems simply crushed.
To do this, we use the perspective()
function so that the rotation is perceived as such, and not as a simple crushing of the element. Example:
transform: perspective(50px) rotate3d(1, 0.5, 1, 45deg);
These rotation functions can be used with:
transform
: Applies one or more geometric transformations (rotations, enlargements, etc.).
Rotation Function Syntax.
- transform: rotateX(45deg); transform: rotateY(45deg); transform: rotateZ(45deg); transform: rotate(45deg);
These four functions have an identical syntax: a value is expected followed by an angular unit (see CSS angle units). This value can be positive or negative.
rotate()
is equivalent torotateZ()
.
X-axis rotation
Y-axis rotation
Z-axis rotation
Syntaxe de la fonction rotate3d()
.
- transform: rotate3d(1, 0, 0, 45deg); x y z a
x
,y
, andz
are three unitless values. They define the axis of rotation.
For rotation around theX
axis:rotate3d(1,0,0,a)
Around the Y-axis:
rotate3d(0,1,0,a)
And around theZ
axis:rotate3d(0,0,1,a)
But all combinations and intermediate values are possible. The diagram below shows something likerotate(1, 0.25, 0.4, a)
a
is a positive, negative, or zero numeric value, followed by a unit of angle (see CSS angle units). This value of course defines the angle of rotation about the axis defined by the first three values.Rotation along a combination of the three axes.
transform:perspective(50px) rotate(5, 7, 1, 20deg);
Simulator.
Note: The simulator also uses the perspective()
function to make rotations easier to visualize.
Browser compatibility and support.
2D or 3D transformations are perfectly handled by all current browsers.
the backface-visibility
property.rotateX()
function used with the transform
property to define a rotation around the X-axis.rotateY()
function used with the transform
property to define a rotation around the y-axis.rotateZ()
function used with the transform
property to define a rotation around the Z-axis.rotate3d()
function used with the transform
property, to set a rotation around any axis.Notes:
(1) Does not support 2D transformations on SVG elements. Use the transform
attribute instead.
(2) Internet Explorer does not support transform-style:preserve-3d
, thus limiting the nesting of animations.
transformations
transformations
rotateX()
function
rotateY()
function
rotateZ()
function
rotate3D()
function
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Opéra

Firefox pour Androïd

Samsung Internet

Chrome

Edge

Firefox

Androïd Brower

Chrome pour Androïd

Baidu Browser

QQ Browser

Safari

Safari sur IOS

UC Browser pour Androïd

Opéra mini
Historic of rotation functions.
-
CSS Transforms Module Level 1
First level of specification concerning 2D transformations.
Presentation of different transformation functions such asrotate()
.February 28, 2012Working Draft.February 14, 2019Candidate Recommendation. -
CSS Transforms Module Level 2
The level 2 of the Transforms specification introduces 3D transformations.
Adding new rotation functions:rotateX()
,rotateY()
,rotateZ()
androtate3d()
.
No change directly affecting therotate()
function.March 03, 2020Working Draft.
See also, concerning transformations.
The CSS Transforms Module includes all the properties and functions related to CSS transformations:
Properties:





Functions:

