How transform-origin Affects SVG Rotation Center

The transform-origin CSS property determines the exact pivot point around which an SVG element rotates. Unlike standard HTML elements, which default to rotating around their own center, SVG elements default to rotating around the top-left corner of the parent SVG coordinate system. Understanding how transform-origin interacts with SVG viewports and the transform-box property allows developers to precisely control whether an element spins around its own center, orbits a specific coordinate, or rotates relative to the entire canvas.

Default SVG Rotation Behavior

When applying a CSS rotation (transform: rotate(...)) to a standard HTML element, the default transform-origin is 50% 50% (its center). However, SVG rendering follows the SVG coordinate system where the default origin is 0 0—the top-left corner of the <svg> canvas.

Without a declared transform-origin, rotating an SVG shape causes it to sweep along a wide arc around the canvas origin rather than spinning in place.

Specifying Coordinates for transform-origin

You can alter the rotation center by providing explicit coordinate values to transform-origin:

The Role of transform-box

When using percentages or keywords for transform-origin in SVG, the browser needs to know what reference box to measure against. This is controlled by the transform-box property:

CSS vs. SVG transform Attributes

SVG also supports native rotation via the SVG transform attribute: transform="rotate(angle, cx, cy)". In this syntax, cx and cy explicitly declare the rotation center coordinates directly in the SVG markup, bypassing CSS transform-origin.

When styling with CSS, modern best practice for rotating an individual SVG element around its own center is combining CSS transforms with transform-box:

.rotating-element {
  transform-box: fill-box;
  transform-origin: center;
  transform: rotate(45deg);
}