CSS Portal

rotateZ() CSS Function

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The rotateZ() CSS function is used to apply a 2D rotation to an element around its Z-axis, which is perpendicular to the screen. This function is part of the transform family of functions, allowing elements to be rotated, scaled, skewed, or translated. When you use rotateZ(), the element rotates in a clockwise or counterclockwise direction based on the angle value provided, typically in degrees (deg) or radians (rad). Positive values rotate the element clockwise, while negative values rotate it counterclockwise.

One of the main advantages of rotateZ() is its ability to combine with other transform functions like rotateX() and rotateY() for 3D effects, or with scale() and translate() for more complex transformations. It's commonly used for animations, hover effects, and interactive UI elements.

For example, you could rotate a div element 45 degrees around its center:

div {
  transform: rotateZ(45deg);
  transition: transform 0.5s ease;
}

This would smoothly rotate the element when the transform property changes, such as on hover:

div:hover {
  transform: rotateZ(-45deg);
}

Using rotateZ() is particularly useful for 2D rotations without affecting the perspective or depth of an element, making it simpler than full 3D rotations when you only need planar movement.

Syntax

transform: rotateZ(<angle>);

Values

  • <angle>A positive value rotates the element clockwise, a negative value rotates the element counter clockwise.

Example

<div class="container">
<div class="rotated-box">RotateZ(45deg)</div>
</div>
/* The box we are rotating */
.rotated-box {
width: 150px;
height: 150px;
background-color: #3498db;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
border: 2px solid #2980b9;

/* The rotation logic */
transform: rotateZ(45deg);
}

/* Optional: Centering the box on the page */
.container {
display: flex;
justify-content: center;
align-items: center;
height: 300px;
}

Browser Support

The following information will show you the current browser support for the CSS rotateZ() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!