98

Getting contradictory messages about that, hope they're not. I cannot imagine support for it would stop, since a gazillion sites use them.

Some additional questions about that:

  1. Why should they phase out this tag?
  2. Any alternative for it?
casperOne
  • 73,706
  • 19
  • 184
  • 253
Peter
  • 47,963
  • 46
  • 132
  • 181
  • They are not obsolete: https://softwareengineering.stackexchange.com/questions/144515/why-were-frames-removed-in-html5-but-not-iframes . Alternatives https://stackoverflow.com/questions/8702704/alternative-to-iframes-with-html5 – Michael Freidgeim Jul 16 '20 at 01:56
  • Any update on this? This question was asked and answered in 2009; it is now 2020. – Kellen Stuart Dec 01 '20 at 16:07

13 Answers13

79

Support for <iframe> is still there in HTML 5, so I don't think this will change in the near future.

To answer your other questions:

  1. <iframe>s (as frames in general) are most of the time not user-friendly:
    • They don't allow easy access of the content in the frame via an URL (without losing the content outside of the frame at least).
    • Most "technophobe" users are irritated by frames.
    • As far as I know they are slower to render for browsers
  2. Alternatives include dynamic page generation (SSI, PHP, Rails and so on) and using JavaScript / AJAX to change contents of e.g. a <div>

To be clear: I'm talking about <iframe> as an interface element. Not a hidden element for loading other stuff like e.g. Google Mail does.

Koraktor
  • 41,357
  • 10
  • 69
  • 99
  • 31
    +1 for the point that Google is using iframes for highly specialized purposes. – cgp Apr 16 '09 at 12:21
56

In my opinion the W3C jumped the gun in dumping iframes from the Strict HTML and XHTML doctypes. In theory you would use the <object> element to add foreign objects to your document, but browser differences and limitations have made this a nonstarter for many developers. With the much-more-pragmatic HTML 5 (which is still a draft), iframes are back and even have two new attributes: seamless, and the intriguing sandbox.

David Kolar
  • 3,475
  • 25
  • 34
  • Awesome, I just hope browsers start supporting AJAX file uploads so we don't need to use iframes or flash for that. – Xeoncross Jan 17 '11 at 17:06
  • @Xeoncross Firefox and chrome do: https://developer.mozilla.org/en/Using_files_from_web_applications – jches Oct 24 '11 at 22:46
  • 2
    Update: the semless attribute has been removed from html5. See: https://caniuse.com/#feat=iframe-seamless – Gabe Jun 16 '18 at 06:34
26

IFrames are not obsolete, but the reasons for using them are rare.

Reasons for using iframes:

  • It's great for walling off other people's stuff from other domains but it doesn't integrate smoothly. (stylesheets, javascript etc...)
  • Integrating multimedia can sometimes be done easier via an iframe as opposed to using the embed tag.
  • Really, really specialized cases like gmail's case where they are using it for sounds and history management.

I would also answer that there is no need for the removal of iframes, it's a needed tag and will be around for a while.

cgp
  • 41,026
  • 12
  • 101
  • 131
25

Iframes are obsolete for page layout. Never use them instead of good CSS layout, even table-based layout is better.

Good reasons for using iframes are:

  • ads: adwords for example uses this technique, it is good for encapsulating - ad css won't destroy your page.
  • hidden iframe: it can be used for hundreds usable things, like tracking, ajax-alternative, etc.
