CSS Portal

rotateX() 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 rotateX() CSS function is used to apply a 3D rotation along the horizontal axis of an element. This transformation pivots the element around its x-axis, giving the impression that the element is tilting forwards or backwards in three-dimensional space. Positive values rotate the element clockwise when looking from the right-hand side, while negative values rotate it counterclockwise. The rotation is typically combined with other transformations using the transform property, which allows multiple functions such as rotateY() or translateZ() to work together.

When using rotateX(), it is important to consider the transform-style property. Setting it to preserve-3d ensures that child elements retain their 3D positioning, rather than flattening onto the plane of the parent element. Additionally, combining rotateX() with perspective on a parent container enhances the visual depth, making the rotation appear more realistic.

For example, applying a forward tilt to a card element could look like this in practice:

.card {
  transform: rotateX(30deg);
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

This will rotate the card along its horizontal axis by 30 degrees, and the smooth transition creates an interactive effect when combined with hover states.

rotateX() is especially useful for creating dynamic 3D interfaces, flipping cards, or simulating depth in UI components such as div containers. It pairs well with animations using the transition or animation properties to create visually engaging effects.

Syntax

transform: rotateX(<angle>);

Values

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

Example

<div class="container">
<div class="box">
ROTATE ME
</div>
</div>
/* The parent container provides the 3D viewport */
.container {
width: 200px;
height: 200px;
border: 1px dashed #ccc;
perspective: 500px; /* Gives depth to the rotation */
margin: 50px auto;
}

/* The element being rotated */
.box {
width: 100%;
height: 100%;
background-color: #3498db;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-family: sans-serif;

/* The Transformation */
transform: rotateX(45deg);

/* Smooth transition for hover effects */
transition: transform 0.5s ease;
}

/* Optional: Change rotation on hover */
.box:hover {
transform: rotateX(180deg);
background-color: #e74c3c;
}

Browser Support

The following information will show you the current browser support for the CSS rotateX() 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!