CSS perspective Property

The CSS perspective property determines the distance between the viewer and the z=0 plane, creating a sense of depth when child elements use 3D transformations.

Smaller perspective distances produce a stronger 3D effect, while larger distances produce a more subtle effect. The property is applied to a parent element and affects the 3D appearance of its transformed children.

perspective Syntax

The perspective property accepts the keyword none, a non-negative length, or a CSS-wide keyword.

Basic Syntax

selector {
  perspective: 600px;
}

This establishes a perspective distance of 600 pixels for the element's transformed children.

Default Value

selector {
  perspective: none;
}

The none value disables perspective projection from this property.

Length Values

.scene {
  perspective: 300px;
}
.scene {
  perspective: 600px;
}
.scene {
  perspective: 1000px;
}
.scene {
  perspective: 50rem;
}

Perspective distances can use CSS length units such as px, em, rem, and other supported length units.

CSS-Wide Keywords

.scene {
  perspective: initial;
}
.scene {
  perspective: inherit;
}
.scene {
  perspective: unset;
}
.scene {
  perspective: revert;
}
.scene {
  perspective: revert-layer;
}

CSS-wide keywords control how the property's value is initialized, inherited, or resolved through the cascade.

Property Values

Value Description
none Specifies no perspective projection for the element's children.
<length> Specifies the distance between the viewer and the z=0 plane. Negative lengths are invalid.
initial Resets the property to its initial value of none.
inherit Uses the computed value from the parent element.
unset Resets the property to none because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value none
Inherited No
Applies to Transformable elements
Computed value Absolute length or none
Animation type By computed value type
Percentages Not applicable
Default perspective origin 50% 50%
Primary use 3D CSS transformations

Valid Values

.scene {
  perspective: none;
}
.scene {
  perspective: 400px;
}
.scene {
  perspective: 75rem;
}
.scene {
  perspective: 0;
}
.scene {
  perspective: calc(500px + 10vw);
}

A zero perspective distance is syntactically valid, but the effective projection distance is clamped to a small positive value during rendering. Extremely small distances can produce exaggerated distortion.

Invalid Values

.scene {
  perspective: -500px;
}
.scene {
  perspective: 50%;
}
.scene {
  perspective: auto;
}
.scene {
  perspective: 600;
}

Negative lengths, percentages, auto, and nonzero unitless numbers are invalid values.

How It Works

The perspective property creates a viewing perspective for child elements that undergo 3D transformations. It makes objects closer to the viewer appear larger and objects farther away appear smaller.

Creating a Perspective Container

.scene {
  perspective: 600px;
}
.card {
  transform: rotateY(45deg);
}

When the card is inside the scene, the rotation appears three-dimensional because the parent establishes a perspective projection.

The Viewer and the Z-Axis

In CSS 3D space, the z-axis extends perpendicular to the screen. Positive z-values move an element toward the viewer, while negative z-values move it farther away.

.near-card {
  transform: translateZ(80px);
}
.far-card {
  transform: translateZ(-80px);
}

When viewed through a perspective container, the nearer card appears larger and the farther card appears smaller.

Perspective Does Not Rotate Elements

.scene {
  perspective: 600px;
}

Setting perspective alone does not visibly rotate or reposition child elements. A 3D transformation is needed to reveal the depth effect.

Perspective and Child Elements

The property establishes a perspective for transformed children rather than applying a 3D transformation directly to the parent itself.

Perspective and Stacking Contexts

A value other than none creates a stacking context. It also establishes a containing block for absolutely positioned and fixed-position descendants.

Understanding Perspective Distance

The perspective distance controls how strongly depth affects the appearance of transformed elements.

Short Perspective Distance

.scene {
  perspective: 200px;
}

A short distance produces a pronounced 3D effect. Rotated elements can appear strongly distorted because the viewer is positioned close to the projection plane.

Medium Perspective Distance

.scene {
  perspective: 600px;
}

A medium distance produces a balanced effect that is often suitable for rotating cards and interface panels.

Long Perspective Distance

.scene {
  perspective: 1500px;
}

A long distance creates a subtler effect. The transformed element appears closer to a flat, orthographic view.

Comparing Perspective Distances

Distance Visual Effect
200px Strong perspective distortion
500px Noticeable depth
800px Moderate depth
1500px Subtle perspective distortion
none No perspective projection from this property

Choosing a Distance

There is no single ideal perspective distance. Choose a value based on the size of the transformed element, the amount of rotation, and the intended visual effect.

Important Consideration

Very small perspective distances can produce extreme distortion or clipping when elements move close to the viewer.

Using perspective With 3D Transforms

The perspective property is commonly combined with 3D transform functions such as rotateX(), rotateY(), and translateZ().

Rotating Around the X-Axis

.scene {
  perspective: 600px;
}
.card {
  transform: rotateX(45deg);
}

The card tilts around its horizontal axis, with perspective making the near and far edges appear at different scales.

Rotating Around the Y-Axis

.scene {
  perspective: 600px;
}
.card {
  transform: rotateY(45deg);
}

