Layout with Frames

Frames are considered transitional by W3C. I use them because they are quite reliable when used within a frameset, more so than the methods designed to replace them. They have the advantage that:

Other means of accomplishing the same effects are possible with some browsers. See Layout with Positioning for a discussion of the issues.

The disadvantage of frames is that the address bar does not change with changes in the main frame. It remains fixed with the address of the outermost frame, that which contains all the other frames. Similarly, search engines have a hard time finding their way around frames.

How to Use Frames

When a page is to contain more than one window (or frame), the <frameset> tags are used instead of the <body> tags. Within the <frameset> tag is placed either the cols attribute, or the rows attribute; this determines how the frames will be spaced, whether in columns or rows, and designates the amount of space to be allotted for each frame.
  <frameset cols="12%,24%,*">
The above example provides for three columns, one occupying 12% of the space, one 24%, and the other the rest of the space.

Between the start and stop frameset tags are placed as many <frame> elements, as were designated by the frameset tag.

Each <frame> tag has a src attribute, giving the name of the html file to be opened in the frame. There is no closing frame tag.

    <title>An Example of Frames</title>
  <frameset cols="12%,*">
    <frame src="htmside" name="side">
    <frame src="htmmain" name="main">

Nesting Frameset Elements

Framesets can be nested. This is done by substituting a frameset element for a frame. For example, here is the code that determines the frames for this page. Note that each frame was given a name.
  <title>Nested Framesets</title>
<frameset rows="9%,*">
  <frame src="htmbannr.html" name="top">
  <frameset cols="18%,*">
    <frame src="htmtoc.html" name="menu">
    <frame src="htmhome.html" name="main">

Menu Bar -- Targeting a Window

When you wish to click a link in one frame, and have it open in another frame, the target attribute is used within the anchor tag. The target is set equal to the name of the frame in which the link should open.

The frame on the left side of this page, containing my menu, is populated with links such as the following.

  <a href="htmhome.html"  target="main">Home    </a>
This code causes the file "htmhome.html" to open in the frame named "main".