HTML SVG <filter>

Beginner
9 min read
Updated: Nov 2026
5 examples
Live preview

Definition and Usage

The SVG <filter> element groups filter primitives (like <feGaussianBlur>) into a reusable effect. It is never drawn by itself — shapes reference it with filter="url(#id)" (or the CSS filter property).

Put filters in <defs>, give each an id, then apply that id to circles, rects, text, or groups.

Baseline · Widely available.

Core SVG filters (blur, offset, merge) are stable across modern browsers since about July 2015. Some newer primitives vary — keep demos simple and test targets.

Room for the effect.

Default filter region is roughly x/y = -10% and width/height = 120% so soft edges are not clipped.

Deprecated: xlink:href.

Do not reuse filters via xlink:href on <filter>. Define the primitives you need (or duplicate a short filter) instead.

Syntax

filter.html
<svg width="230" height="120" viewBox="0 0 230 120"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Sharp and blurred circles">
  <defs>
    <filter id="blurMe" x="-20%" y="-20%" width="140%" height="140%">
      <feGaussianBlur in="SourceGraphic" stdDeviation="5" />
    </filter>
  </defs>

  <circle cx="60" cy="60" r="40" fill="#16a34a" />
  <circle cx="170" cy="60" r="40" fill="#16a34a" filter="url(#blurMe)" />
</svg>

