🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #135

3D Perspective


CSS Perspective

To activate a 3D space, the element needs perspective. The perspective defines the distance between the user's viewpoint and the object.

A small value, like perspective: 200px;, assumes that the user is close to the object and creates a strong 3D effect.

A large value, like perspective: 2000px;, assumes that the user is far away from the object and creates a mild 3D effect.

Without perspective, any 3D transforms will look flat and two-dimensional.

A perspective can be added in two ways:

  • With the perspective property
  • With the perspective() function

Using the perspective Property

The perspective property is set on the parent element, and each child will share the same 3D space.

Example

  .container {
  width: 180px;
  height: 180px;
  border:
  1px solid lightgray;
  margin: 30px;
  perspective: 500px; /*
  set perspective on parent element */

  }

.box {
  width:
  100%;
  height: 100%;
  background-color: green;

  transform: rotateY(45deg);
}

Using the perspective() Function

The perspective() function is used to directly apply a 3D transform to a single element:

Example

  .container {
  width: 180px;
  height: 180px;
  border:
  1px solid lightgray;
  margin: 30px;
}

.box {
  width:
  100%;
  height: 100%;
  background-color: green;

  /* perspective function in transform property */

  transform: perspective(500px) rotateY(45deg);
}

Both of the examples above produce the same result.

However: When you put the perspective property on a parent element, each child will share the same 3D space, while the perspective() function is used to directly apply a 3D transform to a single element.


CSS Transform Properties

The following table lists all the 3D transform properties:

Property Description
transform Applies a 2D or 3D transformation to an element
transform-origin Allows you to change the position on transformed elements
transform-style Specifies how nested elements are rendered in 3D space
perspective Specifies the perspective on how 3D elements are viewed
perspective-origin Specifies the bottom position of 3D elements
backface-visibility Defines whether or not an element should be visible when not facing the screen

CSS 3D Transform Functions

Function Description
matrix3d() Defines a 3D transformation, using a 4x4 matrix of 16 values
translate3d() Defines a 3D translation
translateZ() Defines a 3D translation, using only the value for the Z-axis
scale3d() Defines a 3D scale transformation
scaleZ() Defines a 3D scale transformation by giving a value for the Z-axis
rotate3d() Defines a 3D rotation
rotateX() Defines a 3D rotation along the X-axis
rotateY() Defines a 3D rotation along the Y-axis
rotateZ() Defines a 3D rotation along the Z-axis
perspective() Defines a perspective view for a 3D transformed element

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

3D Perspective – FAQs

Quick answers about learning 3D Perspective in CSS.

This free note from CodingNow 2.0 explains 3D Perspective in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including 3D Perspective, is 100% free with no signup required.
With focused practice, most students grasp 3D Perspective in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now