Course contentsShow
← Web Development
Lesson 537 of 2,9829. CSS Transitions and AnimationsFree lesson

Perspective and Perspective-Origin

Creating depth with the perspective property and controlling the vanishing point with perspective-origin.

Perspective and Perspective-Origin

What you'll learn: How to create realistic 3D depth in your CSS transforms and control where the viewer appears to be looking from.


When you apply 3D transforms like rotateX() or translateZ(), elements can move in 3D space, but without perspective, they'll look flat and unnatural. Think of perspective like the difference between looking at a photograph (no depth) versus looking through a window at the real world (with depth).

The perspective Property

The perspective property defines how far away the viewer is from the 3D scene. Lower values (like 200px) create dramatic, exaggerated depth—like standing very close to something. Higher values (like 2000px) create subtle depth—like viewing from far away.

.container {
  perspective: 600px; /* Apply to parent element */
}

.box {
  transform: rotateY(45deg);
  /* Now the rotation appears 3D with depth */
}

Important: Apply perspective to the parent element, not the element being transformed.

The perspective-origin Property

While perspective controls distance, perspective-origin controls where you're looking from. It sets the vanishing point—the spot toward which parallel lines converge in 3D space.

The default is 50% 50% (center), but you can position it anywhere:

.container {
  perspective: 600px;
  perspective-origin: left top;
  /* Now you're viewing from the upper-left corner */
}

Values can be keywords (left, center, right, top, bottom) or precise measurements (100px 200px).

Imagine rotating a door: with perspective-origin: left center, it feels like you're standing on the left side watching it swing away from you.

Key Takeaway: Use perspective on the parent to create 3D depth, and adjust perspective-origin to control the viewer's position relative to the scene—together they make 3D transforms look realistic and grounded in space.