Questions
4 of 30
1What is the purpose of the transform property in CSS?
2What are the different types of CSS transformations?
3What does transform: translate() do?
4What is the difference between translateX() and translateY()?
5How does rotate() work in CSS?
6What is the unit used in rotation?
7What is the difference between scale() and scaleX(), scaleY()?
8What happens when you use negative values in scale()?
9What does the skew() function do?
10Can you combine multiple transform functions together? How? What is the use of the transform-origin property?
11What is the default transform-origin value?
12How does changing transform-origin affect rotation or scaling?
13What is the difference between translate() and using position or margin for movement?
14What is the difference between 2D and 3D transformations?
15What is the difference between 2D and 3D transformations?
16How do you apply a 3D rotation using CSS?
17How do you apply a 3D rotation using CSS?
18What are perspective and perspective-origin in 3D transforms? What is the purpose of transform-style: preserve-3d?
19What is the use of matrix() in CSS transforms?
20What’s the difference between matrix() and matrix3d()?
21How can you center an element using transform and translate()?
22What is the transition property in CSS used for?
23What are the four main components of a transition?
24What does transition-duration specify?
25What are the common timing function values (e.g., ease, linear, ease-in)?
26What is the shorthand syntax for transition?
27Can multiple CSS properties be transitioned simultaneously? How does transition differ from animation in CSS?
28Can you apply a transition to an element’s pseudo-class (like :hover)?
29Can transitions be triggered by JavaScript?
30What happens if transition-duration is set to 0s?
04 / 30

What is the difference between translateX() and translateY()?

Understanding translateX() and translateY() in CSS

Both translateX() and translateY() are CSS transform functions used to move an element along a single axis without affecting the document flow. They help reposition elements smoothly and are often used in animations and transitions.

Key Differences
  1. 1

    translateX(value) — moves the element horizontally along the X-axis. Positive values move it to the right, negative values move it to the left.

  2. 2

    translateY(value) — moves the element vertically along the Y-axis. Positive values move it downward, negative values move it upward.

Example: Using translateX() and translateY()

In this example, .move-x shifts the box 80px to the right, while .move-y moves it 50px upward. The movement is animated smoothly with the transition property.

Best Practices
  1. 1

    Use translateX() and translateY() instead of left or top for smoother, GPU-accelerated animations.

  2. 2

    Combine both with translate(x, y) when moving elements diagonally.

  3. 3

    Pair with transition for interactive hover or click effects.

Example: Combining Translations with Transitions

Here, the card shifts diagonally when hovered, combining both X and Y translations for a smooth, engaging motion.

Difficulty: 4/10
Topics: CSS transforms, layout performance, responsive design

Scenario Questions

0-2 years experience
  1. 1

    We need a button to slide 50 px to the right on hover. How would you use translateX() to do that, and what would happen if you mistakenly used translateY() instead?

  2. 2

    If you apply transform: translateX(30px) translateY(20px); to a div, describe where it ends up relative to its original position.

  3. 3

    What visual effect does transform: translateX(-100%); have on an element, and does it affect the layout of surrounding elements?

2-5 years experience
  1. 1

    A carousel slides correctly horizontally in Chrome but moves vertically in Safari. How would you investigate whether translateX/Y is being used incorrectly?

  2. 2

    During a refactor you replace left: 20px; with transform: translateX(20px);. Explain the trade‑offs in repaint/reflow and why click targets might behave differently.

  3. 3

    A designer asks you to animate an element from the top‑left to the bottom‑right using only CSS. How would you combine translateX and translateY, and what pitfalls exist with different writing modes or RTL layouts?

5-8 years experience
  1. 1

    Your virtual‑scroll list animates items as they enter the viewport. Discuss the performance impact of using translateX versus translateY for those animations and which axis is generally cheaper on the GPU.

  2. 2

    A legacy codebase mixes transform: translateX() with margin-left for positioning. How would you design a migration plan across multiple teams to standardize on transforms?

  3. 3

    When the UI switches between a horizontal and a vertical layout, how would you abstract translateX/Y usage so the same component works in both orientations without duplicating CSS?

8+ years experience
  1. 1

    Our organization is moving to a design system that exposes motion tokens. How would you decide whether to include translateX/translateY as part of the token API, considering cross‑team maintenance and performance?

  2. 2

    A performance audit shows jank on scroll because many sticky headers use transform: translateY(). Propose a system‑level redesign that removes the jank while preserving the visual effect, and discuss trade‑offs.

  3. 3

    We need consistent motion semantics across web and React Native. How would you align the use of translateX/Y across platforms, and what architectural patterns would you put in place to keep them synchronized?

Follow-up Questions

  • What happens if you apply both translateX and translateY in the same rule?
  • How does the browser actually render these transforms under the hood?
  • Are there any accessibility or hit‑testing implications when using transforms for positioning?