In the context of a web browser, a frame is a part of a web page or browser window which displays content independent of its container, with the ability to load content independently. The HTML or media elements in a frame may come from a web site distinct from the site providing the enclosing content. This practice, known as framing, is today often regarded as a violation of same-origin policy.
In HTML, a frameset is a group of named frames to which web pages and media can be directed; an iframe provides for a frame to be placed inside the body of a document.
Since the early 2000s, concern for usability and accessibility has motivated diminished use of framesets and the HTML5 standard does not support them.
Tags and attributes
The frames in HTML are created using the <code><frameset></frameset></code> tag pair. The <code><frameset></code> tag is a container tag for all other tags that are used to create frames. The <code><frameset></code> tag replaces the <code><body></code> tag in frameset documents.The <code><frameset></code> tag defines how to divide the window into frames.
Each frameset defines a set of rows or columns. If user define frames by using the <code>rows</code> attribute then horizontal frames are created. If user define frames by using <code>cols</code> then vertical frames are created.
The <code><noframes></code> element may be included so web browsers with frames disabled (or browsers that do not support frames) can display something to the user, as in this example:
<syntaxhighlight lang="html">
<frameset cols="85%, 15%">
<frame src="http://www.example.com/frame_1.html" name="frame_1">
<frame src="http://alt.example.com/frame_2.html" name="frame_2">
<noframes>
Your browser does not support frames.
<a href="http://www.example.com/frame_1.html">Click here</a> to view frame 1.
<a href="http://alt.example.com/frame_2.html">Click here</a> for frame 2.
</noframes>
</frameset>
</syntaxhighlight>
Framesets have a <code>border</code> attribute. If set to an integer greater than 0, the user can resize the frames by dragging this border, unless a <code>noresize</code> attribute is present in a frame element. If border is set to 0, no border will be displayed and content in different frames will abut each other without delineation.
The <code>iframe</code> element is used inline within a normal HTML body, and defines the initial content and name similarly to the <code>frame</code> element. Any text inside an <code><iframe></iframe></code> tag pair will be displayed in browsers that do not understand the iframe tag.
<syntaxhighlight lang="html">
<iframe src="http://www.example.com/frame_1.html" height="480" width="640">
Your browser does not support iframes. <a href="http://www.example.com/frame_1.html">Click here</a> to view the content.
</iframe>
</syntaxhighlight>
History
Netscape Navigator 2.0 introduced the elements used for frames in March 1996. Other browser vendors such as Apple with Cyberdog followed later that year. At that time, Netscape proposed frames to the World Wide Web Consortium (W3C) for inclusion in the HTML 3.0 standard.<!-- original link (not working): http://web.archive.org/web/20071030083252/http://docs.rinet.ru/HTMLnya/ch13.htm -->
Frames were used to display and navigate early online magazines and web apps, such as webmail services and web chat sites. Frames had the advantage of allowing elements to be displayed sitewide without requiring server features such as server-side includes or CGI support. These features were not common on early web servers accessible to the public.
Early websites often used a frame at the top to display a banner which could not be scrolled away. These banner frames sometimes included the site's logo as well as advertising.
XHTML 1.1, the intended successor to HTML 4, removed all frames. XFrames, the intended eventual replacement, provided the composite URI to address a populated frameset.
The later HTML5 standard removed framesets by means differing from XHTML. The <code>iframe</code> element remains with a number of "sandboxing" options intended for sharing content between sites.
Advantages
By allowing content to be loaded and navigated independently, frames offered several advantages over the plain HTML in use when they were first developed:
- Simplifying maintenance of content shared across all or most pages, such as navigation data. If an item needs to be added to a sidebar navigation menu, the web page author needs to change only one web page file, whereas each individual page on a traditional non-frameset website would have to be edited if the sidebar menu appeared on all of them.
- Reducing the amount of bandwidth needed by not re-downloading parts of the page which had not changed.
- Allowing several pieces of information to be viewed side by side, with the ability for each section to be scrolled independently. This might include the side-by-side comparison of two pictures or videos, or two different ways to understand something, such as an independently scrolling page of text next to video, images, animation, 3D rotating objects, etc.
- Allowing footnotes or digressions to appear in a dedicated section of the page when linked to, so that the reader does not lose their place in the main text.
- The main advantage to frames is that they enable parts of the page to remain stationary while other parts scroll. This is useful for elements you may not want to scroll out of view, such as navigational options or banner advertising.
- Frames unify resources that reside on separate servers. For instance, you may use frames to combine your own material (and navigation graphics) with threaded discussion material generated
Criticism
The practice of framing HTML content led to numerous criticisms, most centering on usability and accessibility concerns. These include:
- Framing breaks the identity between the content and URL as displayed in the browser, making it difficult to link to or bookmark a particular item of content within the frameset
- The implementation of frames is inconsistent across different browsers
- Screen reader programs
- text or audio browsers
- Email browsers such as Agora
- Mobile browsers
- Framing complicates web indexing and can be detrimental to search engine optimization.
- Framing confuses the boundaries between content on different servers, which raises issues of copyright infringement
- Visitors arriving from search engines may land on a page intended for display in a frame, resulting in the visitor having no way to navigate to the rest of the site
- Frames change the behavior of the back button.
