You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[css-mediaqueries] Edge cases of prefers-color-scheme and iframe color-scheme #13796
#7213 resolved that prefers-color-scheme reflects color-scheme of the embedding element (for SVG only)
RESOLVED: Have prefered-color-scheme reflect 'color-scheme' on the embedding element in the embedding document, to the extent acceptable from security standpoint (pending security review)
This was edited into the spec as:
If evaluated in an embedded SVG document using the "Secure Animated" embedding mode, the preferred color scheme must reflect the value of the used color scheme on the embedding node in the embedding document.
#7493 additionally extended this behavior to iframes:
RESOLVED: Context-dependent color scheme propagation works for iframes (including cross-origin) unless specifically restricted
While implementing this behavior for WebKit, I found two edge cases not mentioned in the spec.
When color-scheme is not specified
From my reading of the spec, the embedded document's prefers-color-scheme should only look at the embedding element's color-scheme. What if the embedding element doesn't specify color-scheme at all?
The spec doesn't mention this, but from my testing, Chrome and Firefox defaults to the system's appearance (i.e if the system is dark, then prefers-color-scheme is dark.) Personally, I prefer this behavior and would like this to be added to the spec.
Nested iframes and color-scheme propagation
Consider a document of nested iframes and some of them have color-scheme specified:
My understanding is that prefers-color-scheme only looks at the color-scheme of the <iframe> containing it, and not its ancestor <iframe>s. However, Chroma and Firefox considers the middle iframe's color-scheme and resolves prefers-color-scheme to light. So effectively, they go up the <iframe> chain and stops at the first <iframe> that explicitly defines a color-scheme I also think this behavior is reasonable and should be added to the spec.
You only need to effectively look at your embedder,
Yes this makes sense
but you need to distinguish whether the color-scheme was explicit or not, indeed.
This implies if the color-scheme isn't explicit then we must fallback to something right? (either the grandparent embedding element or system appearance)
This implies if the color-scheme isn't explicit then we must fallback to something right? (either the grandparent embedding element or system appearance)
Yes, the preferred color scheme of the embedding document, which effectively comes from grandparent embedder or so, recursively. That's what #7526 proposed and what's implemented in Firefox at least.
Activity
emilio commentedon Apr 13, 2026
@tuankiet65 I think the spec is missing the edits from #7526, but we have resolutions already.
You only need to effectively look at your embedder, but you need to distinguish whether the color-scheme was explicit or not, indeed.
tuankiet65 commentedon Apr 13, 2026
Yeah the spec is missing the edit.
Yes this makes sense
This implies if the color-scheme isn't explicit then we must fallback to something right? (either the grandparent embedding element or system appearance)
emilio commentedon Apr 13, 2026
Yes, the preferred color scheme of the embedding document, which effectively comes from grandparent embedder or so, recursively. That's what #7526 proposed and what's implemented in Firefox at least.