PerfectVector
Studio
By Irene Kim

SVG Gaussian Blur: Set Horizontal and Vertical Blur

Control horizontal and vertical SVG blur with feGaussianBlur stdDeviation. Reproduce the effect with three values and check which edge it changes.

4 min read
On this page

Use two numbers on SVG's feGaussianBlur to control the two axes. The first stdDeviation value controls horizontal blur and the second controls vertical blur. Use stdDeviation="8 0" for horizontal blur only, stdDeviation="0 8" for vertical blur only, or stdDeviation="8" to apply 8 on both axes. Filter Effects Level 1

Choose the axis you want to soften

Standard deviation is the width parameter of the Gaussian used along each axis. The numbers are measured in the filter primitive's coordinate system. This example sets primitiveUnits="userSpaceOnUse", so the values use the SVG's user units. A value of 8 gives a stronger spread than 2 on the same axis, with the object and coordinate system held fixed. SVG 1.1 Gaussian blur

AttributeVisible effect on a filled rectangle
stdDeviation="8 0"Paint spreads past the left and right edges. The top and bottom stay sharp.
stdDeviation="0 8"Paint spreads past the top and bottom edges. The sides stay sharp.
stdDeviation="8"Paint spreads past all four edges.

When checking a directional blur, start at the middle of an edge, away from the corners. The left and right edges are vertical lines, so horizontal spread softens them.

Run the same rectangle three ways

Save this SVG and open it in a renderer that supports SVG filters. Change the stdDeviation value to 0 8 and then to 8. Keep the rectangle and filter region fixed.

<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120"
     viewBox="0 0 120 120">
  <defs>
    <filter id="blur" x="0" y="0" width="120" height="120"
            filterUnits="userSpaceOnUse" primitiveUnits="userSpaceOnUse">
      <feGaussianBlur in="SourceGraphic" stdDeviation="8 0"/>
    </filter>
  </defs>
  <rect x="40" y="40" width="40" height="40" fill="#176e65"
        filter="url(#blur)"/>
</svg>

In our 120 × 120 resvg 0.47.0 render, the horizontal version had nonzero alpha at (35, 60), five units left of the rectangle, and zero at (60, 35), five units above it. The vertical version reversed those results. The single-value version had nonzero alpha at both sample points.

Three equal SVG rectangles with horizontal-only, vertical-only, and two-axis Gaussian blur
The same rectangle rendered with 8 0, 0 8, and 8. Compare the centers of the side and top edges to see which axis changes.

Separate a wrong axis from a clipped blur

A sharp line at the outer edge of an otherwise soft blur can come from the filter region. Temporarily give the filter more room while keeping the primitive units and stdDeviation unchanged. If the missing paint returns, inspect the SVG filter region and viewport. If the paint still spreads along the wrong axis, check the order of the two values and any transform applied to the object. The SVG coordinate system follows the applicable transforms. SVG 2 coordinate systems

Blur changes the rendered paint. If the outline also looks soft with the filter removed, inspect the original shape or embedded bitmap before adjusting the filter. The SVG lighting guide shows another use of blur to soften the edge of an effect.

FAQ

Does a single stdDeviation value apply to both axes?

Yes. A single value supplies the standard deviation for both horizontal and vertical blur. For example, 8 has the same meaning as 8 8.

Can I blur along just one axis?

Yes. Give the other axis a value of zero. Use 8 0 to spread paint horizontally or 0 8 to spread it vertically.

What does stdDeviation="0 0" do?

Both axes have zero spread, so the primitive passes through its input image without Gaussian blur.

Start with source artwork you can edit

PerfectVector can recover editable SVG paths from flat raster artwork when you only have a PNG or JPG. If you need a clean outline to blur in SVG, convert the source image to vector, inspect its paths with the filter off, then apply the blur to the outline you want to soften.

Sources

  1. W3C Filter Effects Level 1, feGaussianBlur — Defines axis order and the one-value shorthand.
  2. W3C SVG 1.1, Gaussian blur and coordinate units — Specifies the units and behavior of Gaussian blur.
  3. W3C SVG 2, coordinate systems and transforms — Explains how transforms establish SVG user space.

More from the blog

PerfectVector

Start with a cleaner SVG
that is easier to edit

Vectorize and inspect previews for free, with no daily limit.