SVG filters do not have to live in an inline <svg> element that CSS points at with filter: url(#my-custom-filter). They can be written directly in CSS. Stefan Judis covers the technique in a "Today I Learned" post.

The filter property already accepts built-in functions like grayscale(100%), but it can also reference a filter declared elsewhere. Inlining the SVG definition into the stylesheet means editing the effect where it is applied, and it opens up effects that plain CSS cannot express — Stefan's example is a turbulence filter:

img {
  filter: url('data:image/svg+xml,\
    <svg xmlns="http://www.w3.org/2000/svg">\
      <filter id="waves" x="-20%" y="-20%" width="140%" height="140%" filterUnits="objectBoundingBox" primitiveUnits="userSpaceOnUse" color-interpolation-filters="linearRGB">\
        <feTurbulence type="turbulence" baseFrequency="0.01 0.01" numOctaves="1" seed="1" stitchTiles="noStitch" result="turbulence" />\
        <feDisplacementMap in="SourceGraphic" in2="turbulence" scale="20" xChannelSelector="G" yChannelSelector="A" result="displacementMap" />\
      </filter>\
    </svg>#waves')
  ;
}

Writing filters into CSS

The price of inlining is escaping: the rule is dense with backslashes, since the SVG markup must be embedded as a url() value. Whether a code formatter or minifier would break that escaping is unclear. On the plus side, the SVG itself stays largely intact inside the CSS, readable and editable rather than mangled into an opaque string.

Generated filters fit the same workflow. Yoksel's editor for two-tone and three-tone images is one place to build a filter and copy it straight into a stylesheet as CSS.

Inline SVG beyond filters

Drawing SVG directly in CSS is not limited to filter definitions. In a quick check across modern browsers, inlining works everywhere except Safari. In the not-so-distant past, more of the SVG's special characters had to be encoded for this to work; base64 was never required, and Yoksel's URL-encoder exists for exactly that encoding chore, though it may no longer be needed.