The card rotates around its vertical axis, creating a door-like effect.

Moving Along the Z-Axis

.scene {
  perspective: 600px;
}
.card {
  transform: translateZ(100px);
}

The card moves toward the viewer and appears larger through the perspective projection.

Combining Transformations

.scene {
  perspective: 800px;
}
.card {
  transform: rotateY(35deg) translateZ(40px);
}

The card is rotated and translated in 3D space. Transform functions are applied according to their specified order, so changing that order can change the result.

Using transform-origin

.card {
  transform-origin: left center;
  transform: rotateY(50deg);
}

The transform-origin property changes the point around which the card rotates. It is different from perspective-origin, which controls the viewpoint of the perspective projection.

Perspective and perspective-origin

The perspective-origin property controls the position from which the viewer appears to observe the 3D scene.

Centered Perspective

.scene {
  perspective: 600px;
  perspective-origin: center center;
}

The viewpoint is centered on the perspective container.

Perspective From the Left

.scene {
  perspective: 600px;
  perspective-origin: left center;
}

The viewpoint shifts toward the left side of the container.

Perspective From the Top

.scene {
  perspective: 600px;
  perspective-origin: center top;
}

The viewpoint shifts toward the top of the container.

Percentage Values

.scene {
  perspective: 600px;
  perspective-origin: 25% 75%;
}

Percentage values position the viewpoint relative to the dimensions of the perspective container.

Difference Between the Properties

Property Purpose
perspective Sets the distance between the viewer and the projection plane.
perspective-origin Sets the position of the perspective viewpoint.
transform-origin Sets the origin around which an element is transformed.

These properties can be combined to control both the viewing position and the rotation of a transformed element.

perspective Property vs. perspective() Function

The perspective property and the perspective() transform function both introduce perspective, but they are applied differently.

Using the Property

.scene {
  perspective: 600px;
}
.card {
  transform: rotateY(45deg);
}

The parent establishes a shared perspective for its transformed children.

Using the Function

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

The perspective() function becomes part of the element's own transformation.

Key Differences

Feature perspective Property perspective() Function
Applied to Parent or perspective container Element being transformed
Effect Establishes perspective for child elements Adds perspective to the element's transform list
Viewpoint control Uses perspective-origin Controlled through the transform composition
Typical use Multiple elements sharing a 3D scene Individual transformed elements

Transform Order Matters

.card-one {
  transform: perspective(600px) rotateY(45deg);
}
.card-two {
  transform: rotateY(45deg) perspective(600px);
}

These declarations can produce different results because transform functions are composed in the specified order.

Choosing an Approach

Use the perspective property when multiple child elements should share a common viewpoint. Use perspective() when perspective belongs to an individual transform.

Perspective and transform-style

The transform-style property determines whether an element's children are rendered in a shared 3D space or flattened into the element's plane.

Preserving 3D Space

.scene {
  perspective: 800px;
}
.card-group {
  transform-style: preserve-3d;
}
.card-face {
  transform: translateZ(40px);
}

The preserve-3d value allows descendants to retain their 3D positions within the transformed group.

Default Flattening

.card-group {
  transform-style: flat;
}

The default flat value causes descendants to be flattened into the element's plane.

Creating a Two-Sided Card

.scene {
  perspective: 800px;
}
.card {
  position: relative;
  transform-style: preserve-3d;
}
.card-front,
.card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}
.card-back {
  transform: rotateY(180deg);
}

This structure can be used for a two-sided card. Rotating the card itself can reveal its back face.

Properties That Cause Flattening

Some CSS properties, including certain overflow, opacity, and filtering values, can require descendants to be flattened even when transform-style: preserve-3d is specified.

Important Consideration

The perspective property establishes the viewpoint, while transform-style controls whether nested descendants preserve their three-dimensional arrangement.

perspective Example

The following example compares three perspective distances using cards rotated by the same amount.

HTML Example

<div class="perspective-demo">
  <div class="perspective-item">
    <h3>Strong Perspective</h3>
    <div class="perspective-scene perspective-small">
      <div class="perspective-card">200px</div>
    </div>
  </div>
  <div class="perspective-item">
    <h3>Medium Perspective</h3>
    <div class="perspective-scene perspective-medium">
      <div class="perspective-card">600px</div>
    </div>
  </div>
  <div class="perspective-item">
    <h3>Subtle Perspective</h3>
    <div class="perspective-scene perspective-large">
      <div class="perspective-card">1500px</div>
    </div>
  </div>
</div>

CSS Example

.perspective-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
.perspective-item {
  flex: 1 1 180px;
  text-align: center;
}
.perspective-scene {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  overflow: visible;
}
.perspective-card {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 100px;
  background-color: #2563eb;
  color: #ffffff;
  font-weight: 700;
  border: 2px solid #1e40af;
  transform: rotateY(45deg);
}
.perspective-small {
  perspective: 200px;
}
.perspective-medium {
  perspective: 600px;
}
.perspective-large {
  perspective: 1500px;
}
Browser Result

