HTML5: How to specify the HTML content of the page to show in the iframe element?
Solution:
HTML Code:
<!DOCTYPE html><!-- Declaration specifying the document type -->
<html><!-- Opening tag for the root element of the HTML document -->
<head><!-- Opening tag for the document's header section -->
<meta charset="utf-8"><!-- Metadata tag specifying the character encoding of the document -->
<title>How to specify the HTML content of the page to show in the iframe element</title><!-- Title of the HTML document -->
</head><!-- Closing tag for the document's header section -->
<body><!-- Opening tag for the document's body section -->
<iframe srcdoc="<p>w3resource</p>" src="https://www.w3resource.com/html-css-exercise/basic/solution/html-answer.html"><!-- Inline frame element specifying HTML content to display with srcdoc attribute and URL of the document as a fallback -->
</iframe><!-- Closing tag for the iframe element -->
</body><!-- Closing tag for the document's body section -->
</html><!-- Closing tag for the root element of the HTML document -->
Explanation:
- This HTML code demonstrates how to specify the HTML content of the page to show within an iframe element.
- The <iframe> element is used to embed content from another HTML document or website. In this case, the content is provided directly within the iframe using the srcdoc attribute.
- The srcdoc attribute contains the HTML content to be displayed within the iframe. In this example, it contains a simple paragraph element <p>w3resource</p>.
- If the browser does not support the srcdoc attribute, or if it fails to render the specified content, the src attribute provides a fallback by specifying the URL of the document to be embedded. In this case, it points to "https://www.w3resource.com/html-css-exercise/basic/solution/html-answer.html".
- When the HTML document is rendered, the content specified in the srcdoc attribute will be displayed within the iframe element.
Live Demo:
See the Pen iframe-srcdoc-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/html-css-exercise/basic/iframe-srcdoc-answer.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics