HTML <iframe> srcdoc Attribute

Definition and Usage

srcdoc Attribute specifies the HTML content of the page to be displayed in the inline frame.

Tip:This attribute is expected to be used with sandbox and seamless attribute together.

If the browser supports srcdoc attribute, then it will override the content specified in the src attribute (if it exists).

If the browser does not support srcdoc If the attribute is not set, then the file specified in the src attribute will be displayed (if it exists).

Example

The <iframe> with the srcdoc attribute set:

<iframe srcdoc="<p>Hello world!</p>" src="demo_iframe_srcdoc.html"></iframe>

Try It Yourself

Syntax

<iframe srcdoc="HTML_code">

Attribute Value

Value Description
HTML_code HTML content displayed in iframe. It must be valid HTML syntax.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
20.0 79.0 25.0 6.0 15.0