SVG rotation needs an angle and a center. For a saved SVG file, transform="rotate(30 120 90)" turns an element 30 degrees around the point (120, 90). For CSS rotation around the artwork's own bounds, combine transform-box: fill-box with transform-origin: center.
If you just need to turn a file, rotate SVG online: open the file, choose a preset or enter a custom angle, check the preview, and download. The tool rotates around the viewBox center. The examples below explain how to choose a different pivot in your code.
Rotate SVG with an explicit center
The SVG transform attribute accepts rotate(angle cx cy). The angle is in degrees without a deg suffix; cx and cy are coordinates in the element's current user coordinate system. In the usual SVG coordinate system, where the y-axis points down, a positive angle turns clockwise and a negative angle turns counterclockwise.
Save this complete example as rotated-arrow.svg, or paste it into SVG Editor:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 180">
<g fill="#2563eb" transform="rotate(30 120 90)">
<rect x="60" y="70" width="80" height="40" />
<polygon points="140,50 180,90 140,130" />
</g>
</svg>
The rectangle and triangle form one arrow. Putting both in a <g> rotates them together. Here the drawing's bounding box and the viewBox happen to share the center (120, 90); that is not true of every SVG.
To turn the same arrow a quarter turn, use rotate(90 120 90). For a half turn, use rotate(180 120 90). rotate(30) alone uses the coordinate origin (0, 0), so an off-center drawing can swing away from its original position.
Choose the viewBox center or the artwork center
For viewBox="minX minY width height", calculate the canvas center as:
cx = minX + width / 2
cy = minY + height / 2
For example, viewBox="20 10 240 180" has center (140, 100), not (120, 90). Do not treat the viewBox width and height as screen pixels or forget its starting coordinates.
If the file has uneven empty space around its shapes, the artwork center is different. Use the drawing's bounding box when you want it to spin in place. Its geometric center may still differ from the visual balance point of an asymmetric logo; adjust the pivot deliberately if the result looks uneven.
Use CSS transform-origin for the shape's center
For an inline SVG whose shape or group should turn around its own bounds, use this CSS on that group:
.rotating-artwork {
transform-box: fill-box;
transform-origin: center;
transform: rotate(30deg);
}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 180">
<g class="rotating-artwork" fill="#2563eb">
<rect x="60" y="70" width="80" height="40" />
<polygon points="140,50 180,90 140,130" />
</g>
</svg>
The class needs the CSS above in the containing HTML page. To keep a standalone .svg portable, embed its styles inside the SVG or use the explicit rotate(30 120 90) attribute from the first example.
Most SVG child elements start with transform-origin: 0 0. The root <svg> has a different default. Also, transform-origin: center by itself does not select the shape's bounds: the default transform-box is view-box. fill-box makes the group's object bounding box the reference instead. It does not crop blank space from the file or include the full painted extent of strokes and filters.
Apply the class to the group, rather than separately to every path. Otherwise each child may rotate around its own center and pull a multi-part icon apart. CSS on an HTML page also cannot select paths inside a separate SVG loaded through <img src="icon.svg">; inline the SVG or edit the SVG file itself.
Keep existing transforms and understand their order
A CSS transform on an element takes precedence over its SVG transform attribute. If the group already has a placement transform, put the rotation on a nested group so both operations remain explicit:
<g transform="translate(40 20)">
<g transform="rotate(30 120 90)">
<rect x="60" y="70" width="80" height="40" fill="#2563eb" />
<polygon points="140,50 180,90 140,130" fill="#2563eb" />
</g>
</g>
This fragment rotates in the inner group's coordinates, then places the result with the outer translation. A combined transform="translate(40 20) rotate(30 120 90)" gives the same mapping of points: the rightmost operation acts first. Reversing the order changes where the artwork ends up. Allow enough space in the enclosing SVG for the translated drawing.
Fix SVG clipping after rotation
Rotating a group does not automatically enlarge the root viewBox. At an oblique angle, the artwork can need more room even though its paths remain valid. For a rectangle of width w and height h, the rotated enclosing dimensions are:
rotated width = |w cos(angle)| + |h sin(angle)|
rotated height = |w sin(angle)| + |h cos(angle)|
For a 120 × 80 rectangle at 45 degrees, each enclosing dimension is about 141.4 units. A viewBox only 80 units high cannot contain it. Expand the viewBox around the intended center, and allow extra padding for thick strokes, shadows, and filters. Internal clip paths may need separate changes.
Preview the result on a contrasting background in SVG Viewer. Use SVG ViewBox Fixer to inspect and adjust the canvas, then check the final file at its intended display size. Setting CSS overflow to visible may reveal the problem on a web page, but does not repair the file's export bounds.
Common SVG rotation questions
Why does the SVG orbit instead of rotating in place?
First check the pivot. A bare rotate(angle) uses (0, 0). If you use CSS, check both transform-origin and transform-box, and apply them to the group that represents the whole drawing.
Does rotating SVG reduce image quality?
An SVG transform keeps vector paths as vectors. An embedded bitmap remains a bitmap. Exporting PNG creates a raster image, so choose enough pixels for the final use and inspect fine details.
Should I use CSS or an SVG transform attribute?
Use an explicit attribute pivot for a self-contained static file. Use CSS when the rotation belongs to a web component's styling or state. Avoid defining competing transforms on the same element, and preview the output in its destination.
References and further reading
- MDN: SVG transform attribute for rotation syntax and transform order.
- MDN: SVG transform-origin for origin defaults.
- MDN: CSS transform-box for reference boxes.