SVG filters: blur, shadow, color and distortion

Build SVG filter chains with feGaussianBlur, feDropShadow, feColorMatrix and feTurbulence, and learn filter regions, color space and when to avoid filters.

An SVG filter is a small pipeline of image operations that you attach to an element. The element is drawn, converted to pixels, run through the pipeline, and the result is painted in its place. Blurs, shadows, color shifts, noise and distortion all work this way, and they stay editable text in your markup.

The basic structure

A filter lives in a <filter> element with an id. It contains one or more filter primitives, each of which is an element whose name starts with fe. You apply it with the filter attribute or the CSS filter property.

<svg viewBox="0 0 230 120" xmlns="http://www.w3.org/2000/svg">
  <filter id="blurMe">
    <feGaussianBlur stdDeviation="5" />
  </filter>
  <circle cx="60" cy="60" r="50" fill="green" />
  <circle cx="170" cy="60" r="50" fill="green" filter="url(#blurMe)" />
</svg>

The <filter> element is never drawn by itself. MDN’s page notes that it can be applied with the SVG filter attribute or the CSS filter property, on SVG or HTML elements. The CSS property accepts url() pointing at a filter in the same document or in an external file, such as filter: url("file.svg#filter-element-id").

A drop shadow in one primitive

feDropShadow creates a shadow of its input in a single step. Its dx, dy and stdDeviation attributes default to 2, and you can set the shadow color with flood-color and flood-opacity. MDN lists it as widely available across browsers.

Edit the values below. Try a larger stdDeviation and watch the shadow get cut off at the edges.

You can also build a shadow from separate primitives: blur the alpha channel, offset it, then merge it under the original. MDN’s filter tutorial walks through that chain with feGaussianBlur, feOffset and feMerge. It is worth knowing, because it shows how the pieces connect and lets you change each step.

Inputs, results and chaining

Each primitive reads an input and produces a result. The in attribute chooses the input, and result gives the output a name that later primitives can read through in or in2. Two built-in inputs are used most often:

  • SourceGraphic, the element as drawn.
  • SourceAlpha, only the alpha channel of the element.

If you leave in off, the primitive uses the previous primitive’s output. For anything longer than two steps, name your results. It makes the chain readable and avoids surprises when you reorder things.

<filter id="glow">
  <feGaussianBlur in="SourceAlpha" stdDeviation="6" result="halo" />
  <feFlood flood-color="#1f3fe0" result="color" />
  <feComposite in="color" in2="halo" operator="in" result="tinted" />
  <feMerge>
    <feMergeNode in="tinted" />
    <feMergeNode in="SourceGraphic" />
  </feMerge>
</filter>

The chain blurs the shape’s silhouette, fills that blur with a color, and stacks the original on top. The order in feMerge is the stacking order, bottom first.

The filter region

A filter only paints inside its filter region. By default the region is the element’s bounding box, plus 10% on each side: x and y start at -10%, and width and height are 120%. Both MDN and the Filter Effects specification give these defaults.

That padding is enough for small effects. A large blur or a big offset will spill past it and get clipped with a hard edge. When you see a flat cut on a shadow, widen the region:

<filter id="roomy" x="-30%" y="-30%" width="160%" height="160%">

You can also set filterUnits="userSpaceOnUse" and give the region in plain user units, which is useful when the effect should cover a fixed area regardless of the element’s size.

Color matrices and color space

feColorMatrix changes colors. It has four type values: matrix, saturate, hueRotate and luminanceToAlpha. The matrix type takes 20 numbers, four rows of five, where each row computes one output channel as a weighted sum of red, green, blue, alpha and a constant. Results are clamped between 0 and 1. The other types are shortcuts: saturate takes one number (the spec gives 1 as unchanged and 0 as fully gray), hueRotate takes an angle in degrees, and luminanceToAlpha takes no values.

Filter primitives work in linearRGB by default, not sRGB. This is stated in the Filter Effects specification and repeated on the MDN pages for several primitives. Colors can look different from the same colors in CSS. If you want results that match your sRGB colors, set color-interpolation-filters="sRGB" on the <filter> or on a primitive. Check both versions on your own artwork before choosing.

Noise and distortion

feTurbulence generates Perlin-style noise. Its main attributes:

  • baseFrequency: higher values give finer detail. Two values set x and y separately.
  • numOctaves: how many noise layers are summed. More layers add detail and cost.
  • seed: a different seed gives a different pattern.
  • type: fractalNoise for soft, cloudy output, or turbulence for sharper transitions. The default is turbulence.

Noise on its own makes textures. Feed it into feDisplacementMap as in2 and it distorts another image. MDN gives the formula: each output pixel is sampled from the input at a position shifted by scale * (channel - 0.5), so a channel value of 0.5 means no shift. xChannelSelector and yChannelSelector choose which channels of the noise drive each direction.

Change scale to 40 and the letters break apart. Change seed and the same settings produce a different ripple. If you animate baseFrequency or seed, read SVG animation first, including the section on reduced motion.

Filters on HTML and in CSS

The CSS filter property also has built-in functions such as blur(), drop-shadow() and hue-rotate(), and MDN lists the property as widely available. Use those for simple effects on HTML. Reach for an SVG filter and url() when you need primitives the functions do not cover, such as turbulence or displacement. A related point from MDN: filter lists are applied in the order written, so drop-shadow() followed by hue-rotate() changes the shadow’s color too.

Trade-offs

  • Cost. Every filtered element is rasterized and processed. Large regions, big blurs, many octaves of noise and animated filters all add work. The specification advises avoiding rotating or skewing the coordinate system so the filter region maps pixel for pixel to the device. Measure on a real low-end phone, not just your laptop.
  • Clipping. Always check the edges of blurs and shadows.
  • File size. Filters cost few bytes, but check SVG optimization before running a minifier, since filter ids are referenced by name.
  • Alternatives. For hiding or revealing shapes, masks and clipping are lighter than a filter. For positioning and scaling effects, see SVG transforms.

For a broader view of where SVG features differ between browsers and rendering contexts, see SVG browser compatibility.

Sources

Checked against these references on 2026-11-21.