Natural Shadows in CSS with inlined SVG filters

Dissecting a React Component built by Jamie Kyle, Stefan Judis provides us with an easy to use CSS class that adds a “Natural Shadow” to any element. He does this by inlining the SVG <filter> in a CSS filter.

💁‍♂️ You can think of this “Natural Shadow” like a “Ambient Lighting” (Ambilight) option on a TV, where the TV casts a colored light that changes colour depending on the on-screen action. And yes, you can totally throw a video at it too, it’ll work (while melting your CPU)

In the pen above, I’ve tweaked the .natural-shadow class a bit:

  • The shadow now also extends at the top and bottom, by tweaking x="0" y="0" width="2" height="2" on the <filter>
  • The shadow was made bigger, by tweaking the stdDeviation="5" on the < feGaussianBlur>

As Stefan notes, Safari has some issues with the inline filter …

A natural shadow with SVG filters →

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.