Web Publishing
Frames
Ted Williams, MCSD, MCSE

List of Sections

Links to the sections below:
5.0 Introduction to Frames
5.1 Using Frames
5.2 More Complex Examples
5.3 Floating Frames
5.4 References

5.0 Introduction to Frames

Frames provide a way of splitting your browser display area into two or more separate windows. This technique is preferable to using tables for long pages in that each window can be scrolled separately. Frames are often used to provide an explorer window with many links in the left window and a viewing area in the right window. The user can scroll through the links or the display window independently. This technique is used for this presentation on my web site.

Frames were first introduced in Netscape Navigator 2.0. They were added to Internet Explorer 3.0 but frames were not added to the HTML 3.2 specification. It was not until the HTML 4.0 specification that frames were officially adopted. Only Netscape browsers at or greater than version 2.0, Internet Explorer at or greater than version 3.0 or any browser that supports the HTML 4.0 specification support frames. If your audience includes users with older browsers, you may wish to avoid frames.

For an introduction to frames, consult an HTML 4.0 text. Some of my favorite references are listed below, including some web links. Rather than reproducing yet another introduction to frames, I will concentrate on some of the often overlooked aspects of using frames which are presented below in the form of FAQs (Frequently Asked Questions).

Some of the considerations in using frames are:

5.1 Using Frames

How do frames differ from a standard web page without frames?
There are only three new tags associated with frames: frameset, frame, and noframe. As shown in the next example, note the following new tags:

What happens if a frameset tag is included after a body tag?

The result is dependent upon the browser. Most browsers will ignore any type of frame tag after a body tag.

How can I add a navigation frame to my web page?
It is easy to get lost in a web site with interconnected links between pages. You will make your web site easier to navigate with a frame on the left showing links to related pages at your site. Users are accustomed to this format from their experience with Windows Explorer. And it is not hard to accomplish. Consider the following example:

<HTML>
<HEAD>
<TITLE>Example of a frame</TITLE>
</HEAD>
<FRAMESET COLS="20%,*">
<FRAME NAME="menu" SRC="YourLinks.html">
<FRAME NAME="main" SRC="YourText.html">
<NOFRAMES>
Sorry, this document can only be viewed with a frames-capable browser.
<A HREF="0005pFrames.html">Link to presentation.</A>
</NOFRAMES>
</FRAMESET>
</HTML>

There are only three new tags required for setting up a frame:

Add links to other pages or to various sections of YourText.html in the YourLinks.html. For example, consider the following links:

<HTML>
<HEAD>
<TITLE>Example of YourLinks.html</TITLE>
</HEAD>
<BODY>
<A TARGET="main" HREF="YourText.html">Link to your text.</A><BR>
<A TARGET="main" HREF="YourText.html#Section5">Link to a section.</A>
</BODY>
</HTML>

The TARGET attribute is used to identify the frame to be used for showing the linked page. Recall that the name of the second frame in the above frameset was named "main". By setting the value of TARGET to main, the linked page YourText.html will be displayed in the main window. The next link will cause the browser to look for a name or id of "Section5" in the YourText.html page. The text in the right window will be positioned with Section5 at the top.

Can I change the borders around a frame?
Yes, you can adjust the borders using attributes in either the frameset tag or in the individual frame tags. In a frame tag or a frameset tag, the allowed border attributes are:

If you want to set the border width for both types of browsers, place both the BORDER attribute and the FRAMESPACING attribute in the frame or frameset tag with identical settings. The browser will ignore attributes that it does not understand, so both browsers will work correctly.

Consider the following example:
<HTML>
<HEAD>
<TITLE>Example of a frame</TITLE>
</HEAD>
<FRAMESET FRAMEBORDER=0 BORDERCOLOR="yellow" COLS="20%,*">
<FRAME FRAMEBORDER=1 NAME="menu" SRC="YourLinks.html">
<FRAME NAME="main" SRC="YourText.html">
</FRAMESET>
</HTML>
Note the following rules of precedence:

How do links work within frames?
In the above example, YourLinks.html contains hypertext links to other pages on your web site. Consider the following links contained inside

<A HREF="AnotherPage.html">AnotherPage</A><BR>
<A TARGET="main" HREF="AnotherPage.html">YetAnotherPage</A><BR>
In the first case, AnotherPage.html replaces the same window. This is not what we want. The second hypertext link uses the name of the right frame (see the above example) as the target. The target attribute has the effect of causing AnotherPage.html to replace the page in the main frame, rather than the current frame.

5.2 More Complex Examples

How can I create a new window rather than using an existing frame?
If the value of the target attribute in a hyperlink (see the above example) is a new name that is not the name of any existing frame, a new window is created with that name. Any other links that are selected with the same target value will replace the page in the newly created window.

How can I cancel the extra frames if the user selects a link to another web site?
When the user is selecting frames in the current web site, a navigation frame is helpful. But, when the user selects a link to another web site, the navigation frame is useless, even misleading. For a link to another web site, be sure to use a target of _top. If the link is selected, the top-level window (the entire browser window in this case) will be loaded with the page specified by the link's URL. For example:

<A TARGET="_top" HREF="http://www.some.com/">Some.com</A><BR>
will cause the page specified by the URL to be loaded into the top-level browser window.

Can the user resize a frame?
Yes, the user may click on a border and drag the border of a frame. To disable this feature, include the NORESIZE attribute in the frame tag.

What happens if the page specified by the SRC attribute in a link tag or a frame tag has two frames in it?
The referenced frame is split into two frames. Note that the title of the browser window is the title in the most recently loaded frame in the display. To maintain a consistent appearance, it is best to make all of the titles in the referenced pages the same.

Do not reference a parent frameset inside an inner (nested) frame. The browser will get dizzy.

5.3 Floating Frames

What are "floating" or "inline" frames?
Up until now, frames could not be included in the body of a page. Internet Explorer 3.0 and browsers that support the HTML 4.0 standard allow an inline frame in the body of a page. The frame is treated in much the same way that an inline image is treated. The tag for an inline frame is <iframe>. This tag defines a rectangular region within the document that can display a separate HTML document, including scrollbars and borders (but no title).

The SRC attribute in the iframe tag specifies the URL of the document to be displayed inside the iframe. The content of the iframe tag can include text and links that are only displayed when the browser is non-compliant. Internet Explorer 4.0 and above will display the referenced document instead.

Why would I ever use an inline frame?
You will probably want to avoid inline frames until more browsers support this feature. However, consider the following possibilities:

What attributes are essential in an Iframe tag?
Consider the following HTML snippet to add some canned animation in a 200x100 pixel window with text wrapped around the right side:

...
<IFRAME SRC="animation.html" height=200 width=100 align=left>
You are viewing this text because your browser does not support inline frames. Select the
following < HREF="animation.html">link</A>.  To view inline frames use
Internet Explorer 3.0 or greater.
</IFRAME>
...
Some observations about the above text:

5.4 References

Suggestions? Questions about forms? Send email to: webmaster@tlwilliams.net
Last update: May 7, 2000