Pattern: define → give an id → apply with url(#id).

Attributes

Key pieces of the filter pipeline:

NameDescriptionTry it
idRequired handle for url(#…)Try it
x y width heightFilter region (defaults ~-10% / 120%)Try it
filterUnitsobjectBoundingBox (default) or userSpaceOnUseTry it
filter="url(#id)"Apply the filter on a shapeTry it
feGaussianBlurSoft blur via stdDeviationTry it
feDropShadowShort-form drop shadowTry it
feOffset / feMergeClassic shadow building blocksTry it

Global Attributes

The <filter> tag also supports the Global Attributes in HTML (for example id, class, lang, title) when used in an HTML document.

Live Preview

Change blur strength. The left circle stays sharp; the right one uses url(#liveBlur).

5

Higher stdDeviation means a softer blur.

SVG

stdDeviation="5"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Gaussian Blur

Compare a sharp circle with a blurred copy.

HTML
<svg width="230" height="120" viewBox="0 0 230 120"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Sharp and blurred green circles">
  <defs>
    <filter id="blur5" x="-20%" y="-20%" width="140%" height="140%">
      <feGaussianBlur in="SourceGraphic" stdDeviation="5" />
    </filter>
  </defs>
  <circle cx="60" cy="60" r="40" fill="#16a34a" />
  <circle cx="170" cy="60" r="40" fill="#16a34a" filter="url(#blur5)" />
</svg>
Try It Yourself

How It Works

  1. Declare <filter id="blur5"> inside <defs>.
  2. Add feGaussianBlur with stdDeviation.
  3. Expand the region so the blur is not clipped.
  4. Apply with filter="url(#blur5)" on the second circle.

Example 2 — Classic Drop Shadow

Offset, blur, then merge with the original graphic.

HTML
<svg width="200" height="160" viewBox="0 0 200 160"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Rectangle with classic drop shadow">
  <defs>
    <filter id="drop" x="-30%" y="-30%" width="160%" height="160%">
      <feOffset in="SourceAlpha" dx="6" dy="6" result="off" />
      <feGaussianBlur in="off" stdDeviation="3" result="blur" />
      <feMerge>
        <feMergeNode in="blur" />
        <feMergeNode in="SourceGraphic" />
      </feMerge>
    </filter>
  </defs>
  <rect x="40" y="30" width="100" height="70" rx="8"
        fill="#2563eb" filter="url(#drop)" />
</svg>
Try It Yourself

How It Works

  1. feOffset shifts the alpha mask for the shadow.
  2. feGaussianBlur softens that offset layer.
  3. feMerge draws blur first, then SourceGraphic.
  4. Use result names so each step feeds the next.

Example 3 — feDropShadow Shortcut

One primitive for a common shadow.

HTML
<svg width="200" height="160" viewBox="0 0 200 160"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Circle with feDropShadow">
  <defs>
    <filter id="easyShadow" x="-40%" y="-40%" width="180%" height="180%">
      <feDropShadow dx="4" dy="6" stdDeviation="3"
                    flood-color="#0f172a" flood-opacity="0.35" />
    </filter>
  </defs>
  <circle cx="100" cy="70" r="45" fill="#ea580c" filter="url(#easyShadow)" />
</svg>
Try It Yourself

How It Works

  1. feDropShadow combines offset + blur in one step.
  2. dx / dy move the shadow.
  3. flood-color / flood-opacity tint the shadow.
  4. Still expand the filter box so soft edges show.

Example 4 — Grayscale with feColorMatrix

Turn color into gray with a matrix.

HTML
<svg width="230" height="120" viewBox="0 0 230 120"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Color and grayscale rectangles">
  <defs>
    <filter id="gray">
      <feColorMatrix type="saturate" values="0" />
    </filter>
  </defs>
  <rect x="20" y="30" width="80" height="60" fill="#7c3aed" />
  <rect x="130" y="30" width="80" height="60" fill="#7c3aed" filter="url(#gray)" />
</svg>
Try It Yourself

How It Works

  1. feColorMatrix remaps pixel colors.
  2. type="saturate" values="0" removes color.
  3. Same fill on both rects; only the filter changes the look.
  4. Useful for muted icons without editing the fill.

Example 5 — One Filter, Many Shapes

Reuse the same blur on a circle and a rect.

HTML
<svg width="260" height="120" viewBox="0 0 260 120"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Shared blur on circle and rectangle">
  <defs>
    <filter id="soft" x="-25%" y="-25%" width="150%" height="150%">
      <feGaussianBlur in="SourceGraphic" stdDeviation="3" />
    </filter>
  </defs>
  <circle cx="60" cy="60" r="35" fill="#2563eb" filter="url(#soft)" />
  <rect x="130" y="30" width="90" height="60" rx="6"
        fill="#16a34a" filter="url(#soft)" />
</svg>
Try It Yourself

How It Works

  1. Define the filter once with a stable id.
  2. Point every shape at url(#soft).
  3. Change the filter in one place to update all uses.
  4. Ids must be unique inside the document.

Edge Cases & Pitfalls

Most filter bugs are ids, clipping, or missing primitives.

region

Blur or shadow looks cut off

Widen x/y/width/height on <filter> so the soft edge fits.

id

url(#id) must match

Typos or duplicate ids break the reference. Keep ids unique and exact.

perf

Heavy filters cost

Large blurs on big graphics can be slow. Prefer modest stdDeviation values.

defs

Filter is not painted alone

<filter> only affects elements that reference it. Nothing appears until you apply filter="url(#…)".

Browser Support

Core SVG <filter> primitives are supported in every modern browser.

✓ Baseline · Widely available

SVG <filter>

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support common primitives. feDropShadow is modern-browser friendly; Internet Explorer has limited filter support.

95% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer 10+
Partial
<filter> Widely supported

Bottom line: Safe for production blur and shadows in modern browsers. Prefer feGaussianBlur + merge for widest reach; use feDropShadow when targeting current engines.

Key Takeaways

  • Define in <defs> with a unique id.
  • Apply with filter="url(#id)".
  • Expand the region for blur and shadows.
  • Reuse one filter on many shapes.

One line: primitives in <filter>, apply with url(#id).

Default CSS Settings

<filter> itself has no painted look. The CSS filter property can also point at SVG filters:

defaults.css
/* Conceptual — filter defs are not painted */
filter {
  /* region defaults ≈ -10% / 120% in SVG */
}

/* Optional: apply SVG filter from CSS */
.icon {
  filter: url(#blur5);
}

Prefer the SVG filter attribute in these lessons so the effect stays inside the graphic.

Frequently Asked Questions

Define a <filter> (usually in <defs>) with an id and one or more primitives. Apply it with filter="url(#id)" on a shape, or with the CSS filter property.
Blur and shadows need extra space. Expand the filter region with x, y, width, and height on <filter> (defaults are already about -10% / 120%).
Use feDropShadow for a short form, or combine feOffset, feGaussianBlur, and feMerge for a classic pipeline.
Yes. Define it once with an id, then apply filter="url(#thatId)" to as many elements as you need.
No. <filter> is a definition only. Effects appear on elements that reference it.
CSS filter is great for whole HTML elements. SVG filters shine for reusable defs and multi-primitive pipelines inside the SVG.

Next: SVG Patterns

Learn tiled fills with <pattern> and url(#id) paints.

SVG Patterns →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful