CSS propertyTransforms

translate

Moves an element horizontally, vertically, or in depth, independently of the transform property.

Initial value
none
Inherited
No
Animatable
yes, as a length or percentage
Applies to
transformable elements
JavaScript
element.style.translate = "20px 10px"
On this page

Example

#
CSS
.toast {
  translate: 0 20px;
  opacity: 0;
  transition: translate 0.3s, opacity 0.3s;
}

.toast.visible {
  translate: 0 0;
  opacity: 1;
}
Preview

Definition and usage

#

The translate property is a standalone version of the translate() function. It lets you set a translation without overwriting other transforms written in transform.

One value moves horizontally, two move horizontally and vertically, and the third moves along the Z axis. Percentages are relative to the element’s own size, so translate: -50% -50% moves the element by half its width and height.

The browser applies the individual properties in a fixed order: first translate, then rotate, then scale, and finally transform.

Syntax

#
Syntax
translate: none | <x> <y>? <z>?;

Values

#
  • none

    No translation.
  • 60px

    Moves 60px to the right.
  • -40px 20px

    40px to the left and 20px down.
  • 50% -30%

    percentages

    Moves by a fraction of the element’s own size.

Values in practice

#

none

No translation.
.demo { translate: none; }

60px

Moves 60px to the right.
.demo { translate: 60px; }

-40px 20px

40px to the left and 20px down.
.demo { translate: -40px 20px; }

50% -30%

Moves by a fraction of the element’s own size.
.demo { translate: 50% -30%; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Separate translate, rotate, and scale let you animate one transform without rewriting the whole transform.
  • Centring an absolutely positioned element: left: 50%; top: 50%; translate: -50% -50%;.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.