CSS
HTML
COMPONENTS
CODE HUB
CSS Perspective Generator
Configuration
Length
Rotate X
Rotate Y
Preview
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Code
Copy this to the parent element.
Copy this to the child element.
ReadyTools Academy
Learn HTML, CSS, and JavaScript for free with the ReadyTools Academy.
Track your learning, grow at your own pace, and enjoy the journey! 🎯
Get StartedCSS Perspective Generator
In CSS, the perspective property is used in combination with 3D transformations to control the depth of perspective for elements. It defines how much perspective or depth should be applied to a 3D-transformed element, giving it a sense of depth and distance.
The perspective property takes a length value, typically measured in pixels or other length units, to define the depth of the perspective. The greater the value, the more pronounced the perspective effect will be. Smaller values result in a less noticeable perspective.
Here's the basic syntax for using the perspective property:
.perspective-element {
perspective: 1000px;
}
In this example:
- The .perspective-element class sets the perspective for the 3D-transformed element to 1000 pixels. This value defines the depth of the perspective.
You would typically use the perspective property in conjunction with 3D transformation functions such as rotateX(), rotateY(), and translateZ() to create 3D effects on elements, making them appear closer or farther away from the viewer.
Here's a simple example of how to use perspective with a 3D-transformed element:
.perspective-element {
perspective: 1000px;
transform: rotateY(30deg) translateZ(50px);
}
In this case, the element has a perspective of 1000 pixels, and it's rotated on the Y-axis and translated on the Z-axis to create a 3D effect.
The perspective property is particularly useful for creating 3D transformations and animations in web design and user interfaces, giving elements a realistic sense of depth and spatial positioning.