transform-box
Example
.gear {
transform-origin: center;
animation: spin 2s linear infinite;
}.gear {
transform-box: fill-box;
transform-origin: center;
animation: spin 2s linear infinite;
}With 'fill-box', 'center' means the center of the shape, not the center of the SVG viewport.
Common mistakes
- An SVG path spins around the top-left of the
<svg>instead of its own center.
Key points
- SVG elements set
transform-box: fill-boxbefore usingtransform-origin: center. - HTML elements keep the default box, since 'fill-box' and 'view-box' mainly matter for SVG.
Interview questions
What is the default transform-box?
'view-box', so SVG transforms use the SVG viewport; HTML elements then use their border box.
What is the difference between fill-box and stroke-box?
'fill-box' uses the shape's geometry, while 'stroke-box' also includes the stroke around it.