The HTML <iframe> srcdoc attribute is used to embed HTML content directly inside an iframe instead of loading it from an external URL.
- Specifies inline HTML content for the iframe.
- Can be used with sandbox for added security.
- Overrides the src attribute when both are present.
Syntax:
<iframe srcdoc="HTML_code">Attribute Values
- HTML_code: It is used to specify the HTML content of the page which will display in an iframe element.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>
HTML iframe srcdoc Attribute
</title>
</head>
<!--Driver Code Ends-->
<body style="text-align:center;">
<h1>GeeksforGeeks</h1>
<h2>HTML iframe srcdoc Attribute</h2>
<iframe src="https://media.geeksforgeeks.org/wp-content/uploads/20210910170539/gfg-221x300.png"
srcdoc="<p>GeeksForGeeks</p>" id="GFG"
height="200" width="400" name="myGeeks">
</iframe>
</body>
<!--Driver Code Starts-->
</html>
<!--Driver Code Ends-->