<filter>
Definition
Declare reusable effects inside <defs> with a unique id.

SVG filters add blur, shadows, glows, and colour effects to vector shapes without leaving SVG. This tutorial covers defining a <filter> in <defs>, applying it with filter="url(#id)", common primitives, expanding the filter region, five worked examples, and how filters compare to CSS effects.
Definition
Declare reusable effects inside <defs> with a unique id.
Apply
Attach effects to shapes with filter="url(#filterId)".
Pipeline steps
Chain feGaussianBlur, feOffset, feColorMatrix, and feMerge.
feGaussianBlur
Soften edges and create glow with stdDeviation.
Offset + blur
Build shadows by offsetting alpha, blurring, then merging.
Avoid clipping
Expand x/y/width/height so effects have room to render.
SVG filters let you process the pixels of a vector graphic through a short pipeline of primitives. You define the effect once, give it an id, and attach it to rectangles, circles, text, or groups.
Unlike exporting blurred PNGs, SVG filters stay resolution-independent and can be reused across many elements. Start with blur and drop shadow — those two cover most UI needs — then explore colour matrices and merges as you grow.
Icons, charts, and illustrations often need soft depth. SVG filters keep those effects inside the graphic — scalable, themeable, and free of extra image assets.
Put filters in <defs> and reuse them anywhere.
Each fe* step feeds the next for composed effects.
Give blur and shadow room so they are not clipped.
Effects scale with the SVG — no blurry bitmaps.
In short: define a <filter>, fill it with primitives, expand its region, then apply it with filter="url(#id)".
Basic form of an SVG filter definition and application:
<svg>
<defs>
<filter id="filter-id" x="-20%" y="-20%" width="140%" height="140%">
<!-- filter primitives go here -->
</filter>
</defs>
<rect filter="url(#filter-id)" />
</svg> | Piece | Role | Description |
|---|---|---|
<defs> | Container | Holds reusable definitions that are not drawn by themselves. |
<filter> | Effect | Named with id; contains one or more filter primitives. |
filter="url(#id)" | Apply | Presentation attribute on the target shape or group. |
x y width height | Region | Expand beyond the shape so blur/shadow is not clipped. |
| Primitive | What it does |
|---|---|
feGaussianBlur | Softens the graphic; stdDeviation controls strength. |
feOffset | Moves the input by dx / dy (great for shadows). |
feColorMatrix | Adjusts colour and alpha (tint or fade a shadow). |
feMerge | Stacks results — usually shadow under SourceGraphic. |
feDropShadow | Shorthand drop shadow in modern browsers. |
<svg width="240" height="160" viewBox="0 0 240 160">
<defs>
<filter id="blur" x="-20%" y="-20%" width="140%" height="140%">
<feGaussianBlur stdDeviation="5" />
</filter>
</defs>
<rect x="40" y="35" width="160" height="90" rx="14"
fill="#2563eb" filter="url(#blur)" />
</svg> | Goal | Code |
|---|---|
| Define a filter | <filter id="fx">...</filter> inside <defs> |
| Apply a filter | filter="url(#fx)" |
| Blur | <feGaussianBlur stdDeviation="5" /> |
| Offset for shadow | <feOffset in="SourceAlpha" dx="0" dy="8" /> |
| Avoid clipping | x="-20%" y="-20%" width="140%" height="140%" |
| Modern drop shadow | <feDropShadow dx="0" dy="6" stdDeviation="4" /> |
filter vs Gradients vs PatternsDifferent tools for different visuals — pick the lightest option that fits.
vector pipelineReusable blur, shadow, and composed effects inside SVG
element effectQuick blur/shadow on HTML or the whole SVG box
colour fillSmooth colour transitions without pixel processing
repeating fillTiles and textures as paint servers
Reach for filters when the effect should live with the graphic and scale with it.
Drop shadows and glows that stay crisp at any size.
Subtle blur on highlights or markers without extra assets.
One filter id shared across many logo pieces.
Offset + blur + matrix + merge when CSS alone is not enough.
Large blurs on big canvases can be costly — keep effects subtle.
Key benefit: resolution-independent effects defined once and applied everywhere with a single url(#id).
Five starter snippets using SVG filters. Click View Output for a preview, or Try It Yourself to edit live.
Blur a shape, then build a classic drop shadow pipeline.
Define a blur filter and apply it to a rounded rectangle. stdDeviation controls how strong the blur is.
<svg width="240" height="160" viewBox="0 0 240 160">
<defs>
<filter id="blur-filter" x="-20%" y="-20%" width="140%" height="140%">
<feGaussianBlur stdDeviation="5" />
</filter>
</defs>
<rect x="40" y="35" width="160" height="90" rx="14"
fill="#2563eb" filter="url(#blur-filter)" />
</svg> The filter softens every pixel of the rectangle. Expanding the region to 140% keeps the blur halo from being cut off at the shape’s bounding box.
Offset the alpha channel, blur it, fade it with a colour matrix, then merge the shadow under the original graphic.
<svg width="240" height="160" viewBox="0 0 240 160">
<defs>
<filter id="shadow" x="-20%" y="-20%" width="140%" height="140%">
<feOffset in="SourceAlpha" dx="0" dy="10" result="off" />
<feGaussianBlur in="off" stdDeviation="8" result="blur" />
<feColorMatrix in="blur" type="matrix"
values="0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0.35 0" result="shadow" />
<feMerge>
<feMergeNode in="shadow" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
<circle cx="120" cy="70" r="42" fill="#f97316" filter="url(#shadow)" />
</svg> SourceAlpha isolates the shape’s silhouette. Offsetting and blurring creates the soft shadow; feMerge paints that shadow first, then the original circle on top.
Glows, shorthand shadows, and one filter on many shapes.
Blur a copy of the graphic and merge it behind the sharp original for a gentle glow.
<svg width="240" height="140" viewBox="0 0 240 140">
<defs>
<filter id="glow" x="-40%" y="-40%" width="180%" height="180%">
<feGaussianBlur in="SourceGraphic" stdDeviation="6" result="blur" />
<feMerge>
<feMergeNode in="blur" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
<circle cx="120" cy="70" r="36" fill="#8b5cf6" filter="url(#glow)" />
</svg> Unlike a drop shadow, the glow blurs the full coloured graphic (not just alpha), then stacks the blur under a sharp copy so the center stays vivid.
feDropShadowModern browsers support a single primitive that offsets and blurs in one step.
<svg width="240" height="160" viewBox="0 0 240 160">
<defs>
<filter id="easy-shadow" x="-30%" y="-30%" width="160%" height="160%">
<feDropShadow dx="0" dy="8" stdDeviation="5"
flood-color="#0f172a" flood-opacity="0.35" />
</filter>
</defs>
<rect x="50" y="40" width="140" height="70" rx="12"
fill="#14b8a6" filter="url(#easy-shadow)" />
</svg> feDropShadow is shorter than the offset/blur/merge recipe. Keep the classic pipeline when you need maximum control or older-browser compatibility.
Define a shared shadow once, then apply it to several elements with the same url(#id).
<svg width="280" height="140" viewBox="0 0 280 140">
<defs>
<filter id="card-shadow" x="-25%" y="-25%" width="150%" height="150%">
<feDropShadow dx="0" dy="6" stdDeviation="4"
flood-opacity="0.3" />
</filter>
</defs>
<rect x="20" y="30" width="70" height="70" rx="10"
fill="#3b82f6" filter="url(#card-shadow)" />
<circle cx="140" cy="65" r="35"
fill="#f59e0b" filter="url(#card-shadow)" />
<rect x="190" y="30" width="70" height="70" rx="10"
fill="#10b981" filter="url(#card-shadow)" />
</svg> One definition keeps markup DRY and makes design tweaks easy — change stdDeviation once and every card updates.
Where SVG filters show up in real interfaces and graphics.
Soft drop shadows under UI icons and badges.
Example: floating action button glyph.
Glow selected points or soften background layers.
Example: active marker glow on a chart.
Brand marks with consistent shadow or blur accents.
Example: shared filter across logo parts.
Blur decorative layers behind sharp foreground content.
Example: frosted blob behind a headline.
Animate stdDeviation or opacity for pulsing glows.
Example: status pulse on a live indicator.
Teach pipelines by showing each primitive’s result.
Example: step-through shadow construction.
Pro Tip: if a plain feDropShadow is enough, prefer it — save the longer offset/blur/merge stack for custom shadows.
Why keep effects inside SVG instead of baking them into images.
Effects redraw with the vector — no blurry PNG shadows.
One id powers many shapes across the document.
Stack primitives for custom looks CSS alone cannot express.
Export or embed the SVG and the effect travels with it.
Tweak flood colours and opacity without exporting new assets.
Pro Tip: keep stdDeviation modest — small values look polished and perform better on mobile GPUs.
Follow these practices for clean, performant SVG filters.
Shadows and blurs need space — set x/y/width/height beyond 100%.
Reusable, tidy, and not drawn as standalone content.
Small stdDeviation values look intentional and stay fast.
Use result attributes so multi-step pipelines stay readable.
Apply the same url(#id) to many shapes instead of duplicating defs.
Pro Tip: test heavy filters on mobile early — GPUs differ more than desktop engines for large blurs.
Avoid these mistakes when filters look wrong or disappear.
url(#id)Without the filter attribute, the definition never runs.
→ Add filter="url(#yourId)" and match the id exactly.
Default filter regions crop soft edges.
→ Expand x, y, width, and height on <filter>.
Multiple inline SVGs with the same id can collide on a page.
→ Use unique ids per document, or isolate SVGs carefully.
Big stdDeviation values can stutter on mobile.
→ Keep effects subtle or apply filters to smaller groups.
Sometimes a darker shape or gradient is enough.
→ Prefer simpler paint when you only need a slight depth cue.
Pro Tip: if a shadow looks cut off, fix the filter region first — that one change solves most “broken filter” reports.
Filters live in <defs> so you can reuse them. Give the <filter> an id and reference it later.
Each primitive performs one image-processing step. For example, feGaussianBlur softens pixels, feOffset moves them, and feColorMatrix adjusts colour/opacity.
Shadows and blurs extend beyond the shape. Increase x, y, width, and height on <filter> to prevent clipping.
Add the filter attribute to any SVG element. The browser renders the element through your filter pipeline.
SVG filters can create blur, shadows, colour shifts, and stylised visuals while staying resolution-independent.
<defs> with a unique id.filter="url(#id)" — the hash must match.feGaussianBlur’s stdDeviation controls blur strength.Quick Takeaway: define once, expand the region, apply with url(#id) — and start with blur or drop shadow before stacking exotic primitives.
Core SVG filter primitives such as feGaussianBlur, feOffset, feColorMatrix, and feMerge are widely supported in modern browsers. feDropShadow works in current evergreen browsers; keep a classic pipeline if you need older coverage.
Define filters in
Bottom line: Safe for production UI effects. Prefer subtle filters, unique ids, and expanded regions. Test feDropShadow if you rely on the shorthand.
SVG filters turn simple shapes into polished graphics — blur, glow, and drop shadow — without leaving the vector format. Define a pipeline in <defs>, expand the region, and apply it with filter="url(#id)".
Practice the five examples above, then continue to SVG Patterns to fill shapes with repeating designs.
Reuse one filter across shapes, keep blurs subtle, and expand the filter region whenever shadows look clipped.
<defs> so filters are reusableurl(#id) — filters won’t apply without itid across multiple inline SVGs on one pageBuild blur and shadow the SVG way.
Define in <defs>
APIurl(#id)
UsefeGaussianBlur
FXOffset + blur + merge
DepthExpand to avoid clip
LayoutAn SVG <filter> is a reusable pixel pipeline — define it once in <defs>, then apply it with filter="url(#id)" on any shape. Built-in inputs like SourceGraphic and SourceAlpha let primitives tap the original paint or just its silhouette — that’s how drop shadows stay soft without blurring the fill.
Learn how to fill shapes with repeating tiles using <pattern>.
6 people found this page helpful