<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>246106</bug_id>
          
          <creation_ts>2022-10-05 14:21:14 -0700</creation_ts>
          <short_desc>[Filters] CSS filters are not applied to SVG elements</short_desc>
          <delta_ts>2025-12-08 20:19:23 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>SVG</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=261806</see_also>
    
    <see_also>https://github.com/webcompat/web-bugs/issues/137838</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Said Abou-Hallawa">sabouhallawa</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>azin+webkit</cc>
    
    <cc>circuitcoder0</cc>
    
    <cc>daniel.schulz</cc>
    
    <cc>f.olszewski</cc>
    
    <cc>karlcow</cc>
    
    <cc>maggotfish</cc>
    
    <cc>mark</cc>
    
    <cc>mgilbert</cc>
    
    <cc>pietro.tarsitano</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>shosioness123q</cc>
    
    <cc>takeyou.dev</cc>
    
    <cc>tuanglen</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zimmermann</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1903525</commentid>
    <comment_count>0</comment_count>
      <attachid>462818</attachid>
    <who name="Said Abou-Hallawa">sabouhallawa</who>
    <bug_when>2022-10-05 14:21:14 -0700</bug_when>
    <thetext>Created attachment 462818
test case (an SVG &lt;rect&gt; with style `filter: drop-shadow(...)`)

Open the attached test case.

Result: Only a 100x100 green rectangle is drawn
Expected: A 100x100 green rectangle with black drop shadow is drawn.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1903528</commentid>
    <comment_count>1</comment_count>
    <who name="Said Abou-Hallawa">sabouhallawa</who>
    <bug_when>2022-10-05 14:21:43 -0700</bug_when>
    <thetext>rdar://95175811</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2039420</commentid>
    <comment_count>2</comment_count>
    <who name="Felix Olszewski">f.olszewski</who>
    <bug_when>2024-06-03 06:54:50 -0700</bug_when>
    <thetext>Use this workaround that I discovered whilst chatting with GPT4:

&quot;it was a webkit bug. I found it. Can you give me even more workarounds, maybe similar properties or so?&quot;

-&gt;

Instead of relying on CSS to apply the filter, you can define an SVG filter within your SVG and apply it to the image element. SVG filters are more universally supported in terms of functionality across different browsers, including Safari.

Here&apos;s an example of how you can apply a grayscale effect using an SVG filter:

xml
Copy code
&lt;svg width=&quot;200&quot; height=&quot;200&quot;&gt;
  &lt;defs&gt;
    &lt;filter id=&quot;grayscale-filter&quot;&gt;
      &lt;feColorMatrix type=&quot;matrix&quot; values=&quot;0.33 0.33 0.33 0 0
                                           0.33 0.33 0.33 0 0
                                           0.33 0.33 0.33 0 0
                                           0 0 0 1 0&quot;/&gt;
    &lt;/filter&gt;
  &lt;/defs&gt;
  &lt;image filter=&quot;url(#grayscale-filter)&quot; href=&quot;your-image-url.jpg&quot; x=&quot;0&quot; y=&quot;0&quot; height=&quot;200px&quot; width=&quot;200px&quot;/&gt;
&lt;/svg&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2040926</commentid>
    <comment_count>3</comment_count>
      <attachid>471657</attachid>
    <who name="">azin+webkit</who>
    <bug_when>2024-06-11 21:26:35 -0700</bug_when>
    <thetext>Created attachment 471657
Test case (an HTML and an SVG file) covering root SVG and inline/external symbols</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2040927</commentid>
    <comment_count>4</comment_count>
    <who name="">azin+webkit</who>
    <bug_when>2024-06-11 21:27:50 -0700</bug_when>
    <thetext>I ran into this bug when looking for a workaround for bug 275304.

After testing, it looks like presentation attribute (CSS) filters are only applied to the root SVG element. For context, the specification requires the filter attribute to apply to all graphics elements, &lt;use&gt;, and all containers except for &lt;defs&gt;.

The extent of this bug means there&apos;s no known workaround for bug 275304, rendering a large amount of SVG filter applications impossible to achieve in WebKit.

I&apos;ve included a test case that demonstrates (A) that the filter presentation attribute fails when applied directly to a shape; (B) that it succeeds when applied to a root &lt;svg&gt; element; and (D) that there is no apparent workaround for applying a filter to external symbols (&lt;use&gt; referencing an external &lt;symbol&gt;).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2055193</commentid>
    <comment_count>5</comment_count>
    <who name="">tuanglen</who>
    <bug_when>2024-08-25 00:43:49 -0700</bug_when>
    <thetext>I created a minimal code sample to demonstrate the problem. It uses 2 &lt;rect&gt;s and 2 CSS rules. This problem causes interactive elements in a nice SVG interface that works well in Chrome and Firefox to be non-responsive when using Safari.

Here it is in a codepen: https://codepen.io/tuanglen/pen/eYwrXam

We can&apos;t just fall back to the fancier SVG &lt;feComponentTransfer&gt; that is supposedly the &quot;equivalent&quot; of CSS `filter: brightness()` because the results (on browsers that have both types of filters) look so much better with CSS&apos;s `filter: brightness()` than with SVG&apos;s `&lt;feComponentTransfer&gt;`. In Chrome and FF, smooth gradients remain smooth with `filter: brightness` but turn ugly and banded with `&lt;feComponentTransfer&gt;`. Ironically, `&lt;feComponentTransfer&gt;` in Safari handles gradients better than `&lt;feComponentTransfer&gt;` in Chrome or FF, but Safari needs the CSS filters such as `filter: brightness` to work, too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106101</commentid>
    <comment_count>6</comment_count>
    <who name="Pentever">shosioness123q</who>
    <bug_when>2025-03-26 02:16:55 -0700</bug_when>
    <thetext>Thank you for filing. The appropriate engineers have been notified https://blockblastadventure.com</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2109777</commentid>
    <comment_count>7</comment_count>
    <who name="">mark</who>
    <bug_when>2025-04-08 13:20:09 -0700</bug_when>
    <thetext>(In reply to azin+webkit from comment #4)
&gt; I ran into this bug when looking for a workaround for bug 275304.
&gt; 
&gt; After testing, it looks like presentation attribute (CSS) filters are only
&gt; applied to the root SVG element. For context, the specification requires the
&gt; filter attribute to apply to all graphics elements, &lt;use&gt;, and all
&gt; containers except for &lt;defs&gt;.
&gt; 
&gt; The extent of this bug means there&apos;s no known workaround for bug 275304,
&gt; rendering a large amount of SVG filter applications impossible to achieve in
&gt; WebKit.
&gt; 
&gt; I&apos;ve included a test case that demonstrates (A) that the filter presentation
&gt; attribute fails when applied directly to a shape; (B) that it succeeds when
&gt; applied to a root &lt;svg&gt; element; and (D) that there is no apparent
&gt; workaround for applying a filter to external symbols (&lt;use&gt; referencing an
&gt; external &lt;symbol&gt;).

Thank you very much, applying the filter to the root element solves my use case, so this workaround is perfect.
I&apos;m applying a glow filter to an SVG logo and putting the css class with the filter on the root element means it works identically on Safari as in other browsers.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>462818</attachid>
            <date>2022-10-05 14:21:14 -0700</date>
            <delta_ts>2022-10-05 14:21:14 -0700</delta_ts>
            <desc>test case (an SVG &lt;rect&gt; with style `filter: drop-shadow(...)`)</desc>
            <filename>test-svg-ccs-filter.html</filename>
            <type>text/html</type>
            <size>194</size>
            <attacher name="Said Abou-Hallawa">sabouhallawa</attacher>
            
              <data encoding="base64">PHN0eWxlPgogIHJlY3QgewogICAgICBmaWxsOiBncmVlbjsKICAgICAgZmlsdGVyOiBkcm9wLXNo
YWRvdygxNnB4IDE2cHggMCBibGFjayk7CiAgfQo8L3N0eWxlPgo8Ym9keT4KICAgIDxzdmcgd2lk
dGg9IjIwMCIgaGVpZ2h0PSIyMDAiPgogICAgICA8cmVjdCB3aWR0aD0iMTAwIiBoZWlnaHQ9IjEw
MCIgLz4KICA8L3N2Zz4KPC9ib2R5Pgo=
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>471657</attachid>
            <date>2024-06-11 21:26:35 -0700</date>
            <delta_ts>2024-06-11 21:26:35 -0700</delta_ts>
            <desc>Test case (an HTML and an SVG file) covering root SVG and inline/external symbols</desc>
            <filename>Expanded SVG CSS filter test case.zip</filename>
            <type>application/zip</type>
            <size>1636</size>
            <attacher>azin+webkit</attacher>
            
              <data encoding="base64">UEsDBBQACAAIAPRYzFgAAAAAAAAAAJ0BAAAJACAAZGVidWcuc3ZnVVQNAAcNH2lmEB9pZg0faWZ1
eAsAAQT1AQAABBQAAAClUMEOgyAMPetXND1thwnO7LKAv2IUmZIgGHCifz+cO88sSw9tXtv3Xsv8
3MEsnVfWcMyzHGEZtPEc+2ka74SEELJQZNZ15EopJXEeyzRhfh0aq0G1HOUySWdqXT2UjlVlTbV3
EXaEY+vsePF93dpwcrIFGuN2RohMCRPKCS1BLBwLiiDWPce1K31TaI6NfkoEsimTnbxMj1309Sh/
Fjny/M2EsR/5P09j25/LF1BLBwiyczlqrQAAAJ0BAABQSwMEFAAIAAgA9FjMWAAAAAAAAAAAsAAA
ABQAIABfX01BQ09TWC8uX2RlYnVnLnN2Z1VUDQAHDR9pZhAfaWZMI2lmdXgLAAEE9QEAAAQUAAAA
Y2AVY2dgYmDwTUxW8A9WiFCAApAYAycQGwFxHRCD+BsYiAKOISFBUCZIxwIgFkBTwogQl0rOz9VL
LCjISdXLSSwuKS1OTUlJLElVDggGKfTfk5YGorV9DE1ANABQSwcI1PGb+lwAAACwAAAAUEsDBBQA
CAAIAPtazFgAAAAAAAAAAL0HAAAKACAA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