After comparing the behaviors of iframes with src
and srcdoc
, I stumbled upon a puzzling difference: a div set to 100% height renders as the full height of the iframe when using src=[data uri]
, but not with srcdoc
.
The issue can be easily replicated with this code snippet: https://codepen.io/jamadeo/pen/LYJMzEG
When using src along with an inlined data URI, the div fills the entire height of the iframe:
<iframe src="data:text/html,<div style="background-color: red; height: 100%">hello, world</div>"></iframe>
However, when using srcdoc, the div is only the height of its content.
<iframe srcdoc="<div style="background-color: red; height: 100%">hello, world</div>"></iframe>
This discrepancy between the two methods was unexpected. While researching differences in behavior between src and srcdoc, I found ample information on cross-origin issues and browser compatibility, yet nothing regarding rendering discrepancies.