Transform Origin, Order of Transforms and the Matrix Functions
The point transforms happen around: transform-origin values and defaults, transform-box for SVG, why order changes the result, how browsers interpolate transform lists, and what matrix() and matrix3d() mean and when you meet them.
kvi5hnuCode Sprout team member7 min readOn this page
Every rotation, scale and skew happens around a point, the transform origin. Article 103 showed what each function does; this article covers where it happens, how combined transforms work, and the matrix that every transform turns into.
transform-origin

The default origin is the center of the element's border box. transform-origin takes up to three values: horizontal, vertical, and an optional z offset in length units:
.door { transform-origin: left center; rotate: y -30deg; } /* swings on its left edge */
.needle { transform-origin: 50% 100%; rotate: 40deg; } /* pivots at the bottom center */
.flag { transform-origin: 0 0; } /* the top-left corner */
- Keywords (
left,center,right,top,bottom), percentages of the box and lengths from its top-left corner can be mixed. Two keywords can be in either order:top leftandleft topare the same. - Tested in Chrome on a 100 × 50px box, the computed values were always lengths: the default was
50px 25px,top leftwas0px 0px, andright 10pxwas100px 10px. - The origin is the fixed point of
rotate,scaleandskew: the one point that doesn't move. It has no effect on a pure translation. - It applies to the
rotateandscaleproperties too, and totransform.
Scaling around a corner makes an element grow away from that corner, which is handy for menus that expand from their button: transform-origin: top right; scale: 0.9 shrinks toward the top-right corner.
transform-box
transform-box chooses the box that the origin and percentages refer to: border-box, content-box, fill-box, stroke-box or view-box. For HTML elements, the default behaves as border-box, so it rarely matters.
It matters for SVG. An SVG shape's default origin is 0 0 of the SVG's coordinate system, not the shape's own center. Tested in Chrome: a <rect> inside an <svg> computed transform-origin: 0px 0px. To spin an SVG icon part around its own center:
svg .gear { transform-box: fill-box; transform-origin: center; animation: spin 2s linear infinite; }
fill-box is the shape's own bounding box. transform-box works in all browsers.
Order of transforms
A transform list is read left to right, each function working in the coordinate system the previous ones left (article 103). An equivalent way to think about it is right to left, with each function moving the element in the parent's fixed coordinates. Either way, the result depends on the order:
.a { transform: translateX(100px) rotate(45deg); } /* move right, then spin in place */
.b { transform: rotate(45deg) translateX(100px); } /* spin, then move along the tilted axis: diagonally */
For orbiting elements, this is the trick: rotate(var(--angle)) translateX(80px) rotate(calc(-1 * var(--angle))) moves an element around a circle while keeping it upright.

