This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The srcdoc property of the HTMLIFrameElement specifies the content of the page.
const iframe = document.createElement("iframe");
iframe.srcdoc = `<!doctype html><p>Hello World!</p>`;
document.body.appendChild(iframe);
| Specification |
|---|
| HTML> # dom-iframe-srcdoc> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
srcdoc |
20 | 79 | 25 | 15 | 6 | 25 | 25 | 14 | 6 | 1.5 | 4.4 | 6 |
enforces_trusted_types |
83 | 83 | 135 | 69 | 26 | 83 | No | 59 | 26 | 13.0 | 83 | 26 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/srcdoc