How to set HTML code as iframe source rather than a URL?

Spread the love

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.

Leave a Reply

Your email address will not be published. Required fields are marked *