coderef

srcdocBaseline · Widely available

The srcdoc attribute for the <iframe> HTML element sets a string of HTML to embed in the document. The value of srcdoc overrides loading a document from the src attribute.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jan 15, 2020. Widely available since Jul 15, 2022.

Browser support

DesktopChrome
1–19Not supported
20+Supportedsince Jun 26, 2012
Current: 155
Edge
12–18Not supported
79+Supportedsince Jan 15, 2020
Current: 154
Firefox
1–24Not supported
25+Supportedsince Oct 29, 2013
Current: 157
Safari
1–5.1Not supported
6+Supportedsince Jul 25, 2012
Current: 27
MobileChrome Android
18–18Not supported
25+Supportedsince Feb 27, 2013
Current: 155
Firefox Android
4–24Not supported
25+Supportedsince Oct 29, 2013
Current: 157
Safari iOS
1–5Not supported
6+Supportedsince Sep 10, 2012
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: srcdoc.

Feature detection

JS · check before using
if ("HTMLIFrameElement" in globalThis && "srcdoc" in HTMLIFrameElement.prototype) {
  // HTMLIFrameElement.srcdoc is available
}

Sub-features

Support for each part of the feature (2). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
HTMLIFrameElement.srcdoc207925625256
iframe.srcdoc207925625256