Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

SVG Blur Effect – Gaussian Blur

SVG Blur Effect

In SVG, the blur effect can be achieved through the element, which uses the Gaussian blur algorithm to blur the image.

The blur effect can be used to create various visual effects such as soft shadows, depth of field, and blurred backgrounds.

element:

The element is used to apply Gaussian blur to an image, and it has two main parameters:

The following code defines a blur filter and then applies it to a red-filled rectangle, giving the rectangle a blurred effect; stdDeviation="5" means the standard deviations in both the horizontal and vertical directions are 5, i.e. the blur degree is 5 pixels.

Example

 

 

   

 

 

 

 

Example 1

The element is used to create the blur effect:

Below is the SVG code:

Example

 

   

     

   

 

 

  fill="yellow" filter="url(#f1)" />

Try it »

Click to view:View SVG File.

Code analysis:

  • The element's id attribute defines a unique name for a filter
  • The element defines the blur effect
  • The part in="SourceGraphic" defines that the effect is created from the entire image
  • The stdDeviation attribute defines the amount of blur
  • The element's filter attribute is used to link the element to the "f1" filter

Notes

  • The blur effect can be applied to any SVG graphic element, including rectangles, circles, paths, etc.

  • Parameters of the blur effect stdDeviation can be adjusted as needed to obtain a suitable degree of blur.

  • The blur effect can be combined with other filter effects, such as shadows, blend modes, etc.

By using element, you can add a blur effect to SVG graphic elements, giving them a soft, blurred appearance and thus achieving various visual effects.