74

Why were frames removed in HTML5, but not iFrames? After all, there is almost no difference between the two. In many instances using either of them would give the same output (pardon me if I am wrong)?

mit
  • 103
  • 3
  • 4
    http://stackoverflow.com/questions/4263509/why-are-frames-deprecated-in-html – BBB Apr 15 '12 at 05:20
  • thanks for the link, but what's the little difference between the two, that iframes did not get deprecated. –  Apr 15 '12 at 05:22
  • 1
    Because frames were a terrible idea from the start but iframes do have a few legitimate use cases? – GordonM Apr 27 '15 at 07:59
  • On Stack Overflow: "[Frames deprecated in HTML5 but not iFrames](http://stackoverflow.com/q/10159741/798371)" – WBT May 24 '16 at 19:00

3 Answers3

89

There's a couple of misconceptions in your post. First, the frame and frameset elements are not deprecated in HTML5, they're obsolete (i.e., they've been removed entirely).

Second, the frame and frameset elements are not the same thing as the iframe element, nor do they give the same output:

  • The frameset element replaces the body element in pages as a means to include a different document model for web pages: they're bad for usability and accessibility, and what they intended to accomplish have been completely replaced by CSS and ubiquitous server-side development.

  • The iframe element, on the other hand, does not replace the body of a page. It acts as a means to include a new browsing context embedded within a block of content. It does not suffer from the same usability or accessibility problems as the frameset model and is used almost anywhere one needs to include an embedded browsing context (widgets being the most prolific example).1

The iframe in HTML5 also takes on additional features in that it can be sandboxed, allowing the parent document to decide what gets executed within it. This allows for some measure of security for the parent document (and visitors to the parent document) when embedding untrusted content.


Notes

Note 1: the object element somewhat overlaps with the iframe element, but it has a different content model (which is intended mainly for plugins), has its own set of caveats, and doesn't have the sandboxing attributes the iframe element has.

  • 9
    Why are frameset elements bad for "usability" and "accessibility" but iframe elements aren't? – meriton Apr 15 '12 at 13:18
  • 20
    @meriton The frameset constructs a page out of multiple documents all with with the same priority: this causes [challenges for screen readers](http://www.accessibletech.org/access_articles/webinfo/frames.php) that do not know which document to focus on at any specific time. Iframe elements, on the other hand, are simply embedded into a single page: it's no different than having an embedded image. –  Apr 15 '12 at 17:23
  • 13
    Challenges for screen readers: The blind people I have spoken to have all said that they prefer navigation to be stuck in a separate frame (not iFrame) because they can ignore it and only have it read to them when they want. The real culprit for screen readers is Javascript and AJAX which makes pages completely unusable with current screen readers (well, my info is about 10 months old). My personal experience with screen readers supports this. – GlenPeterson May 13 '13 at 18:41
  • 5
    I've been wondering if a lot of 2005's often requoted accessibility assertions haven't been overdue for an update. Thanks for the dissent on that. – Erik Reppen Aug 22 '13 at 20:25
  • 1
    @GlenPeterson the same effect without frame element can be achieved by using CSS to make the block element fixed in viewport. That is HOW it should be done if you want that kind of navigation. It makes more sense. – netrox Feb 12 '14 at 21:10
10

Framesets are often used in a way where they break the fundamental principle of the Web - that each document has a single URL. This leads to problems with linking, bookmarks, search engines etc.

The typical use of a frameset would be a frame at the top with a logo or header, a frame at the side with a menu, and a content frame. But search engines index individual pages, so when you find some page in Google, it would link directly to the content page without the frameset, so you lose the navigation. The problem with links and bookmarks is you would typically want to link or bookmark a particular content page inside the frameset, without losing the frameset itself. The is no easy way to do that.

The reason framesets became popular in the first place was because they allowed a statically positioned header and menu with a scrolling content area. But that can be achieved much easier with CSS today. Furthermore frames allowed you to use common elements like logos and menus on multiple pages without using any server-side coding. This was an advantage at a time where server-side coding was tedious and error prone (i.e. CGI scripts), and many hosts didn't allow server-side scripting at all. Today with Content Management Systems (CMS) and better server-side platforms, this is much better handled on the server side.

So basically there are no advantages to using a frameset, just lots of problems.

IFrames can be used the same way that framesets were used, and in that case they also lead to the same problems. But there are also many legitimate uses of iframes which do not lead to the same problems.

JacquesB
  • 57,310
  • 21
  • 127
  • 176
8

Frames (frameset) acts as document. It's removed because it breaks HTML documents structure and navigation. Eg. you have links in one frame, content in the other, you can't open link from the page in in a new window, you can't link to specific sub-page, etc.

On the other hand iframes won't break anything if used correctly because they're meant to sandbox content (eg. ads).

Slawek
  • 2,884
  • 16
  • 16