In this example we have an SVG:
<svg id="svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">
<g>
<circle id="center" fill="red" r="1" transform="translate(25 25)" />
<circle id="boxcenter" fill="blue" r=".5" transform="translate(15 15)" />
<rect
id="box"
x="10"
y="10"
width="10"
height="10"
rx="1"
ry="1"
stroke="black"
fill="none" />
</g>
</svg>
In the CSS we have an animation that uses a transform to rotate the rectangle infinitely. transform-box: fill-box
is used to make the transform-origin
the center of the bounding box, so the rectangle spins in place. Without it, the transform origin is the center of the SVG canvas, and so you get a very different effect.
svg {
width: 80vh;
border: 1px solid #d9d9d9;
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#box {
transform-origin: 50% 50%;
transform-box: fill-box;
animation: rotateBox 3s linear infinite;
}
@keyframes rotateBox {
to {
transform: rotate(360deg);
}
}
Full credit for this example goes to Pogany; see this codepen for a live version.