DEV Community

Cover image for How to optimize SVG files for better use in projects?
Edson Junior de Andrade
Edson Junior de Andrade

Posted on • Edited on

How to optimize SVG files for better use in projects?

We often come across large and complex SVG files full of redundancies, which can be a hassle. Fortunately, we can optimize this with SVGO, a tool that reduces the size of SVG files by removing unnecessary data without compromising quality.

How to use it?

To use it, install it globally with the following command:

# npm
npm install -g svgo

# yarn
yarn global add svgo

# pnpm
pnpm add -g svgo
Enter fullscreen mode Exit fullscreen mode

Create an SVGO configuration file in the root of your project with the following command:

echo svgo.config.js
Enter fullscreen mode Exit fullscreen mode

Open the svgo.config.js file and start configuring it. Below is an example, but feel free to explore other possibilities and even add plugins:

module.exports = {
  multipass: false, /* Performs multiple passes over the file to try to find more possible optimizations.*/
  plugins: [
    { name: 
      'removeViewBox', active: false }, /* Keep the viewBox to avoid clipping. */
    { name: 'removeDimensions', active: true }, /* Remove width and height to allow scalability. */
  ]
};
Enter fullscreen mode Exit fullscreen mode

Go to the location where the svg you want to optimize is located and run the following command:

svgo file_name.svg -o file_name.min.svg
Enter fullscreen mode Exit fullscreen mode

That's it! Your svg is optimized, all the redundancies and unnecessary parameters that come with an svg have been removed and it is ready to use.

For more complete content, visit the SVGO documentation

I ❤️ building dashboards for my customers

I ❤️ building dashboards for my customers

Said nobody, ever. Embeddable's dashboard toolkit is built to save dev time. It loads fast, looks native and doesn't suck like an embedded BI tool.

Get early access

Top comments (0)

For IaC Practitioners, By IaC Practitioners

For IaC Practitioners, By IaC Practitioners

Learn how to embed security from day one using policy-as-code, AI-driven scanning, and strong collaboration between engineering and cybersecurity teams at IaCConf on Wednesday August 27, 2025.

Join us on August 27

👋 Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay