Skip to main content

Prefix IDs

Prefix element IDs and class names with the filename or another arbitrary string.

Usage

svgo.config.js
module.exports = {
plugins: [
"prefixIds"
]
}

Parameters

delim

Content to insert between the prefix and original value.

prefix

Either a string or a function that resolves to a string.

prefixIds

If to prefix id attributes.

prefixClassNames

If to prefix classes in the class attribute.

Demo

Live Editor
const svg = `
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox=" 0 0  150 100 " width="150">
  <!-- Created with love! -->
  <defs>
    <ellipse cx="50" cy="50.0" rx="50.00" ry="auto" fill="black" id="circle"/>
  </defs>
  <g>
    <use href="#circle" transform="skewX(16)"/>
    <rect id="useless" width="0" height="0" fill="#ff0000"/>
  </g>
</svg>
`;

const svgoConfig = {
  js2svg: { indent: 2, pretty: true },
  plugins: [
    "prefixIds"
  ]
}

render(<SvgoPreview svg={svg} svgoConfig={svgoConfig}/>);
Result
Loading...

Implementation