Skip to main content
CSS is fun and cool and I like it.

Responsive Iframes

Say you wanted to put the CSS-Tricks website in an <iframe></iframe>. You’d do that like this:

<iframe src=""></iframe>

Without any other styling, you’d get a rectangle that is 300×150 pixels in size. That’s not even in the User Agent stylesheet, it’s just some magical thing about iframes (and objects). That’s almost certainly not what you want, so you’ll often see width and height attributes right on the iframe itself (YouTube does this).


Those attributes are … Read article “Responsive Iframes”


Native Lazy Loading

IntersectionObserver has made lazy loading a lot easier and more efficient than it used to be, but to do it really right you still gotta remove the src and such, which is cumbersome. It’s definitely not as easy as:

<img src="celebration.jpg" loading="lazy" alt="..." />
Read article “Native Lazy Loading”

Introducing iframify


Post Data to an Iframe

Doesn’t take any JavaScript or anything. You just have the form’s target attribute match the iframe’s name attribute.

<form action="iframe.php" target="my-iframe" method="post">
  <label for="text">Some text:</label>
  <input type="text" name="text" id="text">
  <input type="submit" value="post">
<iframe name="my-iframe" src="iframe.php"></iframe>

The outer page doesn’t even reload. But it might appear to at first glance since many browsers run the page-loading spinner in the tab when an iframe reloads.… Read article “Post Data to an Iframe”


Resize Iframe to Fit Content (Same Domain Only)

Normally you set and width and height for iframes. If the content inside is bigger, scrollbars have to suffice. The script below attempts to fix that by dynamically resizing the iframe to fit the content it loads.

<script type='text/javascript' src=''></script>
<script type='text/javascript'>
        var iFrames = $('iframe');
    	function iResize() {
    		for (var i = 0, j = iFrames.length; i < j; i++) {
    		  iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';}
        	if ($.browser.safari || $.browser.opera) { 
        	       setTimeout(iResize, 0);
        	   for (var 
Read article “Resize Iframe to Fit Content (Same Domain Only)”