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: 155Edge
12–18Not supported
79+Supportedsince Jan 15, 2020
Current: 154Firefox
1–24Not supported
25+Supportedsince Oct 29, 2013
Current: 157Safari
1–5.1Not supported
6+Supportedsince Jul 25, 2012
Current: 27MobileChrome Android
18–18Not supported
25+Supportedsince Feb 27, 2013
Current: 155Firefox Android
4–24Not supported
25+Supportedsince Oct 29, 2013
Current: 157Safari iOS
1–5Not supported
6+Supportedsince Sep 10, 2012
Current: 27How 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
}Documentation (MDN)
Specification
Usage share
Sub-features
Support for each part of the feature (2). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| HTMLIFrameElement.srcdoc | 20 | 79 | 25 | 6 | 25 | 25 | 6 |
| iframe.srcdoc | 20 | 79 | 25 | 6 | 25 | 25 | 6 |