1. css
  2. /properties
  3. /perspective-origin

perspective-origin

Definition

The perspective-origin property is a CSS property that defines the point at which the viewer appears to be looking at a 3D transformed element. It is used in conjunction with the perspective property to create a 3D space in which an element is transformed. The perspective-origin property allows you to set the position of the vanishing point, which affects the perceived depth and distortion of the transformed element.

Examples

Set the vanishing point at the center of an element:

.box {
  perspective: 500px;
  perspective-origin: 50% 50%;
}

Set the vanishing point at the top left corner of an element:

.box {
  perspective: 500px;
  perspective-origin: 0% 0%;
}

Set the vanishing point at a specific pixel value:

.box {
  perspective: 500px;
  perspective-origin: 200px 100px;
}

Values

ValueDescription
x-axisSpecifies the horizontal position of the vanishing point. Can be a percentage value, a length value, or the keyword left, center, or right.
y-axisSpecifies the vertical position of the vanishing point. Can be a percentage value, a length value, or the keyword top, center, or bottom.
initialSets the property to its default value (50% 50%).
inheritInherits the property from its parent element.

Best Practices

  • Use this property in conjunction with the perspective property to create a 3D effect that accurately represents the intended depth and distortion of the transformed element.
  • Experiment with different values for the perspective-origin property to achieve the desired visual effect. Small changes in the vanishing point position can have a significant impact on the perceived depth and distortion of the transformed element.
  • Keep in mind that the perspective-origin property only affects elements that are transformed using the transform property with 3D transformation functions.
  • Test your content on different devices and in different browsers to ensure that it renders correctly and looks good across a variety of contexts.
  • Consider using 3D graphics libraries or frameworks, such as Three.js or Babylon.js, to create more complex and sophisticated 3D effects.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesYesYesYes