This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The <foreignObject> SVG element includes elements from a different XML namespace. In the context of a browser, it is most likely (X)HTML.
| Categories | Graphics element, Renderable element |
|---|---|
| Permitted content | Any elements or character data |
heightThe height of the foreignObject. Value type: <length> | <percentage>; Default value: auto; Animatable: yes
widthThe width of the foreignObject. Value type: <length> | <percentage>; Default value: auto; Animatable: yes
xThe x coordinate of the foreignObject. Value type: <length> | <percentage>; Default value: 0; Animatable: yes
yThe y coordinate of the foreignObject. Value type: <length> | <percentage>; Default value: 0; Animatable: yes
Note: Starting with SVG2, x, y, width, and height are Geometry Properties, meaning those attributes can also be used as CSS properties for that element.
This element implements the SVGForeignObjectElement interface.
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<style>
div {
color: white;
font: 18px serif;
height: 100%;
overflow: auto;
}
</style>
<polygon points="5,5 195,10 185,185 10,195" />
<!-- Common use case: embed HTML text into SVG -->
<foreignObject x="20" y="20" width="160" height="160">
<!--
In the context of SVG embedded in an HTML document, the XHTML
namespace could be omitted, but it is mandatory in the
context of an SVG document
-->
<div xmlns="http://www.w3.org/1999/xhtml">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis mollis
mi ut ultricies. Nullam magna ipsum, porta vel dui convallis, rutrum
imperdiet eros. Aliquam erat volutpat.
</div>
</foreignObject>
</svg>
| Specification |
|---|
| Scalable Vector Graphics (SVG) 2> # ForeignObjectElement> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
foreignObject |
1 | 12 | 2 | 2 | 3 | 18 | 4 | 10.1 | 3 | 1.0 | 4 | 3 |
height |
1 | 12 | 2 | 2 | 3 | 18 | 4 | 10.1 | 3 | 1.0 | 4 | 3 |
systemLanguage |
1 | 12 | 12 | 2 | 3 | 18 | 14 | 10.1 | 3 | 1.0 | 4 | 3 |
width |
1 | 12 | 2 | 2 | 3 | 18 | 4 | 10.1 | 3 | 1.0 | 4 | 3 |
x |
1 | 12 | 2 | 2 | 3 | 18 | 4 | 10.1 | 3 | 1.0 | 4 | 3 |
y |
1 | 12 | 2 | 2 | 3 | 18 | 4 | 10.1 | 3 | 1.0 | 4 | 3 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/foreignObject