The CSS translateZ() perform provides depth to a component, drawing it nearer or farther in area. In different phrases, it shifts a component alongside the Z-axis in a 3D area.
.field:hover {
remodel: translateZ(100px);
}
.field.perspective:hover {
remodel: perspective(500px) translateZ(100px);
}
Both the perspective() perform or perspective property is critical for translateZ() to work. With out both one, there’s no impact.
Activate the swap within the following demo, then hover over the field to see it seem nearer:
Whereas it seems just like the .field component is getting greater” on hover, that’s not what is occurring. While you hover over the field, it truly strikes nearer to you a size of 100 pixels, making it seem bigger. We’ll get extra into that in only a bit so it’s extra apparent what’s taking place there.
translateZ() shouldn’t be mistaken for a substitute for the scale() perform or scale property. Perspective and scale are two completely different ideas.
The translateZ() perform is outlined within the CSS Rework Module Stage 2 specification
Syntax
translateZ() = translateZ()
The translateZ() perform takes a single argument that defines how far the component is from the entrance of the display screen. It’s used with the remodel property
Arguments
/* Optimistic lengths */
remodel: translateZ(100px);
remodel: translateZ(5rem);
/* Unfavorable lengths */
remodel: translateZ(-50px);
remodel: translateZ(-8em);
The translateZ() perform takes a single argument:
: the space of the component from the entrance of the display screen. When it’s optimistic, the component strikes nearer to the person, and additional away when it’s unfavourable.
The way it works
The translateZ() perform is hard as a result of it strikes a component alongside the Z-axis, which isn’t visually perceptible in a browser by default. Since browsers solely render components by their peak and width, not their depth, the translateZ() perform might seem to do nothing.

To point out its depth and projection, we have to use both the perspective property or perspective() perform. Moreover, we are able to set transform-style to preserve-3d worth on its mother or father, which lets CSS know that baby components ought to be positioned in 3D.
Projection and perspective
On a web site, there isn’t a way of depth — that’s, “closeness” or “furtherness” — since components are flattened on a 2D display screen. Whether or not it’s translate(200px) or translate(20px), we understand the component on the similar distance, so there isn’t any perspective in any respect except we explicitly allow it. To point out that, take for instance the next HTML:
Firstly, we’ll allow some perspective in the entire scene:
.scene {
perspective: 800px;
}
Then, we’ll set transform-style to preserve-3d within the mother or father, so youngsters may even be reworked in 3D:
.mother or father {
transform-style: preserve-3d;
}
Now we transfer the .field 100px nearer to the person utilizing translateZ().
.field {
remodel: translateZ(100px);
}
Though it seems just like the field grew 100px in measurement, if you rotate the mother or father to the aspect, you’ll see that the .field measurement didn’t improve, nevertheless it’s the space between the .mother or father and the .field that did.

perspective vs. perspective()
Each do the identical work: outline the component’s projection. The perspective property is utilized to the mother or father for all 3D components, whereas the perspective() perform can solely be utilized to a single 3D component, and have to be declared earlier than the 3D remodel perform.
The perspective property
.mother or father {
perspective: 800px;
}
.child-1 {
remodel: translateZ(200px); /* Outlined inside a projection of 800px */
}
.child-2 {
remodel: translate3D(100px, 200px, 150px); /* Outlined inside a projection of 800px */
}
The perspective() perform
.component {
remodel: translateZ(100px) perspective(800px); /* Nope ❌ */
}
.component {
remodel: perspective(800px) translateZ(100px); /* Yep ✅ */
}
It can be used to optimize internet efficiency
Do you know that you need to use the translateZ() perform to spice up our web site’s efficiency? CSS 3D remodel features use the GPU, which is quicker and extra superior to the CPU for component rendering. This efficiency hack prevents flickering throughout animations and makes transitions smoother.
Builders add translateZ(0) to shift rendering from the CPU to the GPU, bettering efficiency. In case you’re combating a glitching animation, now you’ve s method to repair it!
Demo
Specification
The translateZ() perform is outlined within the CSS Rework Module Stage 2 specification.
Browser assist
The translateZ() perform is obtainable on all fashionable browsers.





![How creators and entrepreneurs are utilizing AI to hurry up & succeed [data]](https://blog.aimactgrow.com/wp-content/uploads/2025/06/Untitled20design-Apr-07-2023-08-24-35-4586-PM-120x86.png)


