Search code examples
svgsvg-filters

SVG blur filter has hard borders


I have this code in which I want to add a feGaussianBlur to a <rect/> element:

<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="1000">
    <defs>
        <filter id="f">
            <feGaussianBlur in="SourceGraphic" stdDeviation="20"/>
        </filter>
    </defs>
    <rect x="100" y="100" height="200" width="180" fill="green" filter="url(#f)"/>
</svg>

The output is rendered like this: enter image description here

As you can see, that the sides are not softened. The sides have a hard border.
But, when I decrease the value of the stdDeviation, it works well. Here is the output if the value of stdDeviation is set to 10:

enter image description here

Why is it not working properly with a value greater than 10? And what can I do to achieve it?


Solution

  • Expand the filter region

    x="-20%" y="-20%" width="150%" height="150%"

    See Filter effects region

    <svg xmlns="http://www.w3.org/2000/svg" width="1000" height="1000">
        <defs>
            <filter id="f" x="-20%" y="-20%" width="150%" height="150%">
                <feGaussianBlur in="SourceGraphic" stdDeviation="20"/>
            </filter>
        </defs>
        <rect x="100" y="100" height="200" width="180" fill="green" filter="url(#f)"/>
    </svg>