Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How does transform-origin change the result of a CSS rotation?

Quick answer

transform-origin sets the point an element rotates around. For ordinary CSS elements, the default is the center; changing it to a corner makes that corner the pivot instead. The rotation angle stays the same, but the element follows a different path and ends up in a different visual position. Set the origin explicitly when you need a predictable pivot. [S1]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I set transform: rotate(90deg), but the element seems to move. Is the rotation changing its position?

Geez

The rotation can change where the element appears, even when you haven’t changed its layout position. The key is the pivot: transform-origin sets the point around which the transform is applied. For ordinary CSS elements, the default pivot is the center, written as 50% 50% 0. The browser effectively shifts the origin, rotates, then shifts back; changing the origin therefore changes the element’s visual position as it turns. [S1]

Think of the element as a card pinned to a board. Rotate it around its center and it swings around that center. Pin it at a corner and that corner stays put while the rest swings around it.

Follow-up question

Can you show the difference using coordinates, not just the card comparison?

Geez

Assume a 200-by-100-pixel element whose top-left is at coordinate (0, 0). Its center is (100, 50). The diagram shows the two possible pivots:

Element before rotation (200 × 100)

(0,0) A--------------------
      |          C (100,50) |
      |                     |
      ---------------------- B (200,100)

A = top-left corner     C = center

With transform-origin: 50% 50%, C is the pivot. With transform-origin: 0 0, A is the pivot. For a 90-degree rotation, the element turns around whichever point is selected; the center-pivot and corner-pivot versions therefore trace different paths and have different visual placements. Percentages are relative to the element’s reference box. [S1][S2]

This diagram identifies pivots, not exact screen coordinates after rotation. The final coordinates depend on the element’s position and its surrounding layout.

Follow-up question

What would the paired CSS example look like, and how do I compare it fairly?

Geez

Give both elements the same dimensions and rotation, then change only the origin. For a quick visual comparison, place them in separate spaces or inspect them one at a time:

.center-pivot {
  width: 200px;
  height: 100px;
  transform-origin: 50% 50%;
  transform: rotate(90deg);
}

.corner-pivot {
  width: 200px;
  height: 100px;
  transform-origin: 0 0;
  transform: rotate(90deg);
}

The first rotates around its center; the second rotates around its top-left corner. Keep the angle and dimensions identical so the origin is the only changed variable. The CSS transforms specification describes the same shift-origin, apply-transform, shift-back calculation, and explains why changing the origin changes the visual path and placement. [S2]

Follow-up question

How should I choose the origin when I’m building an actual effect?

Geez

Choose the point that should appear to hold still while the element turns. Use the center for a spin around the element’s middle, or a corner or edge when the motion should swing around that point. Then set the origin explicitly and check the result in its actual layout; the pivot tells you how it rotates, but it doesn’t guarantee a particular final screen position.

A reusable note for a design or code review could be:

Element: [selector or component]
Rotation: [angle]
Pivot: [center, top-left, or other point]
CSS origin: [for example, 50% 50% or 0 0]
Expected fixed point: [point that should stay in place]
Check: compare with the same element and angle using the default center origin

For ordinary CSS elements, origin percentages refer to the reference-box dimensions. SVG elements can have different initial-value behavior in some cases, so this center-versus-corner example should not be assumed to describe every SVG setup. The cited material establishes how the origin affects the pivot and visual path; it does not establish exact placement for every layout or SVG case. [S1][S2]

A practical checklist

  • Identify the point that should act as the pivot.

  • Set transform-origin explicitly instead of relying on the default.

  • Compare examples with the same dimensions and rotation angle.

  • Check the visual result in the element’s actual layout.

  • If working with SVG, verify how its reference box and initial behavior apply.

A few more useful answers

What is the default `transform-origin` for an ordinary CSS element?

It is the center, 50% 50% 0, for ordinary CSS transformable elements. SVG can differ in some cases. [S1]

Do percentages in `transform-origin` refer to the page?

No. The horizontal and vertical percentages refer to the element’s reference-box dimensions. [S1][S2]

Does changing the origin change the rotation angle?

No. It changes the pivot, which changes the element’s visual path and placement as it rotates; the angle can stay the same. [S1][S2]

Sources

References used for this guide.

  1. [S1] MDN: transform-origin CSS property
    developer.mozilla.org · Checked
  2. [S2] W3C: CSS Transforms Module Level 1, rendering model and transform origin
    w3.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work