Skip to content

Instantly share code, notes, and snippets.

@antoineMoPa
Created July 11, 2025 19:58
Show Gist options
  • Select an option

  • Save antoineMoPa/ffb90095d3defc37141b43945e04c819 to your computer and use it in GitHub Desktop.

Select an option

Save antoineMoPa/ffb90095d3defc37141b43945e04c819 to your computer and use it in GitHub Desktop.

Inlining SVG styles easily with svgo

First install svgo

npm install -g svgo

Write this config

svgo.config.js

module.exports = {
  multipass: true,
  plugins: [
    {
      name: 'inlineStyles',
      params: {
        onlyMatchedOnce: false, // make sure all styles are inlined
      },
    },
    {
      name: 'convertStyleToAttrs',
    },
    {
      name: 'removeViewBox',
      active: false, // keep viewBox if you want to retain responsiveness
    },
    {
      name: 'removeUnknownsAndDefaults',
      active: false, // keep defaults just in case
    },
  ],
};

Run svgo

mkdir -p inlined && for f in *.svg; do svgo --config svgo.config.js -i "$f" -o "inlined/${f%.svg}_inlined.svg"; done

files will appear in ./inlined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment