* Fix iframe color-scheme behavior
* Docs: remove double blank line before iframe color-scheme section (MD012)
}
}
+ // Reset iframe color-scheme
+ //
+ // If the color scheme of an iframe differs from parent document, iframe gets
+ // an opaque canvas background appropriate (resulting in a white background
+ // on the iframe when in a page with a dark color scheme).
+ iframe {
+ color-scheme: light dark;
+ border: 0;
+ }
+
// Body
//
// 1. Remove the margin in all browsers.
display: inline-block;
}
- // Remove border from iframe
-
- iframe {
- border: 0;
- }
-
// Summary
//
// 1. Add the correct display in all browsers
</Callout>
To merely toggle the visibility of an element, meaning its `display` is not modified and the element can still affect the flow of the document, use [the `.invisible` class]([[docsref:/utilities/visibility]]) instead.
+
+## iframe color-scheme
+
+The `<iframe>` element is updated to set `color-scheme: light dark`. This ensures that the iframe is displayed in the same color scheme as the parent document. Without it, an iframe would get an opaque `background: canvas` from a mismatched `color-scheme` value.
+
+<Example code={`<div class="bg-body fg-body p-3" data-bs-theme="dark">
+ <iframe class="w-100" style="color-scheme: unset" src="data:text/html,<!DOCTYPE html><html><meta name='color-scheme' content='light dark'><body style='background-color:transparent;color:gray;'><h4>Default iframe</h4></body></html>"></iframe>
+ <iframe class="w-100" src="data:text/html,<!DOCTYPE html><html><meta name='color-scheme' content='light dark'><body style='background-color:transparent;color:gray;'><h4>iframe with color-scheme: light-dark</h4></body></html>"></iframe>
+ </div>`} />