Skip to content

translate

Utilities for translating elements.

Source: https://tailwindcss.com/guide/transforms/translate

Quick reference

ClassStyles
translate-<number>translate: calc(var(--spacing) * <number>) calc(var(--spacing) * <number>);
-translate-<number>translate: calc(var(--spacing) * -<number>) calc(var(--spacing) * -<number>);
translate-<fraction>translate: calc(<fraction> * 100%) calc(<fraction> * 100%);
-translate-<fraction>translate: calc(<fraction> * -100%) calc(<fraction> * -100%);
translate-fulltranslate: 100% 100%;
-translate-fulltranslate: -100% -100%;
translate-pxtranslate: 1px 1px;
-translate-pxtranslate: -1px -1px;
translate-(<custom-property>)translate: var(<custom-property>) var(<custom-property>);
translate-[<value>]translate: <value>;
translate-x-<number>translate: calc(var(--spacing) * <number>) var(--tw-translate-y);
-translate-x-<number>translate: calc(var(--spacing) * -<number>) var(--tw-translate-y);
translate-x-<fraction>translate: calc(<fraction> * 100%) var(--tw-translate-y);
-translate-x-<fraction>translate: calc(<fraction> * -100%) var(--tw-translate-y);
translate-x-fulltranslate: 100% var(--tw-translate-y);
-translate-x-fulltranslate: -100% var(--tw-translate-y);
translate-x-pxtranslate: 1px var(--tw-translate-y);
-translate-x-pxtranslate: -1px var(--tw-translate-y);
translate-x-(<custom-property>)translate: var(<custom-property>) var(--tw-translate-y);
translate-x-[<value>]translate: <value> var(--tw-translate-y);
translate-y-<number>translate: var(--tw-translate-x) calc(var(--spacing) * <number>);
-translate-y-<number>translate: var(--tw-translate-x) calc(var(--spacing) * -<number>);
translate-y-<fraction>translate: var(--tw-translate-x) calc(<fraction> * 100%);
-translate-y-<fraction>translate: var(--tw-translate-x) calc(<fraction> * -100%);
translate-y-fulltranslate: var(--tw-translate-x) 100%;
-translate-y-fulltranslate: var(--tw-translate-x) -100%;
translate-y-pxtranslate: var(--tw-translate-x) 1px;
-translate-y-pxtranslate: var(--tw-translate-x) -1px;
translate-y-(<custom-property>)translate: var(--tw-translate-x) var(<custom-property>);
translate-y-[<value>]translate: var(--tw-translate-x) <value>;
translate-z-<number>translate: var(--tw-translate-x) var(--tw-translate-y) calc(var(--spacing) * <number>);
-translate-z-<number>translate: var(--tw-translate-x) var(--tw-translate-y) calc(var(--spacing) * -<number>);
translate-z-pxtranslate: var(--tw-translate-x) var(--tw-translate-y) 1px;
-translate-z-pxtranslate: var(--tw-translate-x) var(--tw-translate-y) -1px;
translate-z-(<custom-property>)translate: var(--tw-translate-x) var(--tw-translate-y) var(<custom-property>);
translate-z-[<value>]translate: var(--tw-translate-x) var(--tw-translate-y) <value>;
translate-nonetranslate: none;

Examples

Using the spacing scale

Use translate-&lt;number&gt; utilities like translate-2 and -translate-4 to translate an element on both axes based on the spacing scale:

html
<img class="-translate-6 ..." src="/img/mountains.jpg" />
<img class="translate-2 ..." src="/img/mountains.jpg" />
<img class="translate-8 ..." src="/img/mountains.jpg" />

Using a percentage

Use translate-&lt;fraction&gt; utilities like translate-1/4 and -translate-full to translate an element on both axes by a percentage of the element's size:

html
<img class="-translate-1/4 ..." src="/img/mountains.jpg" />
<img class="translate-1/6 ..." src="/img/mountains.jpg" />
<img class="translate-1/2 ..." src="/img/mountains.jpg" />

Translating on the x-axis

Use translate-x-&lt;number&gt; or translate-x-&lt;fraction&gt; utilities like translate-x-4 and translate-x-1/4 to translate an element on the x-axis:

html
<img class="-translate-x-4 ..." src="/img/mountains.jpg" />
<img class="translate-x-2 ..." src="/img/mountains.jpg" />
<img class="translate-x-1/2 ..." src="/img/mountains.jpg" />

Translating on the y-axis

Use translate-y-&lt;number&gt; or translate-y-&lt;fraction&gt; utilities like translate-y-6 and translate-y-1/3 to translate an element on the y-axis:

html
<img class="-translate-y-4 ..." src="/img/mountains.jpg" />
<img class="translate-y-2 ..." src="/img/mountains.jpg" />
<img class="translate-y-1/2 ..." src="/img/mountains.jpg" />

Translating on the z-axis

Use translate-z-&lt;number&gt; utilities like translate-z-6 and -translate-z-12 to translate an element on the z-axis:

html
<div class="transform-3d">
  <img class="-translate-z-8 rotate-x-50 rotate-z-45 ..." src="/img/mountains.jpg" />
  <img class="translate-z-2 rotate-x-50 rotate-z-45 ..." src="/img/mountains.jpg" />
  <img class="translate-z-1/2 rotate-x-50 rotate-z-45 ..." src="/img/mountains.jpg" />
</div>

Note that the translate-z-&lt;number&gt; utilities require the transform-3d utility to be applied to the parent element.

Using a custom value

Use the translate-[&lt;value&gt;] syntax to set the translate based on a completely custom value:

html
<img class="translate-[3.142rad] ..." src="/img/mountains.jpg" />

For CSS variables, you can also use the translate-(&lt;custom-property&gt;) syntax:

html
<img class="translate-(--my-translate) ..." src="/img/mountains.jpg" />

This is just a shorthand for translate-[var(&lt;custom-property&gt;)] that adds the var() function for you automatically.

Responsive design

Prefix a translate utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

html
<img class="translate-45 md:translate-60 ..." src="/img/mountains.jpg" />

Learn more about using variants in the variants documentation.

Released under the MIT License.