Favorites

perspective() CSS Function

perspective()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The perspective() transform function gives 3D transforms depth by setting the distance between the viewer and the z = 0 plane.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The perspective() CSS function is a transform function that applies a 3D perspective to the element it is used on. It sets the distance between the viewer and the plane where the element sits (z = 0), so that parts of the element that are rotated or moved toward the viewer look larger, and parts moved away look smaller. It is used inside the transform property, together with 3D transform functions such as rotateX(), rotateY() and translateZ().

The argument is a length, such as 500px. A smaller value means the viewer is closer, which gives a stronger, more dramatic 3D effect; a larger value gives a subtler effect. The keyword none, or a value of 0, means no perspective is applied. Because transform functions are applied from left to right, perspective() must come before the functions it should affect, for example transform: perspective(600px) rotateY(30deg).

The perspective() function is different from the perspective property. The function only affects the element it is applied to, and each element gets its own vanishing point. The property is set on a parent and gives all of its 3D-transformed children a shared vanishing point, which looks more natural for groups of elements such as a 3D carousel. The vanishing point used by the property can be moved with perspective-origin.

/* Perspective applied to a single element */
.card {
  transform: perspective(600px) rotateY(25deg);
}

/* Equivalent effect for a group: set the property on the parent */
.scene {
  perspective: 600px;
}

.scene .card {
  transform: rotateY(25deg);
}

Interactive Demo

Transform
Demo Code
HTML Code
<div class="demo-area">
	<div class="demo-ghost"></div>
	<div class="demo-element">Transform</div>
</div>
CSS Code
.demo-area {
	position: relative;
	width: 300px;
	height: 190px;
	background: #f4f4f4;
	outline: 1px dashed #b0b0b0;
}
.demo-ghost, .demo-element {
	position: absolute;
	left: 100px;
	top: 55px;
	width: 100px;
	height: 80px;
	box-sizing: border-box;
}
.demo-ghost {
	border: 2px dashed #b0b0b0;
}
.demo-element {
	padding: 8px;
	background: rgb(247 37 133 / 85%);
	color: #fff;
	font-size: 14px;
	transform: perspective(none) rotateY(50deg);
}

Syntax

perspective() = perspective( [ <length [0,∞]> | none ] )

Values

  • sizeIs a <length> representing the distance from the user to the z=0 plane. If it is 0 or a negative value, no perspective transform is applied.

Example

<div class="container">
<div class="cube">3D Card</div>
</div>
/* The parent container centers the item */
.container {
width: 100%;
height: 300px;
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
}

/* The element being transformed */
.cube {
width: 150px;
height: 150px;
background-color: #3498db;
color: white;
display: flex;
justify-content: center;
align-items: center;
font-weight: bold;
border-radius: 8px;
box-shadow: 0 10px 20px rgba(0,0,0,0.2);

/* 1. Establish perspective (distance from viewer)
2. Rotate the element to see the depth
*/
transform: perspective(500px) rotateY(45deg);

/* Smooth transition for hovering */
transition: transform 0.5s ease;
}

/* Change the rotation on hover to see the 3D effect in motion */
.cube:hover {
transform: perspective(500px) rotateY(-20deg) rotateX(20deg);
background-color: #2980b9;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS perspective() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.