On this page
An exported SVG can contain a small illustration wrapped in a surprising amount of editor metadata, redundant groups, and unnecessarily precise coordinates. Removing bytes is useful, but an optimizer that changes the artwork has failed its primary job.
Build a pipeline that separates structural cleanup from geometric changes. Measure the original, change one class of data at a time, and compare both appearance and transfer size before promoting the result.
Establish the geometry contract
The viewBox defines the coordinate system, while displayed dimensions define how that system maps onto the page. Path coordinates, strokes, gradients, masks, and clipping paths all depend on that relationship. Editing one piece without considering the others can create subtle defects.
Use the SVG Path Scaler & Normalizer below to inspect coordinate transformations on a small representative path. Scaling a path can be useful when normalizing icon artwork, but it is not equivalent to optimizing an entire SVG document.
Record the source dimensions, viewBox, smallest display size, largest display size, and any required stroke behavior. Keep the original asset unchanged in source control. An optimizer should create a derived artifact so you can compare, reproduce, and reverse the transformation.
Identify special features before automation: embedded text, filters, external references, animation, and reused symbols. A simple monochrome icon and a branded illustration need different optimization policies. Applying the same aggressive preset to both saves configuration at the expense of reliability.
Remove structural waste before changing shapes
Start with low-risk cleanup such as editor metadata, comments, and genuinely unused definitions. Even these changes need context: a definition referenced from application code may look unused to a tool that only sees one file. Define the asset's integration contract first.
Use the SVG Code Minifier & Cleaner for a second view of removable overhead. The MDN SVG reference is the authoritative starting point when you need to verify element and attribute behavior rather than guessing from exported markup.
Do not remove the viewBox simply because explicit width and height are present. Responsive scaling commonly depends on it. Likewise, preserve meaningful accessibility information unless the embedding component supplies the accessible name through another documented mechanism.
Avoid blind regular-expression rewrites of XML. Attribute values can contain references, namespaces matter, and formatting varies. Use a parser or a mature optimizer with a configuration checked into the project. Keep the dependency version pinned so an unrelated update does not silently change every icon.
After structural cleanup, compare raw and compressed sizes. A large reduction in source characters may translate to a smaller reduction over the network because repeated markup compresses well. Both numbers are useful, but they answer different questions.
Transform coordinates with explicit assumptions
Path scaling requires correct handling of command semantics. Absolute and relative coordinates differ; horizontal and vertical commands are specialized; elliptical arcs include radii, rotation, and flags. A function that multiplies every number will corrupt arc flags and rotation values.
For complete documents, a group transform can express a simple mapping without rewriting every path. The example below moves 48-unit artwork into a 24-unit coordinate space. It assumes the entire grouped artwork should scale together, including its ordinary strokes.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<g transform="scale(0.5)">
<path d="M8 24 L20 36 L40 12"
fill="none" stroke="currentColor" stroke-width="4"
stroke-linecap="round" stroke-linejoin="round" />
</g>
</svg>This is an illustration of geometry, not a guaranteed byte optimization. Baking a transform into path data may produce a larger or smaller result depending on the source. Consult the MDN transform attribute reference before changing operation order; translation followed by scaling is not generally equivalent to scaling followed by translation.
Use the path scaler and normalizer to compare a baked coordinate version with the transformed version. Check stroke behavior separately. A non-scaling stroke intentionally behaves differently under transforms and may need to remain that way for maps or diagrams.
Gradients and masks can use different coordinate systems. Transforming only paths while leaving their supporting definitions unchanged may alter the image. If the document contains these features, preserve their relationships or use an optimizer that understands the complete structure.
Set a precision budget from display size
Decimal precision should follow visible error tolerance, not a universal rule such as “two decimals everywhere.” A coordinate error that is invisible in a 24-pixel icon can become obvious when the same graphic is enlarged to 1200 pixels.
Estimate the scale factor from user units to displayed pixels. If a 24-unit viewBox is displayed at 240 pixels, each user unit spans 10 pixels. Rounding coordinates to the nearest 0.01 unit introduces up to roughly 0.05 displayed pixels of error per coordinate before considering accumulated curve effects.
That estimate is a starting point, not proof. Curves, intersections, and thin strokes can amplify visual sensitivity. Inspect joins and tangencies closely: a tiny shift where two shapes meet may produce a visible seam even when most of the illustration looks unchanged.
Test at multiple device pixel ratios and backgrounds. Transparent artwork can hide edge artifacts on white and reveal them on a dark surface. Include the largest legitimate display size rather than an arbitrary zoom level no user will encounter.
The production SVG guide covers embedding decisions that influence the review. Inline symbols, external image files, and CSS backgrounds have different styling and naming constraints, so evaluate the optimized file in its real delivery context.
Make the pipeline reproducible and safe
Maintain a fixture set containing straight paths, arcs, gradients, masks, and accessibility metadata. Run the optimizer against these examples whenever its version or configuration changes. Compare rendered output and review meaningful diffs rather than approving hundreds of rewritten files blindly.
Optimization is not sanitization. Untrusted SVG can contain active or externally referencing content. Treat uploads according to a separate security policy, and choose an embedding strategy appropriate to the trust level. Removing whitespace and metadata does not make arbitrary markup safe.
The MDN SVG security documentation describes restrictions that apply when SVG is used as an image. Those restrictions are not interchangeable with inline embedding behavior, so keep the distinction visible in the asset pipeline.
Set an acceptance rule: no unexpected visual difference, no lost naming behavior, and a measured benefit worth maintaining. Sometimes the best outcome is keeping a complex illustration unchanged while aggressively cleaning a large set of simple icons.
Key takeaways
- Establish the coordinate and integration contract before changing SVG data.
- Remove structural overhead before attempting geometric simplification.
- Handle path commands, strokes, gradients, and transforms as related geometry.
- Choose precision from actual display requirements and visual comparisons.
- Keep optimization reproducible and separate from untrusted-content sanitization.
Reach designers & developers at work
Put your product next to the tools people use every day. One sponsor per placement, no tracking pixels.
Become a sponsor