Thinker
  • 14,234
  • 9
  • 40
  • 55
  • 35
    *** DO NOT use iframes for adwords, it is a violation of TOS. *** http://www.scribd.com/doc/97655/15-Common-Mistakes-by-Google-Adsense-Publishers-that-Violate-Terms-of-Service – cgp Apr 16 '09 at 12:18
  • 38
    altCognito: AdWords uses iframes, not me :) I didn't mean puting adword iframe into another iframe. – Thinker Apr 16 '09 at 12:30
  • 7
    I know it's a common mistake out there (hence all the articles) so I wanted to flag it to make sure people understood what you were saying. – cgp Apr 16 '09 at 12:49
  • 5
    Iframes are a must when including complicated content that must be served from another domain, and must not be manipulated with current page's CSS or JS code. – vsync Nov 25 '09 at 12:18
  • Sorry, how is an iframe an alternative to CSS? This answer makes no sense. – Chris B Oct 11 '11 at 16:48
  • Chris, CSS of your page can interfere with CSS of external Ad injected with JS onto your site. Ad would have to include very large CSS file to be sure, that links have no border, no background, no overline, etc. – Thinker Oct 11 '11 at 22:12
  • 5
    What you're talking about has nothing to do with iframes. Point is - You use an iframe to bring in an nested, external browsing context. You don't use it for 'page layout'. If I need a nested browsing context - how in the world would I use "good CSS layout" instead? It doesn't make sense. – Chris B Oct 20 '11 at 14:32
  • I think perhaps Thinker is mixing the usage of "Iframes" with "Frames". Frames were commonly used for layout in the dark ages. – j.strugnell Feb 07 '12 at 11:39
  • IE has a bug with divs and the scroll bar. If I load 3000 items in a div, set the height and give it a scrollbar, IE crashes... The workaround that I came up with was to use an iframe. [Example of bug...](http://plnkr.co/edit/vJjyq8JeUFLD1fzM2LRj?p=preview). – Mike Feb 21 '17 at 21:46
12

I've seen lots of forums that suggest the Object tag as a replacement for IFrame, which probably works in most cases.

For example, I had a PDF showing in an IFrame (because there were other things we need to show on the page besides only the PDF) and was able to get it to display fine using Object.

What was:

<iframe id="confirmed_pdf" class="current_pdf" src="/prescriptions/show_pdf?id=123" height="570" width="480"></iframe>

Became:

<object id="confirmed_pdf" class="current_pdf" data="/prescriptions/show_pdf?id=123" type="application/pdf" height="570" width="480">
  <p>[Show this message if displaying the PDF did not work]</p>
</object>

But Object was not a suitable replacement to fill the requirement to be able to print ONLY the PDF portion of the page.

An IFrame is like its own window within the page (a window within a window, basically), and once you get the window object, you can call .print() on it, like:

jQuery("#confirmed_pdf").contentWindow.print();

IFrame has a contentWindow property, that's what makes printing only that part possible. Object does not have a contentWindow property, so there's no way to print only the section of the page.

So, it seems like if you're just using IFrame to display something, there's other tags like Object that can be used instead. But if you need to interact with the contents of the IFrame in certain ways, then IFrame may be necessary.

Gayle
  • 3,053
  • 3
  • 20
  • 13
7

IFrames are used a lot with AJAX. GMail for example, uses nine hidden IFrames I believe.

John Topley
  • 113,588
  • 46
  • 195
  • 237
  • 5
    I count five iframes. One is not hidden, and in fact, one of them that is almost the entire view. IFrames are not used with Ajax typically (not in any of the major frameworks anyway). Gmail is using iframes for things like: History tracking, sound (odd), and some sort of canvas drawing. – cgp Apr 16 '09 at 12:08
  • I was just going by an article I read a few years ago. – John Topley Apr 16 '09 at 13:01
7

IFrames are not dead, but Frameset/Frames are dying.

In the last 2 releases of IE (IE7/IE8) zooming in Frames (not IFrames) has created disastrous results.

By all means use IFrames, but IMHO stay clear of Framesets/Frames.

scunliffe
  • 62,582
  • 25
  • 126
  • 161
5

Horses for courses... <iframe>s are like anything else... for the right purpose they're the right tool; for the wrong purpose they're an ugly hack, or worse.

In Ajax, <div>s are often the more appropriate container. In some places the activity of passing-off external content as part of your own site, as supported by <iframe>s, is inappropriate.

My team used an <iframe> the other day as an ideal way to give users access to their HTML e-mail history - the e-mails were complete <html> pages which we wanted to insert easily into our web template. <iframe>s were absolutely perfect for presenting that data]'.

On the other hand, <iframe>s should almost always be removed or disabled in any user-submitted content which is output back onto the site, because in that context they are a major security issue.

tsuchan
  • 51
  • 1
  • 1
5

At my previous company, we provided a hosted application that customers would integrate into their own websites. At times, they would use an IFrame to do this, fitting our hosted page into their existing designs. Sometimes this was even done seamlessly (ie. the IFrame had no borders or scrollbars, it just looked like part of the page). I considered this to be a good use of the tag.

Joshua Carmody
  • 13,410
  • 16
  • 64
  • 83
  • Iframes are a must with dealing with things you need to put in clients websites with your own style and Javascript, that the user's code won't break. CSS can be override easily and JS can cause conflicts sometimes (in rare cases) so its best for a "Closed System" approach. – vsync Sep 10 '09 at 07:51
5

They can be extremely useful in some circumstances, but those are limited. In particular embedding common functionality across multiple sites.

For example I have a client who runs a number of Scottish goods e-commerce sites. As part of this we have developed a couple of simple applications to locate possible clan names from your surname or your choice of tartans (giggle if you wish but tartans are worth $700 million a year to our economy). The database behind this is surprisingly large (nearly ten thousand rows in the core names and tartans tables) and fairly regularly updated.

So we have the applications set up to run on one website and then embedded these into our other websites using an iframe, enabling simple javascript parameter passing so we can integrate the selection of a tartan or clan with functionality on the embedding site. The iframe is set as noborder so it appears completely seamless to the end user.

Of course there would be other ways of doing this, but the use of an iframe is simple and robust. And it's certainly not obsolete.

Cruachan
  • 15,733
  • 5
  • 59
  • 112
4

The google gadget specification currently relies on iframes: http://code.google.com/apis/gadgets/docs/spec.html

Currently they are the only simple way to provide isolation for javascript apps that are pulled from multiple domains/providers.

Also many of the widgets that people embed on their websites from third-parties use iframes.

While they do have their drawbacks, iframes provide a pragmatic solution to common problems on the web. I'd have to guess that they will be around for some time to come.

Jason
  • 271
  • 1
  • 2
3

Compliance and Security issues can also drive you to use Iframes; Shopping carts are popular IFrame-based implementations when you want to visually incorporate a shopping cart as part of some web pages without taking on full responsibility for the payment processing side of things.

We commonly deliver an Iframe to integrate our eCommerce stuff and clients like how turnkey it can be.

quolo
  • 31
  • 1
0

I work for a company that used frames for everything from pull down menus, lists, content blocks, etc just to cover the intricacies of .net web forms. The application is very slow and only runs on IE. Don't do this.