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:
-
Blur: Blur the image, through the
element. -
Shadow: Add a shadow effect to the image, through the
element. -
Brightness, Contrast Adjustment: Adjust the brightness and contrast of the image, through the
element. -
Color Matrix: Modify the colors of the image through color matrix operations, through the
element. -
Blend Mode: Blend two images together, through the
element.
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
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
styleattribute.
By using SVG filters, you can add various visual effects to SVG graphic elements, giving them a more vivid and diverse appearance.