Remove Hidden Elements
Default
Remove hidden or invisible elements from the document. This can be elements with 0 width and height defined, or elements that were just hidden with CSS.
This plugin ignores non-rendering elements, such as <clipPath>
and <linearGradient>
, which still apply regardless of styles, unless they are unused.
Refer to the parameters for the conditions this plugin looks for. All checks enabled by default.
Usage
- Basic
- Parameters
svgo.config.js
module.exports = {
plugins: [
"removeHiddenElems"
]
}
svgo.config.js
module.exports = {
plugins: [
{
name: "removeHiddenElems",
params: {
isHidden: true,
displayNone: true,
opacity0: true,
circleR0: true,
ellipseRX0: true,
ellipseRY0: true,
rectWidth0: true,
rectHeight0: true,
patternWidth0: true,
patternHeight0: true,
imageWidth0: true,
imageHeight0: true,
pathEmptyD: true,
polylineEmptyPoints: true,
polygonEmptyPoints: true
}
}
]
}
Parameters
isHidden
Removes elements where
visibility
ishidden
, unless a child element hasvisibility
set tovisible
.displayNone
Removes elements where
display
isnone
.opacity0
Removes element where
opacity
is0
.circleR0
ellipseRX0
ellipseRY0
rectWidth0
rectHeight0
patternWidth0
patternHeight0
imageWidth0
imageHeight0
pathEmptyD
Remove
<path>
elements whered
is not set or empty. Does not apply for single point paths associated with amarker
.polylineEmptyPoints
Removes
<polyline>
elements with no points defined.polygonEmptyPoints
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: [ "removeHiddenElems" ] } render(<SvgoPreview svg={svg} svgoConfig={svgoConfig}/>);
Result
Loading...