How to apply drop-shadow filter via CSS to SVG specific element/path

Gruber picture Gruber · Dec 25, 2015 · Viewed 14.7k times · Source

I'd like to apply a drop-shadow filter to a specific element/path inside an inline placed SVG via CSS, I don't need the whole graphic to be shadowed, just an element inside it.

As you can see above, I'm trying to apply a drop-shadow to the red circle element of the SVG, but it's not working.

Searching around I haven't found any specific info on this, only few comments in other SVG related questions simply stating that it doesn't work on single SVG elements, but without much explanations.

UPDATE

As pointed out by @azeós in the comments, it is rendering correctly with Firefox (v. 43.0.2) so it's a Chrome specific issue. Is there anyway to make this crossbrowser without fiddling out with the SVG code as suggested in the comments?

Answer

serraosays picture serraosays · Dec 28, 2015

Updated 2020-04: I did some experiments on this issue because I too couldn't find any information on this and the results are pretty inconsistent.

The TL;DR: SVG drop-shadows are very inconsistent but HTML drop-shadows reliably work (outside of IE11). If you want SVG drop-shadows, you're going to have use a polyfill or just do the drop-shadow within the SVG itself.

Codepen experiment: http://codepen.io/staypuftman/pen/GoNoMq

Chrome 81 + Canary 83:

Neither Chrome nor edge Canary respect filter or -webkit-filter properly in the context of an SVG object drop-shadow but do work on a simple div.

enter image description here

Firefox 75 + Firefox 53 (pre-quantum):

Looks pretty good for both SVG and HTML objects.

enter image description here

Safari 13+

Safari briefly had dropshadows on earlier versions but has dropped them again.

enter image description here

Safari 10.1 - 11

Safari has fixed this issue in the 10.1 (and maybe the 10.0) series.

enter image description here

Safari 9.x

SVG CSS dropshadow does not show and the div dropshadow has less opacity for some reason

enter image description here

Edge (Chromium version)

No SVG dropshadows but the HTML ones work well.

enter image description here

IE11

Nothing.

enter image description here