Filter
Filters are SVG's mechanism to create sophisticated effects.
Filters are defined by the <filter> element, which should be put in the <defs> section of your SVG, and you must give the filter an id so you can reference it elsewhere.
(You would reference the filter using the filter attribute.)
How filter primitive works
Between the <filter> tags, goes a list of primitives (the <fe*> tags). Primitives are basic operations like blurring, adding a lighting effect, etc.
They take in images specified by the in and/or in2 attributes, and store the result in a name specified by the result attribute.
Primitive global attributes
All primitives accept these attributes:
result— name for the filter primitive result; the name can be referenced in theinorin2attribute of another primitive.x,y,width,height— position and dimension of the filter primitive viewport (to "crop out" the filter primitive layer)
Primitive in and in2 attributes
For in or in2, you can specify one of the following:*
SourceGraphic— use the graphic elements that use the<filter>SourceAlpha— use the graphic elements that use the<filter>, but only use the alpha channel (the colors will become gray)- The name from a
resultattribute
The default value is SourceGraphic for first filter primitive, otherwise it's the result of the previous filter primitive.

in values. The image consists a group of 3 RGB circles on top of a vertical rectangle. The blur filter effect is applied on the group of RGB circles. (Source: W3)(*) I omit BackgroundImage, BackgroundAlpha, FillPaint, and StrokePaint as I don't understand what the spec is saying, and it's not consistent on Chrome and Firefox. (See the in attribute test)
Filter SVG element
<filter>
x— x coordinate offset of the filtery— y coordinate offset of the filterwidth— width the filterheight— height of the filterfilterUnits— defines the coordinate system for attributesx,y,width,height; specifyuserSpaceOnUse(use viewport/absolute coordinate) orobjectBoundingBox(use the bounding box of the element that references the filter, with coordinate values ranging from 0 to 1)primitiveUnits— defines the coordinate system for the filter primitives (the children of<filter>); specifyuserSpaceOnUse(use viewport/absolute coordinate) orobjectBoundingBox(use the bounding box of the element that references the filter, with coordinate values ranging from 0 to 1)
Primitive SVG elements
result, x, y, width, height.<feBlend>
Composes objects together and apply a blending mode.
in— first input (the "top" image)in2— second input (the "bottom" image)mode— the blending mode to use; specify:normal,darken,lighten,multiply,screen,overlay,color-dodge,color-burn,hard-light,soft-light,difference,exclusion,hue,saturation,color, orluminosity
<feColorMatrix>
Changes colors based on a transformation matrix. (The final RGBA value will be clamped between 0 and 1.)
in— the input imagetype—matrix,saturate,hueRotate, orluminanceToAlphavalues— depends ontype(if you specifytypeother thanmatrix, it will construct the matrix based on the value oftypeandvalues):- for
type="matrix": input the first four rows of the matrix (ignore the last row because it's a constant) - for
type="saturate": input a single real number from 0 to 1 - for
type="hueRotate": input a single real number (representing the degrees) - for
type="luminanceToAlpha":valuesis not required
- for
<feComponentTransfer>
Performs remapping for each color component. It allows operations like brightness adjustment, contrast adjustment, color balance, or thresholding (MDN).
in— the input image
<feComponentTransfer> expects you to provide these "transfer function" children elements: <feFuncR>, <feFuncG>, <feFuncB>, <feFuncA>. Each transfer function element accepts:
type— defines how to map each color component to . specify one of:identity—table— use linear interpolation using values given intableValues.tableValuescontains values (each ranging from 0 to 1), specifying the "start" and "end" values for evenly sized interpolation regions. A color would fall into one of these interpolation regions; you would then perform a linear interpolation using the "start" and "end" values of the region.discrete— use the step function using values given intableValues.tableValuescontains values (each ranging from 0 to 1), specifying a step function consisting of evenly sized steps. A color would fall into one of these "steps", you just use thetableValuesvalue representing the step.linear— expects you to giveslopeandinterceptattributes, representing and respectively. Then, .gamma— expects you to giveamplitude,exponent, andoffsetattributes, representing , , and respectively. Then, .
<feComposite>
Performs Porter–Duff compositing operations.
in— first input (the "top" image)in2— second input (the "bottom" image)operator—over,in,out,atop,xor,lighterorarithmetic(default isover)k1,k2,k3,k4— required whenoperator="arithmetic". With and representing pixel channel values ofinandin2respectively, the result pixel channel value is given as

operator values (Source: Codepen)<feConvolveMatrix>
Applies a matrix convolution filter effect. Operations that can be achieved through convolution include blurring, edge detection, sharpening, embossing and beveling (MDN).
A convolution combines pixels in the input image with its neighboring pixels to produce a resulting image. The convolution matrix (the "convolution kernel") is an orderY () by orderX () matrix; together with divisor , bias , targetX , targetY , yield the calculation:
in— the input imageorder— size of the kernel matrix (default is 3); if you specify two numbers (e.g.3 4), the first number representsorderX(number of columns), and the second number respresentsorderY(number or rows)kernelMatrix— space-separated list of numbers, representing the kernel matrixdivisor— represents in the equation above (default is sum of all values inside thekernelMatrix)bias— represents in the equation above (default is 0)targetX— offsets the x positioning of the kernel matrix relative to the target pixel (default is centered around the target pixel, i.e. )targetY— offsets the y positioning of the kernel matrix relative to the target pixel (default is centered around the target pixel, i.e. )edgeMode— how to handle the case near the edge of the input image; specifyduplicate(default),wrap, ornonepreserveAlpha— a value offalse(default) indicates that the convolution will apply to all channels (including alpha channel)
<feDiffuseLighting>
Lights an image using the alpha channel as a bump map. (Bump mapping is a "texture mapping technique in computer graphics for simulating bumps and wrinkles on the surface of an object," Wikipedia.)
in— the input imagesurfaceScale— height of surface for an alpha value of 1diffuseConstant— (diffuse reflection constant) in Phong reflection modellighting-color— color of the light
<feDiffuseLighting> expects you to provide the light sources using <fePointLight>, <feDistantLight>, or <feSpotLight> children elements.
<feSpecularLighting>
Lights an image using the alpha channel as a bump map. (Bump mapping is a "texture mapping technique in computer graphics for simulating bumps and wrinkles on the surface of an object," Wikipedia.)
in— the input imagesurfaceScale— height of surface for an alpha value of 1specularConstant— (specular reflection constant) in Phong reflection modelspecularExponent— larger value means more "shiny"lighting-color— color of the light
<feDiffuseLighting> expects you to provide the light sources using <fePointLight>, <feDistantLight>, or <feSpotLight> children elements.
<feDisplacementMap>
Use the pixel values from in2 to spatially displace the pixels from in:
where is the input image (in), is the destination, is the scale, and are the component values of the channel designated by the xChannelSelector and yChannelSelector.
in— input image to be displacedin2— input image that governs how we displaceinscale— displacement scale factor (see above)xChannelSelector— which channel to use to displace the pixels ininalong the x-axis; specifyR,G,B, orA(default isA)yChannelSelector— which channel to use to displace the pixels ininalong the y-axis; specifyR,G,B, orA(default isA)
<feDropShadow>
Creates a drop shadow of the input image.
dx— x offset of the drop shadowdy— y offset of the drop shadowstdDeviation— the standard deviation for the blur operation in the drop shadowflood-color— color of the shadowflood-opacity— opacity of the shadow
<feFlood>
Fills the filter subregion with a color.
flood-color— color of the fillflood-opacity— opacity of the fill
<feGaussianBlur>
Applies a gaussian blur.
in— the input imagestdDeviation— the standard deviation for the blur operationedgeMode— how to handle the case near the edge of the input image; specifyduplicate,wrap, ornone(default)
<feImage>
Fetches the image data from an external source and provides the pixel data as output (if the external source is an SVG image, it is rasterized).
href— URL to the imagepreserveAspectRatio— seepreserveAspectRatio(default isxMidYMid meet)
<feMerge>
Allows you to show/merge multiple results at once.
<feMerge> expects you to put <feMergeNode> elements as its children. (<feMergeNode> only accepts the attribute in.)
<feMorphology>
Erodes or dilates the input image (thickens or thins it).
in— the input imageoperator—erode(default) ordilateradius— radius for the operation
Normal text
Thinned text
Fattened text
<feOffset>
Offsets the input image.
in— the input imagedx— offset in the x axisdy— offset in the y axis
<feTile>
Fill a target rectangle with a repeated, tiled pattern of an input image. The effect is similar to the one of a <pattern>.
in— the input image
<feTurbulence>
Creates an image using Perlin turbulence function.
type— specifyfractalNoiseorturbulence(default)baseFrequency— the base frequency parameter(s) for the noise function (if two numbers are provided, the first number represents the base frequency for the x axis, and the other for the y axis)numOctaves— the number of octaves for the noise function (the higher this number is, the more natural the noise looks, but requires more computation)seed— the starting number for the pseudo random number generatorstitchTilesdefines how the Perlin Noise tiles behave at the border; specifynoStitch(default) orstitch
Light source elements
<fePointLight>
x,y,z— position of light
<feSpotLight>
x,y,z— position of lightpointsAtX,pointsAtY,pointsAtZ— to where the light is pointingspecularExponent— bigger means bricghterlimitingConeAngle— angle in degrees between the spot light axis (between the light source and the point to which it is pointing); no light is projected outside the cone.
<feDistantLight>
azimuth— the direction angle for the light source on the xy-plane (clockwise), from the positive x-axis. (Controls which side/edge of the shape is reflecting the light.)elevation— the direction angle for the light source from the XY plane towards the Z-axis.

References
- Filter effects (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Filter_effects
- <filter> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/filter
- in (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/in
- <feBlend> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feBlend
- <feColorMatrix> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feColorMatrix
- 15.10 Filter primitive ‘feColorMatrix’ (W3C) — https://www.w3.org/TR/SVG11/filters.html#feColorMatrixTypeAttribute
- <feComponentTransfer> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feComponentTransfer
- 9.7.1. Transfer function feFuncR (W3C) — https://drafts.fxtf.org/filter-effects/#feFuncRElement
- <feComposite> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feComposite
- 9.8. Filter primitive feComposite (W3C) — https://drafts.fxtf.org/filter-effects/#feCompositeElement
- <feConvolveMatrix> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feConvolveMatrix
- 15.13 Filter primitive ‘feConvolveMatrix’ (W3C) — https://www.w3.org/TR/SVG11/filters.html#feConvolveMatrixElementTargetXAttribute
- <feDiffuseLighting> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDiffuseLighting
- <feSpecularLighting> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feSpecularLighting
- <feDisplacementMap> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDisplacementMap
- <feDropShadow> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
- <feFlood> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feFlood
- <feGaussianBlur> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feGaussianBlur
- <feImage> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feImage
- <feMerge> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feMerge
- <feMorphology> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feMorphology
- <feOffset> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feOffset
- <feTile> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feTile
- <feTurbulence> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feTurbulence
- 9.21. Filter primitive feTurbulence (W3C) — https://drafts.fxtf.org/filter-effects/#feTurbulenceElement