Favorites

translateZ() CSS Function

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

The translateZ() transform function moves an element towards or away from the viewer in 3D. It needs perspective to have a visible effect.

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 translateZ() CSS function is a 3D transformation function that moves an element along the z-axis, which is perpendicular to the screen. Unlike 2D transformations like translateX() or translateY(), translateZ() creates the illusion of depth by shifting elements closer to or farther from the viewer. Positive values move the element toward the user, while negative values move it away from the user.

This function is often used in combination with the transform property and can enhance visual effects in 3D layouts, such as card flips, rotating cubes, or parallax scrolling. Using translateZ() effectively usually requires a parent element with perspective applied to give the movement along the z-axis a realistic depth appearance.

For example, consider a 3D card effect:

<div class="card-container">
  <div class="card">Front</div>
</div>
.card-container {
  perspective: 800px;
}

.card {
  width: 200px;
  height: 300px;
  background-color: #4caf50;
  transform: translateZ(50px);
  transition: transform 0.5s;
}

In this example, the card appears closer to the viewer by 50 pixels along the z-axis. Adjusting the value of translateZ() can create dramatic depth effects when combined with rotations using rotateY() or rotateX().

Because translateZ() only affects the visual position in 3D space, it does not change the element's layout in the document flow, similar to how transform works in general.

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-area {
	perspective: 500px;
}
.demo-element {
	padding: 8px;
	background: rgb(247 37 133 / 85%);
	color: #fff;
	font-size: 14px;
	transform: translateZ(0);
}

Syntax

transform: translateZ(tz);

Values

  • tzA <length> representing the z-component of the translating vector. A positive value moves the element towards the viewer, and a negative value farther away.
Any length units accepted in CSS are accepted as values - for example, pixels (px), inches (in), points (pt), etc. A positive value shifts forward, a negative one backwards. A value of 0 does not change the position of the element.

Example

<div class="scene">
<div class="box">
<p>Hover Me</p>
</div>
</div>
/* 1. The Container: Creates the 3D space */
.scene {
width: 200px;
height: 200px;
margin: 100px auto;
perspective: 600px; /* Essential: Defines how far the viewer is from the Z=0 plane */
}

/* 2. The Element: The object moving in 3D space */
.box {
width: 100%;
height: 100%;
background-color: #3498db;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
border-radius: 10px;
transition: transform 0.5s ease; /* Smooths the movement */
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

/* 3. The Action: Moving the box closer to the viewer */
.scene:hover .box {
/* Positive Z moves the element "closer" to your eyes */
transform: translateZ(100px);
background-color: #2ecc71;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS translateZ() 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.