February 19th, 2007

How to set an iframe to 100% height in FireFox

Here's the HTML code to implement if you'd like to embed another web page in an iframe on your web site, but would like it to appear as the entire page. This makes it hard to detect that the page is within an iframe. It's easy to do in IE, just set the iframe height and width to 100%. But this is invalid markup and won't work in FireFox. Here's the code to make it work, with CSS.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
 <head>
  <title>iframe example</title>
  <style type="text/css">
   html, body, div, iframe { margin:0; padding:0; height:100%; }
   iframe { display:block; width:100%; border:none; }
  </style>
 </head>
 <body>
  <div>
   <iframe src="http://example.org/" height="100%" width="100%">
    <p><a href="http://example.org/">example.org</a></p>
   </iframe>
  </div>
 </body>
</html>
Share

26 Responses to ' How to set an iframe to 100% height in FireFox '

Subscribe to comments with RSS or TrackBack to ' How to set an iframe to 100% height in FireFox '.

  1. Fadi EDWARD said,

    on May 20th, 2007 at 9:03 am

    Thank you, it worked for me, I would like to append that you can not even use a form tag in the middle.

  2. Justin Cook said,

    on May 20th, 2007 at 9:56 am

    In the middle of what? I use a form within an iframe all the time!

  3. Torsten said,

    on June 26th, 2007 at 5:46 pm

    GREAT! THANX!

    This really did the trick, had been googling around for hours!

    //Torsten

  4. krzysiek said,

    on August 26th, 2007 at 6:03 pm

    Oh, yeah. Finally I've found it. Indeed it does work! THX

  5. Sonny said,

    on September 11th, 2007 at 3:31 am

    Thanks – this was very helpful.

    BR

  6. NNM said,

    on September 25th, 2007 at 2:40 am

    Didn't work here. And you really need to change that black text on black background in your textboxes…

  7. mark said,

    on January 14th, 2008 at 5:16 pm

    On IE7 I can still see double window borders although I'm using border: 0 or none.

    Is there a workaround?

    Thanks

  8. Tony said,

    on January 31st, 2008 at 10:30 am

    This did the trick for me too!
    although it just moved another object in my page, something to do with the tags maybe

  9. CyberSkull said,

    on December 9th, 2008 at 11:02 pm

    Doesn't seem to work with XHTML 1.0 transitional.

  10. CyberSkull said,

    on December 9th, 2008 at 11:12 pm

    I figured it out. Since I am using a table in there, I have to set my td to height: 100% as well.

  11. Tarik said,

    on January 18th, 2009 at 2:12 am

    Excellent guide. It works perfectly. Thanks a bunch, Justin!

  12. Joann said,

    on March 10th, 2009 at 3:22 pm

    Thanks for the advice. It worked great.

  13. naqshi said,

    on March 14th, 2009 at 8:06 am

    Thank you very much Justin! works for me both in IE8 & FF 3.0!!

  14. donperry said,

    on April 20th, 2009 at 7:23 pm

    @Fadi EDWARD

    You are so right. No Form TAG!!! Remove all Parent form tags

  15. Eduardo said,

    on May 11th, 2009 at 6:11 pm

    Very Very tnkx, i used for IE8!!

  16. bill said,

    on June 4th, 2009 at 7:04 am

    very good
    work fine on ie6, ie8, & mozilla 3.0.10
    Thanks

  17. Tiago said,

    on June 19th, 2009 at 9:53 am

    Many thanks my friend. I was looking for this.

  18. Charles said,

    on June 25th, 2009 at 7:36 pm

    I'm using the latest version of FireFox. I have an issue with the scroll bar when I'm using the above code. A scroll bar appears for the iframe no matter what, even if it's entirely pointless. It appears even if the content is nothing more than "Hello World". What's the deal? Anybody else have this issue or know how to resolve it?


  19. on October 30th, 2009 at 8:56 pm

    Rock on!! Thanks for the fix. I was going nuts with this one.

  20. Parvesh said,

    on April 7th, 2010 at 1:57 am

    Its really helpful, and working in all browsers. Thanx

  21. James said,

    on July 23rd, 2010 at 9:46 am

    Thank you, that worked for me too! Good stuff.

  22. Michael said,

    on August 19th, 2010 at 8:54 am

    Thanks a lot. You made my day.

  23. lincoln said,

    on March 29th, 2011 at 5:15 am

    This sample work fine on ie7, ie8, ie9, mozilla 3.0.10 and mozilla 4.0

    iframe example

    html, body, div{ margin:0; padding:0; height:100%; border: none; overflow: hidden; }
    iframe { margin:0; padding:0; height:100%; display:block; width:100%; border:none; overflow: inherit auto;}

    example.org

  24. Balakrishnan said,

    on August 1st, 2011 at 2:42 pm

    Really easiest way to set height for iframe. I wasted lot of hours then searched in net and use this code. Thanks a lot

  25. Jon Sooy said,

    on September 14th, 2011 at 11:28 am

    You have no idea how much this just saved me. Thank you!!

  26. mark said,

    on October 18th, 2011 at 12:46 pm

    that's really cool, it worked in firefox 3.6 and firefox 5.
    thank you :) ))

Leave a reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word