{"id":52,"date":"2026-10-17T13:15:08","date_gmt":"2026-10-17T13:15:08","guid":{"rendered":"https:\/\/refracttools.com\/blog\/?p=52"},"modified":"2026-10-17T13:15:10","modified_gmt":"2026-10-17T13:15:10","slug":"optimise-svg-files","status":"publish","type":"post","link":"https:\/\/refracttools.com\/blog\/image-optimisation\/optimise-svg-files\/","title":{"rendered":"How to optimise SVG files without breaking them"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To optimise SVG files safely, run them through SVGO (or a tool built on it), round coordinates to two or three decimal places, keep the <code>viewBox<\/code>, and compare the result with the original before you replace it. That removes the editor clutter that design tools add, often cutting icons to a fraction of their exported size, without changing how they look.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The catch is that SVGs are code, and some optimisations can break things that depend on that code: animations, CSS selectors, sprites and screen reader labels. This guide covers what optimisation removes, what to watch for, and the settings that are safe for most sites.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-takeaways is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">Key takeaways<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Optimisation strips metadata, comments, hidden elements and default values, and shortens numbers.<\/li>\n\n\n<li>Decimal precision has the biggest effect. Two or three places suit most icons and logos.<\/li>\n\n\n<li>Keep the <code>viewBox<\/code> so the SVG scales. SVGO 4 no longer removes it by default.<\/li>\n\n\n<li>Be careful with IDs, merged paths and titles if your SVG is animated, styled with CSS or used in a sprite.<\/li>\n\n\n<li>Always compare before and after, and serve SVGs with gzip or Brotli compression.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">What SVG optimisation removes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An icon exported from Figma, Illustrator or Inkscape contains far more than the drawing. Typical extras include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Editor metadata and namespaces, such as <code>sodipodi<\/code> or <code>inkscape<\/code> attributes and generator comments.<\/li>\n\n\n<li>Hidden layers, empty groups and unused definitions.<\/li>\n\n\n<li>Attributes set to their default value, which the browser would assume anyway.<\/li>\n\n\n<li>Coordinates with six or more decimal places, such as <code>12.000000<\/code> or <code>4.2500003<\/code>.<\/li>\n\n\n<li>Transforms that can be folded into the path data, and shapes that can be written more compactly as paths.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a small example before and after:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- Before --&gt;\n&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;!-- Generator: Design App 12.0 --&gt;\n&lt;svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"24px\" height=\"24px\" viewBox=\"0 0 24 24\" version=\"1.1\"&gt;\n  &lt;title&gt;arrow&lt;\/title&gt;\n  &lt;g id=\"Page-1\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\"&gt;\n    &lt;g id=\"arrow\" fill=\"#000000\"&gt;\n      &lt;path d=\"M12.000000,4.000000 L10.590000,5.410000 L16.170000,11.000000 L4.000000,11.000000 L4.000000,13.000000 L16.170000,13.000000 L10.590000,18.590000 L12.000000,20.000000 L20.000000,12.000000 Z\"\/&gt;\n    &lt;\/g&gt;\n  &lt;\/g&gt;\n&lt;\/svg&gt;\n\n&lt;!-- After --&gt;\n&lt;svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\"&gt;&lt;title&gt;arrow&lt;\/title&gt;&lt;path d=\"m12 4-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z\"\/&gt;&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That small icon drops from 542 bytes to 154, about 72% smaller, and renders identically. The same kinds of savings apply to larger files, where the clutter adds up across hundreds of paths.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Decimal precision: the biggest win<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Path data is mostly numbers, so how many decimal places you keep matters more than any other setting. A 24 \u00d7 24 icon drawn to six decimal places is specifying positions far smaller than a pixel.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Precision<\/th><th>Good for<\/th><th>Risk<\/th><\/tr><\/thead><tbody><tr><td>3 decimal places<\/td><td>Detailed illustrations, maps<\/td><td>Very low<\/td><\/tr><tr><td>2 decimal places<\/td><td>Most icons and logos<\/td><td>Low<\/td><\/tr><tr><td>1 decimal place<\/td><td>Simple geometric icons<\/td><td>Curves can shift slightly<\/td><\/tr><tr><td>0 decimal places<\/td><td>Pixel-aligned shapes only<\/td><td>Visible distortion on curves<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Start at 2 or 3 and only go lower if the before-and-after comparison shows no change.<\/p>\n\n\n<aside class=\"tool-card tool-card--inline\"><span class=\"swatch\" style=\"background:linear-gradient(135deg,#5ce1c6,#2f4bff)\" aria-hidden=\"true\"><\/span><div class=\"tool-card__body\"><p class=\"tool-card__eyebrow\">Free tool<\/p><p class=\"tool-card__name\">SVG optimiser<\/p><p class=\"tool-card__blurb\">Clean and minify SVG files with SVGO, in your browser.<\/p><\/div><a class=\"btn primary\" href=\"https:\/\/refracttools.com\/svg-optimiser\/\">Try it free <span aria-hidden=\"true\">\u2192<\/span><\/a><\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">What can break, and how to avoid it<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">The viewBox<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>viewBox<\/code> is what lets an SVG scale to any size. Older SVGO setups removed it when width and height were present, which left icons that wouldn&#8217;t resize with CSS. SVGO 4 dropped <code>removeViewBox<\/code> from its default preset for exactly this reason. If you remove anything, remove the fixed <code>width<\/code> and <code>height<\/code> and keep the <code>viewBox<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">IDs used by CSS, JavaScript or sprites<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Optimisers shorten or remove IDs they think are unused. That is safe for a standalone icon, but it breaks anything that targets those IDs from outside the file: CSS like <code>#logo-mark { fill: red; }<\/code>, a script that animates <code>#wheel<\/code>, or a sprite referenced with <code>&lt;use href=\"#icon-search\"&gt;<\/code>. If your SVG is referenced like this, turn off ID clean-up.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Merged paths<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Merging several paths into one saves bytes, but if you animate or colour parts separately, they need to stay separate. Keep merging off for animated SVGs and multi-colour icons that are themed with CSS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Titles and accessibility<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>&lt;title&gt;<\/code> inside an SVG gives screen readers a name for it. SVGO 4 also stopped removing titles by default. Keep them for meaningful icons and illustrations; for purely decorative SVGs, use <code>aria-hidden=\"true\"<\/code> on the element instead.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-callout is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\"><strong>Tip:<\/strong> SVG files can contain scripts and event handlers. If you accept SVG uploads from users or paste third-party SVGs inline, remove them. An SVG shown with an <code>&lt;img&gt;<\/code> tag can&#8217;t run scripts, but inline SVG can.<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Safe settings for SVGO<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you run SVGO yourself, this configuration is a good default for icons that are also styled or referenced from CSS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ svgo.config.mjs (SVGO 4)\nexport default {\n  multipass: true,\n  floatPrecision: 2,\n  plugins: [\n    {\n      name: 'preset-default',\n      params: {\n        overrides: {\n          cleanupIds: false, \/\/ keep IDs used by CSS, JS or &lt;use&gt;\n        },\n      },\n    },\n    'removeDimensions', \/\/ drop width\/height, keep viewBox\n  ],\n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For standalone icons nobody references by ID, you can leave <code>cleanupIds<\/code> on for slightly smaller files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Don&#8217;t forget server compression<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">SVG is text, so it compresses very well with gzip or Brotli. Most hosts compress HTML, CSS and JavaScript automatically but some miss <code>image\/svg+xml<\/code>. Check the response headers for <code>content-encoding: gzip<\/code> or <code>br<\/code> when an SVG loads. Optimising the file and compressing it in transit work together.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Optimise your SVGs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Drop your files into the <a href=\"https:\/\/refracttools.com\/svg-optimiser\/\">SVG optimiser<\/a>. It runs SVGO in your browser, so nothing is uploaded, shows each file before and after with the size saving, and lets you choose the precision and whether to keep titles. Scripts are removed by default. If you need a PNG version of an SVG for an app store or social image, the <a href=\"https:\/\/refracttools.com\/image-converter\/\">image converter<\/a> renders it at 2\u00d7, 3\u00d7 or 4\u00d7. And if the SVG is your logo, the <a href=\"https:\/\/refracttools.com\/favicon-generator\/\">favicon generator<\/a> can turn it into a full icon set; the <a href=\"https:\/\/refracttools.com\/blog\/image-optimisation\/favicon-sizes\/\">favicon sizes guide<\/a> explains which files you need.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Source: <a href=\"https:\/\/svgo.dev\/docs\/migrations\/migration-from-v3-to-v4\/\" rel=\"noopener\" target=\"_blank\">SVGO: migration from v3 to v4<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Run SVGs through SVGO, keep the viewBox, round to two or three decimal places and compare before and after. Here is what optimisation removes and what can break.<\/p>\n","protected":false},"author":1,"featured_media":51,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_refract_tool":"svg-optimiser","footnotes":""},"categories":[9],"tags":[5,17,30],"class_list":["post-52","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-image-optimisation","tag-image-tools","tag-performance","tag-svg"],"_links":{"self":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":1,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/52\/revisions\/70"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media\/51"}],"wp:attachment":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}