Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

srcdoc — an inline HTML document for iframe

The srcdoc attribute supplies an iframe document's HTML without a separate file and takes precedence over src.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<iframe srcdoc="HTML source"></iframe>

srcdoc contains an iframe document's HTML, not a URL. The resulting document's URL is about:srcdoc. A present attribute, even empty, takes precedence over src.

The document may omit optional tags. Inside a double-quoted attribute, escape & before ", using &amp; and &quot;. Account for two parsing passes: the outer attribute and the inner HTML.

srcdoc does not sanitize HTML. Use sandbox for untrusted content; an empty sandbox blocks scripts and forces an opaque origin.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>srcdoc demo</title>
<iframe title="Preview" sandbox src="about:blank"
  srcdoc="<p title=&quot;Greeting&quot;>Hello &amp;amp; welcome!</p>"></iframe>
</html>

Result

Hello & welcome!

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources