translate3d()

By Gabriel Shoyombo on

The CSS translate3d() transform function moves an element in a three-dimensional space along the X, Y, and Z axes. It’s the 3D counterpart to the translate() function, and the best way to move an element when you want depth.

.card {
  transform: translate3d(40px, -20px, 100px);
}

The translate3d() function is used with the transform property and is defined in the CSS Transforms Module Level 2 specification.

Syntax

<translate3d()> = translate3d(<length-percentage>, <length-percentage>, <length> )

In simpler terms:

transform: translate3d(tx, ty, tz);

In plain English: Transform this element by sliding it over horizontally, vertically, and by a certain depth in 3D space.

Arguments

The translate3d() function takes three arguments:

/* px values */
transform: translate3d(50px, -30px, 200px);

/* percentages for x and y (relative to the element itself) */
transform: translate3d(50%, -50%, 0);

/* mix of units */
transform: translate3d(2rem, 1em, 100px);

/* no movement at all */
transform: translate3d(0, 0, 0);
  • tx: How much to translate the element along the x-axis (horizontal). Positive values move it to the right, while negative values move it to the left. It accepts <length>, or <percentage> values, relative to the element’s width.
  • ty: How much to translate the element along the y-axis (vertical). Positive values move it down, while negative values move it up. It accepts <length>, or <percentage> values, relative to the element’s height.
  • tz: How much to translate the element along the z-axis (depth). Positive values bring the element closer to the viewer, while negative values push it further away. This argument only accepts <length>; percentages are not valid here as there’s no depth to calculate a percentage of.

Compared to other translate functions

When you only need to move along one or two axes, there are shorthand functions available:

/* These are all equivalent */
transform: translate3d(50px, 0, 0);
transform: translateX(50px);

/* These are all equivalent */
transform: translate3d(0, 30px, 0);
transform: translateY(30px);

/* These are all equivalent */
transform: translate3d(0, 0, 100px);
transform: translateZ(100px);

translate3d() is the explicit three-axis version. It’s often preferred even when one or two arguments are 0 because it forces the browser to composite the element on the GPU, which when available, helps improve animation performance.

What does “moving along the Z axis” actually mean?

The X and Y axes are pretty straightforward, right? They’re the horizontal and vertical directions on your screen. The Z axis, on the other hand, a little wonky. It points straight at you, moving back and forth in depth like a straight line and moves toward and away from you.

When moving an element along the Z axis in a positive direction (e.g., 50px), it appears to move forward, towards you. A negative value (e.g., -50px) pushes the element backwards, away from you in space.

But notice that, by itself, moving an element along the Z axis has absolutely no effect. We have to use it with the perspective property applied on the element’s parent element. In other words, the element’s parent sorta acts as a container that the element transforms in.

/* This alone won't work */
.element {
  transform: translate3d(0, 0, 100px);
}

/* Instead... */

/* Add perspective to a parent to create depth */
.parent {
  perspective: 600px;

  .element {
    transform: translate3d(0, 0, 100px); /* Visibly closer */
  }
}

Think of perspective as the distance between your eye and the screen. A small value (like 200px) creates an intense, fisheye-like depth effect. A large value (like 1200px) creates subtle, refined depth. Typically a range of 400px–900px works best, but you sometimes have to play around with the values to get things just right.

Basic usage

The most direct use of translate3d() is to animate elements along the Z axis to create a sense of depth, typically seen in parallax effects and card flips.

For example, let’s say we have three cards that sit at different Z positions so they feel staggered in depth:

.parent {
  perspective: 800px;

  .card-front {
    transform: translate3d(0, 0, 80px);
  }

  .card-middle {
    transform: translate3d(0, 0, 0px);
  }

  .card-back {
    transform: translate3d(0, 0, -100px);
  }
}

translate3d(0, 0, 0) can help performance

You’ll often see this in older CSS codebases, and it might look pointless:

.animated-element {
  transform: translate3d(0, 0, 0);
}

It’s not a mistake. Even though nothing is actually moved, this promotes the element to its own composite layer, making animation significantly smoother. It’s a way of saying, “Hey, browser, put this element on its own separate layer.”

That said, modern browsers are smart enough that this trick is really necessary anymore. In fact, will-change: transform often suffices. Also, overusing translate3D() can waste memory. Maybe consider using it for smoother transitions when you’re actually experiencing a performance issue that janks your animation.

Combining translate3d() with other 3D transforms

The CSS translate3d() function is most powerful when it’s chained with rotate3d() or scale3d() for full 3D compositions.

It’s important to know that transform functions are rendered in order, right-to-left, so the order in which the properties are declared in the transform shorthand matters.

/* Rotates first, then translates in the rotated space */
transform: translate3d(0, 0, 100px) rotateY(45deg);

/* Translates first, then rotates around the original origin */
transform: rotateY(45deg) translate3d(0, 0, 100px);

These two declarations produce different results. Think of it like physical movement: turning and then stepping forward is not the same as stepping forward and then turning.

Specification

The translate3d() function is defined in the CSS Transforms Module Level 2 specification, which is currently in Editor’s Draft. That means the information can change between now and when it formally becomes a Candidate Recommendation.

Browser support

The translate3d() function is fully supported across all modern browsers.

Back to Top ⌃