The first two panels place the labels identically; the final rotate(-a) only undoes the label's own turn. The SVG pair renders the transform-box section above: the same rotate: 30deg pivots on a different point once transform-box changes.
The individual properties always apply as translate, rotate, scale, then transform, which is the order you usually want: move it, turn it, size it.
How transforms animate
When two transform lists are transitioned or animated, browsers interpolate them:
- Same functions in the same order: each function is interpolated on its own. Tested in Chrome, halfway between
rotate(0deg)androtate(360deg)was a 180° rotation, so the element really spins a full turn. Halfway betweenscale(-1)andscale(1)wasscale(0): the element flips by collapsing to nothing. nonecounts as the identity version of the other list's functions, sononetorotate(90deg)works.- Different functions or orders: matching functions at the start of both lists (a shorter list is padded with identity functions) are still interpolated one by one. From the first mismatch on, the rest of each list is converted to a matrix, decomposed into translation, rotation, scale and skew, and those parts are interpolated. So
rotate(0deg)torotate(360deg) scale(2)still spins. Tested in Chrome, halfway betweentranslateX(100px) rotate(90deg)androtate(90deg) translateX(100px)gave a plain matrix. The motion is smooth but can take a different path than you'd expect, and a 360° rotation becomes no rotation at all: tested in Chrome, a quarter of the way fromrotate(0deg) scale(1)toscale(1) rotate(360deg), the matrix was the identity.
The individual properties avoid most surprises: each animates as a simple value. Tested in Chrome: a quarter of the way through rotate: 0deg to rotate: 360deg was 90deg.
For predictable animations, keep the same functions, in the same order, in every keyframe, or use the individual properties.
The matrix functions
Every 2D transform is a 3 × 3 matrix, and matrix(a, b, c, d, e, f) writes it directly:
| a c e | x' = a·x + c·y + e
| b d f | y' = b·x + d·y + f
| 0 0 1 |
aanddscale along x and y.bandcskew, and together withaanddrotate.eandftranslate, in pixels.
So matrix(1, 0, 0, 1, 0, 0) is no transform, matrix(2, 0, 0, 2, 0, 0) is scale(2), matrix(1, 0, 0, 1, 30, 10) is translate(30px, 10px), and rotate(θ) is matrix(cos θ, sin θ, −sin θ, cos θ, 0, 0). Combining transforms multiplies their matrices, which is why order matters: matrix multiplication isn't commutative.
matrix3d() takes 16 numbers, a 4 × 4 matrix in column-major order, and can express any 3D transform including perspective.
When you'll meet matrices:
getComputedStyle(el).transformreturns any transform other thannoneasmatrix()ormatrix3d()(article 103). Usenew DOMMatrix(value)in JavaScript to read it:m.a,m.eand so on, orm.inverse().- Design and animation tools sometimes export them.
You rarely need to write one by hand; readable functions give the same result and are easier to change.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
label { display: inline-flex; align-items: center; gap: 0.3rem; margin-inline-end: 0.6rem; }
#angle { inline-size: 6rem; }
.stage { display: grid; place-items: center; block-size: 9rem; }
.ghost, .box { grid-area: 1 / 1; inline-size: 6rem; block-size: 3rem; border-radius: 6px; }
.ghost { border: 2px dashed #b9a993; }
.box {
background: #8a3b12; opacity: 0.85;
transform-origin: var(--origin, center);
rotate: var(--angle, 30deg);
transition: rotate 0.15s;
}
.orbit { position: relative; block-size: 7rem; display: grid; place-items: center; }
.sun { inline-size: 1.4rem; block-size: 1.4rem; border-radius: 50%; background: #f4c95d; }
.planet {
position: absolute; font-size: 1.2rem;
animation: orbit 6s linear infinite;
}
@keyframes orbit {
from { transform: rotate(0turn) translateX(3rem) rotate(0turn); }
to { transform: rotate(1turn) translateX(3rem) rotate(-1turn); } /* same functions, same order */
}
.note { margin: 0.2rem 0; color: #555; }
@media (prefers-reduced-motion: reduce) { .planet { animation-duration: 30s; } }
Change the origin and drag the angle: the rotation pivots around a different point each time, and with 50% 150% the box swings around a point below itself. The face orbits the sun because both keyframes use the same three functions in the same order, so each is interpolated on its own.
What's current
transform-origin,transform-boxand the matrix functions: all browsers.DOMMatrixreplaces the old prefixedWebKitCSSMatrixin JavaScript.
Common questions
Why does my SVG part rotate around the wrong point?
SVG elements use the SVG's 0 0 as their origin. Add transform-box: fill-box; transform-origin: center.
Why does my spinning animation not spin?
If its keyframes use different function lists, the browser interpolates matrices, and a 360° turn becomes no turn. Use the same functions, or the rotate property.
Does transform-origin change where translate moves an element?
No, translation is the same from any origin.
Do I need to learn matrices?
Only to read computed values or exported code. Use DOMMatrix in JavaScript for that.
Summary
transform-origin(default: center) is the fixed point of rotation, scale and skew.transform-box: fill-boxmakes SVG shapes transform around their own box.- Transform lists apply left to right; order changes the result.
- Matching function lists interpolate function by function; mismatched ones interpolate as decomposed matrices.
matrix(a, b, c, d, e, f)is the general 2D form; computed transforms are always matrices.
Practice questions
A dropdown should grow out of its top-right corner. Write the CSS for its closed and open states.
Answer
.menu { transform-origin: top right; scale: 0.9; opacity: 0; transition: scale 0.15s, opacity 0.15s; }
.menu.open { scale: 1; opacity: 1; }
What transform does matrix(1, 0, 0, 1, 40, -10) describe?
Answer
translate(40px, -10px): a and d are 1, so no scaling; b and c are 0, so no rotation or skew; e and f translate.
Why does this animation not rotate, and how do you fix it?
@keyframes spin {
from { transform: rotate(0deg) scale(1); }
to { transform: scale(1) rotate(360deg); }
}
Answer
The function order differs, so both are converted to matrices, and a 360° rotation is the same matrix as 0°: nothing turns. Use the same order in both keyframes, rotate(0deg) scale(1) and rotate(360deg) scale(1), or animate the rotate property.
A gear inside an inline SVG spins around the SVG's top-left corner. Fix it.
Answer
.gear { transform-box: fill-box; transform-origin: center; }
Previous: 2D Transforms: translate, rotate, scale, skew and the Individual Transform Properties

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.