CSS - translate()

The translate() CSS function moves the position of the element on the plane. This transformation is characterized by a vector whose coordinates define how much it moves in each direction.

Examples

Using a single axis translation

HTML

HTML
<p>foo</p>
<p class="transformed">bar</p>
<p>foo</p>

CSS

CSS
p { 
  width: 50px;
  height: 50px;
  background-color: teal;
}

.transformed {
  transform: translate(10px);
  /* equivalent to translateX(10px)*/
  background-color: blue;
}

Result

Combining y-axis and x-axis translation

HTML

HTML
<p>foo</p>
<p class="transformed">bar</p>
<p>foo</p>

CSS

CSS
p { 
  width: 50px;
  height: 50px;
  background-color: teal;
}

.transformed {
  transform: translate(10px,10px);
  background-color: blue;
}

Result

Syntax  

CSS
translate(tx)       or
translate(tx, ty)

Description  

The translate() CSS function moves the position of the element on the plane. This transformation is characterized by a vector whose coordinates define how much it moves in each direction.

 

tx
Is a <length> representing the abscissa of the translating vector.
ty
Is a <length> representing the ordinate of the translating vector. If unspecified, it will equal 0 :  translate(2) means translate(2, 0).
Cartesian coordinates on ℝ2 Homogeneous coordinates on ℝℙ2 Cartesian coordinates on ℝ3 Homogeneous coordinates on ℝℙ3

A translation is not a linear transform in ℝ2 and cannot be represented using a matrix in the cartesian coordinates system.

10tx01ty001 10tx01ty001 100tx010ty00100001
[1 0 0 1 tx ty]

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/css/transform-function/translate

CSS CSS Transforms NeedsCompatTable Reference