Favorites

rotateZ() CSS Function

rotateZ()
CSS FunctionThis function is supported by all modern browsers.
Updated 1st January 2026

The rotateZ() transform function rotates an element around the Z axis, which points out of the screen. It looks the same as rotate().

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

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.

Interactive Demo

Transform
Demo Code
HTML Code
<div class="demo-area">
	<div class="demo-ghost"></div>
	<div class="demo-element">Transform</div>
</div>
CSS Code
.demo-area {
	position: relative;
	width: 300px;
	height: 190px;
	background: #f4f4f4;
	outline: 1px dashed #b0b0b0;
}
.demo-ghost, .demo-element {
	position: absolute;
	left: 100px;
	top: 55px;
	width: 100px;
	height: 80px;
	box-sizing: border-box;
}
.demo-ghost {
	border: 2px dashed #b0b0b0;
}
.demo-element {
	padding: 8px;
	background: rgb(247 37 133 / 85%);
	color: #fff;
	font-size: 14px;
	transform: rotateZ(0);
}

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;
}
Open in editor

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
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.