This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

translateX()

Summary

Transform function for a 2d translation which moves an element on the x-axis by the given value.

Syntax

translateX ( <translation-value> )

Parameters

translation-value

Value for the translation across the x-axis. Can be a length or a percentage value.

Examples

The example shows three div elements, that are transformed individually with the translateX() function.

  1. The translation of the first element moves it 10 pixels to the right along the x-axis.
  2. You can also provide a negative value. In this case, element-2 is moved 20 pixels to the left, in the negative direction on the x-axis.
  3. Using a percentage value of 50 percent moves element-3 in x-direction by a value which matches 50 percent of the element-3’s width. In this case element-3 has a 100 pixel width, so it is moved 50 pixels to the right.
.element-1 {
    transform: translateX(10px);
}

.element-2 {
    transform: translateX(-20px);
}

.element-3 {
    transform: translateX(50%);
}

View live example

See also

Related articles

Transforms

External resources

Attributions