How to Flatten SVG Transforms and Keep Path Shape
Rewrite SVG path coordinates to flatten nested transforms. Check the original and flattened artwork at the same scale and keep a separate master for edits.
On this page
- Find the coordinates you need to transfer
- Apply the matrix to the path
- Verify the rendered result and the saved markup
- Decide what else the transform affects
- FAQ
- Can I just remove the transform attribute?
- Does flattening a transform rasterize the SVG?
- Should I change the viewBox while flattening path coordinates?
- Start with editable source art
- Sources
To flatten SVG transforms, apply the combined matrix to the path coordinates, write the new coordinates into d, and remove the transforms those coordinates already include. Keep the original SVG as your master. Flatten a copy when a receiver needs coordinates in the parent coordinate system or drops the transform during import.
Flattening changes how the file stores the artwork's position and size. For a filled cubic path, you can keep both the rendered shape and the original curve command. Start with a solid-filled path written with absolute M, L, and C commands and a Z closure. Use a path without a stroke or effects for this first test.
Find the coordinates you need to transfer
A transform matrix maps a point from one coordinate system to another. In matrix(a b c d e f), a point (x, y) becomes (a·x + c·y + e, b·x + d·y + f). With nested groups, apply the path's own mapping first, then its ancestors' mappings, up to the space that will contain the new path. The root viewBox can stay in place for a transfer copy that keeps the same canvas. CSS Transforms matrix definition · SVG 2 coordinate systems
Save this as nested.svg. It contains one closed path, with scale and skew in the inner group and a translation in the outer group.
<svg xmlns="http://www.w3.org/2000/svg" width="136" height="72" viewBox="0 0 136 72">
<g transform="translate(18 12)">
<g transform="matrix(2 0 .5 1.5 0 0)">
<path fill="#285f75" d="M8 10 C12 0 36 0 40 10 L40 28 L8 28Z"/>
</g>
</g>
</svg>Apply the matrix to the path
- Combine the two mappings. Apply the inner mapping
(2x + .5y, 1.5y), then add(18, 12). The combined matrix ismatrix(2 0 .5 1.5 18 12). - Map every absolute point. The starting point
(8, 10)becomes(39, 27). For the cubicCcommand, map both control points and the endpoint. A control point steers the curve between the endpoints. SVG 2 cubic Bézier commands - Keep the
Zclosure, replace the path data, and remove the two transformed wrappers. Save the second file asflat.svgwith the same canvas and fill.
<svg xmlns="http://www.w3.org/2000/svg" width="136" height="72" viewBox="0 0 136 72">
<path fill="#285f75" d="M39 27 C42 12 90 12 103 27 L112 54 L48 54Z"/>
</svg>| Point to map | Before | After |
|---|---|---|
| Start of the path | 8, 10 | 39, 27 |
| First control point | 12, 0 | 42, 12 |
| Second control point | 36, 0 | 90, 12 |
| End of the curve | 40, 10 | 103, 27 |
Verify the rendered result and the saved markup
Open both SVGs at the same display size. Check the position and silhouette before trying the transfer. In our 136 × 72 pixel resvg renders, the two files had zero differing pixels. The flattened file still had one cubic command and no transform attributes. The original and flattened paths also match at 4× in the same renderer.

If the shape shifts, compare one expected point first. A point that is offset by the wrong amount can reveal a reversed transform order or an ancestor left in the file after you rewrote coordinates. The SVG transform order guide walks through that diagnosis. For relative commands, use the absolute and relative path guide before applying a translation to numeric values.
Decide what else the transform affects
The example keeps the same root coordinate system and has no stroke, clip, mask, or filter. A path-only rewrite needs a separate paint check for artwork that uses any of them. A nonuniform scale, for instance, can change how a stroke looks along different edges. Removing the scale and preserving the original stroke width as one number can change the result. See the SVG stroke troubleshooting guide before adapting the example to stroked artwork.
An elliptical arc has radii, rotation, and direction flags in addition to its endpoint. Use a path-aware tool for arcs or convert them to curves with a tolerance you can verify. The point-by-point rewrite above covers M, L, C, and Z. For a path with H or V, first rewrite the command as an L with both coordinates. A skew or rotation can turn that horizontal or vertical segment into a diagonal one. SVG 2 line commands Keep transformed groups that inherit important styles unless you can preserve those styles on the rewritten paths.
FAQ
Can I just remove the transform attribute?
Only when the transform is effectively the identity in the destination coordinate system. In the example, deleting both group transforms without rewriting the path moves and shrinks the badge.
Does flattening a transform rasterize the SVG?
No. A geometry rewrite leaves SVG path data. You can still select nodes and edit curves after flattening the example.
Should I change the viewBox while flattening path coordinates?
Keep it the same when the flattened file should occupy the same canvas. A viewBox change also affects how that coordinate system fits the viewport.
Start with editable source art
PerfectVector can turn flat raster artwork into editable SVG paths.
If the source is a PNG or JPG, trace the artwork into vector paths before you work with path coordinates. Inspect the outline and any interior openings on the traced SVG, then create a separate transfer copy for flattening.
Sources
- W3C CSS Transforms — Matrix function — The six matrix coefficients and their placement.
- W3C SVG 2 — Coordinate systems and units — Coordinate system and viewport mapping.
- W3C SVG 2 — Cubic Bézier commands — Endpoints and control points in path data.
More from the blog
SVG Polygon vs. Polyline: Check the Closing Edge
See why an SVG polyline can look filled while its closing stroke is missing. Compare it with a polygon using the same points, then check the edge in your file.
SVG Non-Scaling Stroke: Keep Line Width on Resize
Keep SVG strokes the same width as shapes resize. Compare ordinary and non-scaling strokes, then check the result in your browser or export tool.


