Bug 294315

Summary: prefers-color scheme is not applied to svg image when inserted through img or background css
Product: WebKit Reporter: Karl Dubost <karlcow>
Component: CSSAssignee: Kiet Ho <kiet.ho>
Status: NEW    
Severity: Normal CC: kiet.ho, koivisto, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
URL: https://wpt.live/css/mediaqueries/prefers-color-scheme-svg-image.html
See Also: https://bugs.webkit.org/show_bug.cgi?id=314270

Karl Dubost
Reported 2025-06-11 01:29:10 PDT
https://wpt.fyi/results/css/mediaqueries/prefers-color-scheme-svg-image.html https://wpt.live/css/mediaqueries/prefers-color-scheme-svg-image.html The SVG called directy is changing color depending on the preferred color scheme when called directly. But once it is called through an img element or a CSS background property it fails. The test is basically. <div style="color-scheme: dark"> <img src="resources/prefers-color-scheme.svg"> <div class="background"></div> </div> with the SVG being <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"> <style> :root { color: blue } @media (prefers-color-scheme: dark) { :root { color: purple } } </style> <rect fill="currentColor" width="32" height="32"/> </svg> The SVG stays blue instead of being purple. This would have impact on anyone using SVG icon with dark theme.
Attachments
Radar WebKit Bug Importer
Comment 1 2025-06-18 01:34:59 PDT
Note You need to log in before you can comment on or make changes to this bug.