Web Development

Mastering CSS rotateY(): A Complete Guide to 3D Horizontal Rotation

2026-05-19 09:32:46

What is rotateY()?

The CSS rotateY() function spins an element around its vertical (y) axis, creating a horizontal flip effect. Imagine a playing card pivoting left or right on a central vertical line—that's the motion this transform produces. It belongs to the transform property's family of 3D functions and is defined in the CSS Transforms Module Level 2 specification.

Mastering CSS rotateY(): A Complete Guide to 3D Horizontal Rotation
Source: css-tricks.com

To visualize, picture a pin stuck through the top and bottom of an element, allowing only horizontal rotation. Positive angles rotate the right edge away from you (turning the element to the right), while negative angles rotate the left edge away (turning left).

.demo-element {
  transform: rotateY(var(--deg));
  transition: transform 0.3s ease;
}

Syntax and Angle Units

The rotateY() function accepts a single angle argument:

rotateY( <angle> )

You can express the angle using four different units:

Here are some practical examples:

Understanding the Angle Direction

When the angle is positive, the element's right side moves away from the viewer, giving a rightward tilt. A negative angle makes the left side recede, tilting left. This mimics the natural perspective of an object rotating on a vertical axis.

Setting Up Perspective for True 3D Effects

Without additional setup, rotateY() will appear flat—the element simply shrinks in width. To see true three‑dimensional depth, you must apply a perspective property to the parent element. The perspective defines the distance between the viewer and the object’s z‑plane.

Mastering CSS rotateY(): A Complete Guide to 3D Horizontal Rotation
Source: css-tricks.com
.parent {
  perspective: 1000px;
}

.card {
  transform: rotateY(45deg);
}

A lower value (e.g., 400px) makes the 3D effect more pronounced—the element appears closer and more sharply tilted. A higher value (e.g., 2000px) reduces the visual intensity, making the rotation look subtler.

Compare the difference: without perspective, the rotated element looks compressed and two‑dimensional. With perspective, it gracefully tilts right, revealing a sense of depth.

Practical Use Cases for rotateY()

Developers commonly use rotateY() to create:

Remember to combine rotateY() with transform-style: preserve-3d on child elements if they also need to maintain 3D positioning.

Browser Support and Accessibility

The rotateY() function works in all modern browsers. For older ones, consider a fallback like -webkit-transform: rotateY(). Because the function creates visual depth, keep motion preferences in mind: some users may experience dizziness with strong 3D transforms. Use the prefers-reduced-motion media query to offer a static or simplified alternative.

Explore

Microsoft Unleashes Agentic AI for R&D: Microsoft Discovery Expands Preview Access 10 Surprising Networking Decisions That Power OpenAI’s 131,000-GPU AI Training Beast VS Code Python Environments Extension: April 2026 Update - Faster, More Reliable, and Smarter Enterprise Microsite Sprawl Crisis: How Multi-Tenant CMS Architecture Rescues Digital Operations Demystifying AI: The Role of Diffusion Models in Drug Discovery