← Chrome 158 reference · All APIs
v158 · css & svg · enabled by default
object-fit and object-position apply to SVG documents in <object> and <embed>
Same-origin SVG documents loaded through HTML <object> or <embed> elements are sized and positioned inside the element’s content box according to CSS object-fit and object-position, matching replaced-element behavior for <img> and aligning with Firefox. Previously, Chrome ignored both properties on embedded SVG documents and stretched the SVG viewport to the entire content box.
at a glance
| Shipped in | Chrome 158 (desktop, Android, Android WebView) — filed under “Enabled by default” in the milestone=158 listing (feature type: “Chromium catches up” in ChromeStatus API record) |
|---|---|
| Runtime flag | SVGEmbeddedAsReplacedElement — implemented behind this flag since Chrome 141 and shipped by default in Chrome 158 per ChromeStatus (note: Blink’s runtime_enabled_features.json5 on main still listed status: "experimental" when checked 2026-11-24; flag can be tested via --enable-blink-features=SVGEmbeddedAsReplacedElement on earlier builds) |
| Specification | HTML Living Standard §15.4.1 Embedded content; CSS Images 3 §4.5 object-fit & §4.6 object-position; Fullscreen API UA stylesheet |
| Tracking bug | issues.chromium.org/41302806 |
| Web platform tests | 60 SVG fit/position tests across object-fit-{fill,contain,cover,none,scale-down}-svg-001..006{o,e}.html, object-fit-dyn-aspect-ratio-001/002.html, and fullscreen/rendering/backdrop-object.html |
| ChromeStatus | 4886345347629056 — object-fit and object-position apply to SVG documents in <object> and <embed> |
why it exists
The HTML rendering specification defines both <embed> and an <object> representing an image, plugin, or content navigable as replaced elements, and CSS Images 3 specifies that object-fit and object-position apply to all replaced elements. Previously, Blink applied replaced-element content-rect sizing to <img> and <video> but skipped it in LayoutEmbeddedObject for embedded SVG documents, forcing the SVG viewport to fill the entire content box regardless of author styles or the Fullscreen UA stylesheet’s object-fit: contain rule. Chrome 158 routes same-origin embedded SVG documents in <object> and <embed> through replaced-element sizing, matching Firefox and eliminating layout surprises when swapping between <img src="*.svg"> and interactive <object data="*.svg">.
layout_embedded_object.cc.
Syntax
No new CSS property or HTML attribute syntax is introduced; existing CSS Images 3 properties now govern the replaced content rectangle of same-origin SVG documents hosted in <object> and <embed>:
/* CSS Images Module Level 3 — §4.5 and §4.6 */
object-fit: fill | contain | cover | none | scale-down; /* Initial: fill */
object-position: <position>; /* Initial: 50% 50% */
/* Target HTML elements hosting an SVG document */
object[type="image/svg+xml"],
embed[type="image/svg+xml"] {
object-fit: contain;
object-position: top right;
}
“The
embed,iframe, andvideoelements are expected to be treated as replaced elements. … Anobjectelement that represents an image, plugin, or its content navigable is expected to be treated as a replaced element.”
This reference covers four parts of the Chrome 158 contract: object-fit sizing and SVG intrinsic dimensions, object-position placement and hit testing, dynamic updates, viewBox mutations, and Fullscreen UA styles, and element scope (<object>/<embed> vs <iframe>) and out-of-process frame limitations.
object-fit — sizing SVG documents with intrinsic dimensions and preserveAspectRatio
Inputs. All five CSS Images 3 object-fit keywords (fill, contain, cover, none, scale-down; initial value fill) apply to the concrete object size of the embedded SVG document’s viewport inside the <object> or <embed> content box. The concrete object size depends on the root <svg> element’s intrinsic dimensions (width/height attributes) and intrinsic aspect ratio (viewBox), and then the SVG’s own preserveAspectRatio maps the viewBox into that viewport:
Root <svg> attributes | Intrinsic size / ratio | Effect of object-fit |
|---|---|---|
Explicit width, height, viewBox, and preserveAspectRatio="none" (e.g. colors-16x8.svg) | Intrinsic size + ratio; stretches like a raster image | fill stretches to the content box; contain/cover preserve the intrinsic ratio; none renders at intrinsic size; scale-down chooses the smaller of none and contain |
viewBox only, no width/height (e.g. colors-16x8-noSize.svg) | Intrinsic aspect ratio only (no intrinsic width/height) | contain and cover size the SVG viewport using the viewBox aspect ratio; none and fill fall back to the content box when no natural dimensions exist |
Explicit width, height, viewBox, and default preserveAspectRatio (xMidYMid meet, e.g. colors-16x8-parDefault.svg) | Intrinsic size + ratio; SVG itself preserves aspect ratio inside its viewport | object-fit sizes the SVG viewport (e.g. fill gives the SVG the full content box, while cover or none lets the viewport overflow and be clipped); inside that viewport, xMidYMid meet still scales the viewBox proportionally without distortion |
Outputs. Blink computes the replaced content rectangle in LayoutEmbeddedObject::ReplacedContentRectFrom() using pixel-snapped replaced sizing (PreSnappedRectForPersistentSizing(LayoutReplaced::ReplacedContentRectFrom(base_content_rect))). With the initial values (object-fit: fill; object-position: 50% 50%), the replaced content rect equals the full content box, preserving backwards compatibility for unstyled embeds.
layout_embedded_object.cc.
object-position — alignment, clipping, and hit testing
Inputs. Any valid CSS <position> value (1- to 4-value keywords, lengths, and percentages; initial value 50% 50%), such as top right, bottom 1px right 2px, or top 25% left 25%.
Outputs. Positions the computed SVG concrete object rectangle within the <object> or <embed> content box, clipping any overflow at the content box edge (for example under object-fit: cover or none). In Blink’s LayoutEmbeddedContent::NodeAtPoint(), pointer hit testing checks ReplacedContentRect().Contains(result.LocalPoint()) and offsets child frame coordinates by ReplacedContentRect().offset, so interactive links and event handlers inside the embedded SVG match the visually positioned viewport rather than the unshifted content box.
object-position; Blink layout_embedded_content.cc; WPT object-fit-contain-svg-001o.html.
Dynamic mutations, viewBox changes, and Fullscreen UA stylesheet
Dynamic CSS updates. In Blink’s LayoutEmbeddedObject::StyleDidChange(), modifying object-fit or object-position on an <object> or <embed> immediately marks frame geometries dirty (SetNeedsUpdateGeometries()) and updates child paint properties (SetNeedsPaintPropertyUpdate()), resizing and repositioning the embedded SVG frame on the next paint.
Dynamic SVG viewBox / aspect-ratio changes. When script mutates the embedded SVG’s root attributes via objectEl.contentDocument.documentElement.setAttribute("viewBox", ...) (as verified in WPT object-fit-dyn-aspect-ratio-001.html), the changed intrinsic aspect ratio recalculates the object-fit / object-position replaced rectangle automatically.
Fullscreen rendering change. Because the Fullscreen API UA stylesheet applies object-fit: contain (intentionally non-!important) to :fullscreen elements, calling requestFullscreen() on an <object> or <embed> hosting an SVG document now letterboxes the SVG within the fullscreen viewport (exposing ::backdrop behind it) instead of stretching it to fill the screen. Authors who want stretched fullscreen behavior can override the UA rule with object:fullscreen { object-fit: fill; }.
layout_embedded_object.cc; WPT object-fit-dyn-aspect-ratio-001.html; WPT fullscreen/rendering/backdrop-object.html; Fullscreen API UA stylesheet.
Element scope, <iframe> exclusion, and out-of-process frame limitation
Element scope and context. This change applies specifically to <object> and <embed> elements whose loaded document is an SVG document (contentDocument().IsSVGDocument()). It requires no secure context, no permission, and no user activation (except requestFullscreen() for fullscreen mode).
<iframe>is unchanged:object-fitandobject-positiondo not resize or reposition an SVG document loaded inside an<iframe>, matching Firefox.- Same-origin (
LocalFrame) limitation: Per Blink’slayout_embedded_object.cc(TODO(crbug.com/41302806): Only works for same-origin content (LocalFrame)) and ChromeStatus, SVG documents hosted in a cross-origin / out-of-process frame (RemoteFrame, wherecontentDocument()is null) are not covered and keep the legacy stretched-viewport behavior. - Non-SVG documents: HTML, PDF, or other document types inside
<object>/<embed>are unaffected by this SVG-specific path.
layout_embedded_object.cc; ChromeStatus interop_compat_risks.
Errors, feature detection, and cross-browser fallbacks
Invalid object-fit or object-position values are silently dropped by the CSS parser (never throwing JS exceptions). Importantly, CSS.supports("object-fit", "contain") returns true in Chrome < 158 and Safari even though those browsers ignore object-fit on SVG documents inside <object> and <embed>:
- Cross-browser fallback (Safari and Chrome < 158): When interactivity inside the SVG DOM is not needed, use
<img src="diagram.svg">, whereobject-fitandobject-positionare Baseline Widely available across all browsers. When<object>/<embed>is required for scriptable SVG DOM access, set an explicitviewBoxandpreserveAspectRatioon the root<svg>(for examplepreserveAspectRatio="xMidYMid meet"orxMidYMid slice) so browsers ignoringobject-fitstill preserve aspect ratio cleanly. - Cross-origin SVG embeds and
<iframe>: Because Chrome 158 applies replaced-element sizing only to same-origin (LocalFrame)<object>/<embed>documents (and never to<iframe>or cross-origin out-of-process frames), either host the SVG same-origin, use<img>, or rely on the SVG’s ownpreserveAspectRatio.
Examples
No interactive demo is published on the Chrome Platform Showcase for v158/object-fit-and-object-position-apply-to-svg-documents-in-object-and-embed/ yet (HEAD check returned 404 on 2026-11-24).
Sizing and positioning same-origin SVGs in <object> and <embed>
<figure class="svg-frame">
<!-- Same-origin SVG document (LocalFrame) -->
<object class="svg-contain" type="image/svg+xml" data="/assets/floorplan.svg"
width="320" height="200">
Fallback text if the SVG fails to load.
</object>
<embed class="svg-cover" type="image/svg+xml" src="/assets/floorplan.svg"
width="320" height="200">
</figure>
<style>
.svg-contain {
width: 320px;
height: 200px;
border: 1px solid #999;
object-fit: contain;
object-position: top right;
}
.svg-cover {
width: 320px;
height: 200px;
border: 1px solid #999;
object-fit: cover;
object-position: 25% 25%;
}
</style>
Source: WPT object-fit-contain-svg-001o.html; CSS Images 3 §4.5 & §4.6.
Dynamic viewBox mutation and Fullscreen ::backdrop control
<style>
.interactive-svg {
width: 240px;
height: 240px;
object-fit: contain;
object-position: 0 0;
}
/* Fullscreen UA stylesheet sets object-fit: contain automatically;
style ::backdrop or override object-fit if desired. */
.interactive-svg::backdrop {
background: #111;
}
</style>
<object id="chart" class="interactive-svg" type="image/svg+xml"
data="/assets/chart.svg"></object>
<script>
const obj = document.getElementById("chart");
obj.addEventListener("load", () => {
// Same-origin contentDocument: changing viewBox recalculates object-fit automatically
const svgRoot = obj.contentDocument?.documentElement;
if (svgRoot) {
svgRoot.setAttribute("viewBox", "8 4 8 4");
}
});
</script>
Source: WPT object-fit-dyn-aspect-ratio-001.html; WPT fullscreen/rendering/backdrop-object.html.
Browser compatibility
| Browser | SVG in <object> / <embed> | Evidence / notes | Base object-fit / object-position (BCD) |
|---|---|---|---|
| Chrome (desktop, Android, WebView) | 158 | Enabled by default in Chrome 158 per ChromeStatus 4886345347629056 (previously behind SVGEmbeddedAsReplacedElement since M141). Same-origin (LocalFrame) SVG documents only; <iframe> unchanged | 32 |
| Edge | Unknown (Chromium 158) | Chromium-based; inherits Blink changes when SVGEmbeddedAsReplacedElement is enabled (note: wpt.fyi Edge 158.0.4370.33 showed Fail before the flag flipped to stable on main) | 79 (16–78 <img> only) |
| Firefox | Shipped | Already applies object-fit and object-position to SVG in <object>/<embed> (exact initial release unrecorded in BCD; cited as Shipped/Shipping in ChromeStatus and authored the WPT css-images SVG suite) | 36 |
| Safari | No | Not yet implemented; tracked in WebKit Bug 317804 (status: NEW per ChromeStatus) | 10 |
Security and privacy
Applying object-fit and object-position to same-origin SVG documents in <object> and <embed> changes only CSS layout and paint geometry for already-accessible same-origin documents; cross-origin out-of-process frames (RemoteFrame) are explicitly excluded in Blink’s layout_embedded_object.cc, avoiding any cross-origin intrinsic-dimension disclosure across site-isolated processes. It introduces no new permissions, storage, network requests, or fingerprinting surface. Chromium’s ChromeStatus API record lists security and privacy reviews as Pending (checked 2026-11-24) with no reported security risks; CSS Images 3 Privacy & Security Considerations notes no new security issues for object sizing.
layout_embedded_object.cc; ChromeStatus 4886345347629056; CSS Images 3 Privacy & Security Considerations.