English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Reference

HTML: <iframe> srcdoc attribute

The srcdoc attribute specifies the HTML content of the page to be displayed inline in the iframe, and the srcdoc attribute should be used with the sandbox and seamless attributes

 HTML <iframe> tag

Online Example

An <iframe> with a srcdoc attribute:

<!DOCTYPE html>
<html>
<head>
<title>HTML: <iframe> srcdoc attribute - 基础教程网 oldtoolbag.com</title>
<body>
<iframe srcdoc="<p>Hello world!</p>/p>" src="demo-iframe.html">
  <p>Your browser does not support iframes.</p>/p>
</iframe>
</body>
</html>
Test see ‹/›

Browser Compatibility

The numbers in the table indicate the first browser version number that supports the attribute.

Attribute




srcdoc20.0Not supported25.06.0 15.0

Definition and Usage

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

Tip:The srcdoc attribute should be used with the sandbox and seamless attributes.

If the browser supports the srcdoc attribute, it will override the content specified in the src attribute (if it exists).
If the browser does not support the srcdoc attribute, it will display the file specified in the src attribute (if it exists).

HTML 4.01 and HTML5difference between

The srcdoc attribute is an HTML5 New attributes added in.

Syntax

        <iframe srcdoc="HTML_code">

Attribute value

ValueDescription
HTML_codeHTML content is displayed in iframe. It must be valid HTML syntax.
 HTML <iframe> tag