HTML - srcdoc Attribute



HTML srcdoc attribute specifies the HTML content on the page to show in the inline frame.

If the srcdoc attribute is present in the <iframe> element, then it will override the content specified in the src attribute. If the srcdoc attribute is not present in the <iframe> element, then it will show the file specified in the src attribute.

It can be used together with sandbox and seamless attribute.

Syntax

<tag srcdoc="HTML_code" >

HTML_code: It is used to specify the HTML content of the page which will display in an iframe element.

Applies on

Below-listed element allows the use of the HTML srcdoc attribute.

Element Description
<iframe> HTML <iframe> tag is used to create an inline frame.

Examples of HTML srcdoc Attribute

Below examples will illustrate the HTML srcdoc attribute, where and how we should use this attribute!

Using srcdoc attribute with "iframe" Tag

Content provided in srcdoc attribute is seen in output window.

<!DOCTYPE html>
<html>

<head>
      <title>HTML iframe srcdoc Attribute</title>
</head>

<body>
      <h1>HTML iframe srcdoc Attribute</h1>
      <iframe srcdoc="<p>Hi, I am tutorialspoint. I provide easy 
      learning tutorials. Have a happy learning experience.</p>" 
               height="100" 
               width="300">
      </iframe>
</body>

</html>

Override content of src Attribute using srcdoc

Content in srcdoc replaces the tutorialspoint website given in src attribute.

<!DOCTYPE html>
<html>
<body>
      <h3>HTML srcdoc Attribute</h3>
      <strong>Normal Iframe</strong>
      <br>
      <iframe src=
"https://tutorialspoint.com/html/html_overview.htm"
              height=400 
              width="500">
      </iframe>
      <br>
      <strong>Normal Iframe</strong>
      <br>
      <iframe src=
"https://tutorialspoint.com/html/html_overview.htm"
              srcdoc=
    "<p>We ere representing HTML Introduction Post</p>" 
              height=400 
              width="500">
      </iframe>
      
</body>

</html>

Supported Browsers

Attribute Chrome Edge Firefox Safari Opera
srcdoc 20.0 79.0 25.0 6.0 15.0
html_attributes_reference.htm
Advertisements