Sometimes, we want to set HTML code as iframe source rather than a URL.
In this article, we’ll look at how to set HTML code as iframe source rather than a URL.
How to set HTML code as iframe source rather than a URL?
To set HTML code as iframe source rather than a URL, we set the srcdoc
attribute.
For instance, we write
<iframe srcdoc="<html><body>Hello, <b>world</b>.</body></html>"></iframe>
to set the srcdoc
attribute to the HTML content we want to display.
Conclusion
To set HTML code as iframe source rather than a URL, we set the srcdoc
attribute.