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

SVG Filters

SVG Filters


SVG filters are a powerful graphic effect technique that can be used to achieve various visual effects, such as blur, shadows, lighting, etc.

Filters can be applied to SVG graphic elements, such as rectangles, circles, paths, etc., as well as SVG text elements, giving them different appearances and effects.

Basic Syntax

SVG filters are usually defined using the element, and applied through the filter attribute to the target element.



  

  

    

  

  

  

  



Filter Effects

SVG filters can achieve a variety of effects; common filter effects include:

The following code defines a blur filter and then applies it to a red-filled rectangle, giving the rectangle a blurred effect.

Example

 

 

   

 

 

 

 

Try it »

The filters available in SVG are:

  • feBlend - A filter that combines with an image
  • feColorMatrix - Used for color filter conversion
  • feComponentTransfer
  • feComposite
  • feConvolveMatrix
  • feDiffuseLighting
  • feDisplacementMap
  • feFlood
  • feGaussianBlur
  • feImage
  • feMerge
  • feMorphology
  • feOffset - Filter the shadow
  • feSpecularLighting
  • feTile
  • feTurbulence
  • feDistantLight - Used for lighting filtering
  • fePointLight - Used for lighting filtering
  • feSpotLight - Used for lighting filtering

Remark In addition, you can use multiple filters on each SVG element!

Notes

  • SVG filters can be combined; multiple filter effects can be defined in one element.

  • Each filter effect has different parameters that can be adjusted, such as the standard deviation parameter of the blur filter, the offset and blur radius of the shadow filter, etc.

  • SVG filters can be used together with CSS stylesheets, or defined directly on SVG elements using the style attribute.

By using SVG filters, you can add various visual effects to SVG graphic elements, giving them a more vivid and diverse appearance.