Web Development

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

2026-05-16 10:58:05

Introduction

The CSS rotateY() function lets you rotate an element around its vertical y‑axis, creating a horizontal flipping effect. It’s part of the transform property and is widely used to add depth and interactivity to web designs. Whether you’re building a 3D card flip or a subtle hover effect, understanding rotateY() is essential.

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

Imagine a pin stuck through the top center of an element: with rotateY(), the element can turn left or right as if it were a door swinging on its hinges. Positive values rotate the element to the right, negative values to the left.

.element {
  transform: rotateY(45deg);
  transition: transform 0.3s ease;
}

This function is defined in the CSS Transforms Module Level 2 specification.

Syntax

rotateY() = rotateY( [ <angle> | <zero> ] )

The function accepts a single argument of type <angle> (or the special value 0). This argument determines the rotation amount around the y‑axis.

Angle Units

The <angle> data type offers four units:

All units are interchangeable. For example, rotateY(180deg) and rotateY(0.5turn) produce the same visual result.

Rotation Direction

When the angle is positive, the element’s right edge moves away from the viewer, making it appear to rotate to the right. When negative, the left edge moves away, rotating the element to the left.

/* Examples */
rotateY(90deg);   /* rotates right */
rotateY(-180deg); /* rotates left */
rotateY(1.57rad); /* approximately 90deg right */
rotateY(1turn);   /* full rotation */

Creating 3D Depth with perspective

For rotateY() to produce a true three‑dimensional effect, you must set the perspective property on the parent element. perspective mimics the viewer’s distance from the element, defining the strength of the 3D projection.

Without perspective, the rotation looks flat and shrunk—like a 2D image simply compressing. With perspective, the element gains depth, appearing to tilt in space.

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

.child {
  transform: rotateY(60deg);
}

Values between 400px and 1200px work well for most designs. Lower values (e.g., 200px) exaggerate the depth, while higher values (e.g., 2000px) make the effect subtle.

Practical Examples

3D Card Flip

A common use case is a card that flips over when hovered. By combining rotateY() with backface-visibility: hidden, you can hide the back side while the front rotates away and the back comes into view.

.card {
  perspective: 1000px;
}

.card-inner {
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

.card:hover .card-inner {
  transform: rotateY(180deg);
}

.card-front, .card-back {
  backface-visibility: hidden;
}

.card-back {
  transform: rotateY(180deg);
}

Interactive Hover Effects

You can also apply a mild rotation on hover to add a playful tilt:

img {
  transition: transform 0.3s;
}

img:hover {
  transform: rotateY(10deg);
}

This works best when perspective is set on a parent container.

Browser Compatibility

The rotateY() function is supported in all modern browsers. For older versions (e.g., Internet Explorer 9 and below), you may need vendor prefixes like -webkit-transform and -ms-transform. Always test your implementation across target browsers.

Best Practices

With rotateY(), you can unlock a new dimension of interactivity and visual richness. Experiment with different angles and perspectives to achieve the perfect 3D effect for your project.

Explore

Anthropic Unveils Breakthrough Tool That Lets Anyone Read AI's Inner Thoughts in Plain English Thinking Machines Unveils Groundbreaking AI Interaction Models for Real-Time Voice and Video Mastering AI-Assisted Software Development: A Practical How-To Guide The Block Protocol: Making Web Blocks Universal and Reusable Solar-Battery Hybrid Project Gets Green Light Next to Standalone Battery in Wheatbelt Town