Set HTML to an iframe

By Steven Verbeek • May 8th, 2020


Ever wanted to set some HTML to an iframe?

You can easily do that using srcdoc attribute on an iframe if you don't care about IE 11 support.

View Can I Use Browser Support →
<iframe srcdoc="<html><body>blah</body></html>"></iframe>

If you do need IE 11, support sadly you have to resort to Javascript.

document.getElementById('iframe')
    .contentWindow
    .document
    .write("<html><body>Hello world</body></html>");
← Return to table of contents