Svg drop shadow using css3
If you're all about efficiency, here's the quickest method for adding a drop shadow to an SVG using CSS3:
This CSS rule applies a 3px offset in both X and Y directions, a 3px blur, and a semi-transparent black color to the shadow.
Looking back for support
To ensure your lovely shadows display properly in legacy browsers such as older versions of Safari, include -webkit-filter
to buff up the compatibility:
Better with SVG filters
For those finding the CSS kingdom a bit cramped, SVG itself has a whole realm of filters to offer:
This example demonstrates an SVG filter for creating a drop shadow, with feGaussianBlur
, feOffset
, and feComponentTransfer
used together to generate a deeply customized shadow.
Shading SVG text
SVG <text>
elements can don a shadow using the text-shadow
CSS property just like regular text elements:
How's that for legibility?
Customized opacity with RGBA
A higher level of shadow customization is achievable by tweaking the alpha value in your RGBA color definition:
Advanced SVG filtering
Looking to turn up your SVG shadows to 11? Use feDropShadow
in your SVG filters:
The SVG equivalent of CSS box-shadow
, feDropShadow
lets you style your SVG shadows with utmost flair.
Universal Shadow Pact (AKA compatibility)
Like a universal treaty, ensure your shadows are compatible across all browsers and if you find one breaking the pact, use a polyfill like CSS-Filters-Polyfill.
Was this article helpful?