Strong Perspective

200px

Medium Perspective

600px

Subtle Perspective

1500px

All three cards use rotateY(45deg). The difference in appearance comes from the perspective distance assigned to each parent container.

Expected Behavior

Perspective Result
200px Strong distortion between the near and far edges.
600px Moderate distortion with visible depth.
1500px Subtle distortion with a flatter appearance.

Practical Card Rotation

.card-container {
  perspective: 800px;
}
.card {
  transition: transform 0.4s ease;
}
.card-container:hover .card {
  transform: rotateY(15deg);
}
@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }
}

This creates a small 3D rotation on hover. The reduced-motion rule removes the transition for users who request less animation.

Accessibility Considerations

Perspective effects can improve visual presentation, but strong 3D transformations and animation may make content difficult to read or uncomfortable for some users.

Respect Reduced-Motion Preferences

@media (prefers-reduced-motion: reduce) {
  .animated-card {
    animation: none;
    transition: none;
  }
}

Use the prefers-reduced-motion media feature to reduce or remove unnecessary motion effects.

Maintain Text Readability

Avoid extreme rotations that make text difficult to read. Important information should remain legible without requiring users to interpret heavily distorted content.

Preserve Keyboard Access

Interactive elements inside transformed containers should remain reachable by keyboard. Do not rely on hover alone to reveal essential controls.

Avoid Hiding Important Content

3D transformations can move content outside its visible container or turn it away from the viewer. Ensure important information remains accessible.

Provide Non-Animated Alternatives

For complex 3D interfaces, consider providing a simpler presentation that does not depend on animated perspective effects.

Important Consideration

Perspective changes visual rendering but does not change the semantic structure or reading order of HTML content.

Common Mistakes

Applying perspective to the Wrong Element

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

The perspective property affects the element's transformed children, not its own transform. Apply it to a parent container when the card itself needs perspective.

Forgetting the 3D Transform

.scene {
  perspective: 600px;
}

Perspective alone usually produces no visible effect. A child needs a suitable 3D transformation to reveal the depth.

Using a Negative Distance

.scene {
  perspective: -600px;
}

Negative perspective distances are invalid.

Using Percentages

.scene {
  perspective: 50%;
}

The property accepts lengths, not percentages.

Using auto

.scene {
  perspective: auto;
}

The auto keyword is invalid. Use none to disable perspective.

Using a Unitless Number

.scene {
  perspective: 600;
}

Nonzero perspective distances require a valid CSS length unit.

Confusing perspective With perspective()

The property establishes a perspective for child elements, while the perspective() function is included in an element's own transform list.

Confusing perspective-origin With transform-origin

perspective-origin controls the viewpoint. transform-origin controls the point around which an element transforms.

Using Excessively Small Distances

Very small distances can produce extreme distortion, clipping, or difficult-to-read content.

Ignoring Nested 3D Flattening

Nested elements may need transform-style: preserve-3d to maintain their three-dimensional arrangement.

Ignoring Reduced-Motion Preferences

Animated 3D effects should account for users who prefer reduced motion.

Important Considerations

Keep the following points in mind when using perspective:

  • It establishes a perspective projection for transformed child elements.
  • Its initial value is none.
  • The property is not inherited.
  • It accepts none or a non-negative CSS length.
  • Negative perspective distances are invalid.
  • Percentages are not accepted.
  • Nonzero numeric values require a length unit.
  • Smaller distances produce stronger perspective effects.
  • Larger distances produce subtler perspective effects.
  • Very small distances can cause exaggerated distortion.
  • Perspective alone does not rotate or translate child elements.
  • A suitable 3D transformation is needed to reveal the depth effect.
  • The property is generally applied to a parent container.
  • The perspective() function is applied within an element's transform list.
  • The property and function are not interchangeable in every layout.
  • The default perspective-origin value is 50% 50%.
  • The perspective-origin property controls the viewpoint position.
  • The transform-origin property controls the transformation origin.
  • Positive z-axis translations move elements toward the viewer.
  • Negative z-axis translations move elements farther from the viewer.
  • A non-none perspective creates a stacking context.
  • It establishes a containing block for absolutely positioned and fixed-position descendants.
  • The transform-style: preserve-3d declaration can be necessary for nested 3D scenes.
  • Some CSS properties can force nested 3D content to flatten.
  • Transform function order can affect the final visual result.
  • Strong perspective effects can reduce text readability.
  • Animated perspective effects should respect reduced-motion preferences.
  • Perspective changes visual presentation without changing HTML reading order.

Browser Support

The CSS perspective property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari.

Support for CSS 3D transformations is well established. Complex nested 3D scenes, flattening behavior, and rendering details may vary between browsers, so advanced effects should be tested in the intended environments.

For current compatibility information, visit Can I Use? and search for perspective.

Specifications

The perspective property is defined in CSS Transforms Module Level 2.

CSS Transforms Module Level 2

The specification defines perspective projection, perspective distance, and how perspective interacts with three-dimensional transformations.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: perspective