## Frames

Frames give you a way to organize and structure the content of your HTML documents by letting you create compound documents that the user can view within the main window of Internet Explorer. To use frames, you create a document that uses the FRAMESET and FRAME elements to divide the main window into rectangular frames (like panes in a window). Then, for each frame, you specify an HTML document that contains the content (text and images) to fill the frame. Floating frames enable you to open a browser within a browser. You can insert a floating frame in the same manner in which you can insert an image on an HTML page. You can specify the size of the frame and its border, and you can align it with other text and images on the page. With frames, you can create sophisticated layouts that add and mix sounds, video, animation, and colors. Using two frames in a single page, you can display an index in one frame and the content in another. For example, you can split the main window into two equal frames and fill these with different documents by using the following elements:

    <HTML>
    <HEAD>
    <TITLE>Two Equal Frames</TITLE>
    </HEAD>
    <FRAMESET COLS="50%,*">
    <FRAME SRC=x.htm>
    <FRAME SRC=y.htm>
    </FRAMESET>
    </HTML>

Click here to see demo.

In this example, the COLS= attribute in the FRAMESET element specifies the width of the frames. The width of the first frame is 50 percent of the main window, and the width of the second, given as an asterisk, is relative to the first (meaning it spans whatever is left of the main window). Note that this document does not contain a BODY element. This is because documents that define frames do not contain content. Instead, the SRC= attribute in each FRAME element specifies a document. In this example, the x.htm and y.htm files are content sources for the frames.

You can divide the main window into rows, as well as columns, by using the ROWS= attribute. Furthermore, you can independently divide individual rows into rows and columns by nesting FRAMESET elements. The following example shows how to divide the main window into two rows in which the last row is divided into two columns:

    <HTML>
    <HEAD>
    <TITLE>Nested Frames</TITLE>
    </HEAD>
    <FRAMESET ROWS="10%,*">
    <FRAME SCROLLING=NO SRC=z.htm>
    <FRAMESET COLS="50%,*">
    <FRAME SRC=x.htm>
    <FRAME SRC=y.htm>
    </FRAMESET>
    </FRAMESET>
    </HTML>

In this example, the SCROLLING= attribute is used in the first FRAME element to prevent the scroll bar from being displayed. By default, Internet Explorer displays the scroll bar only if the entire content of the frame does not fit within the frame. Setting SCROLLING= to NO always prevents the scroll bar.

The FRAME element has attributes to let you set the width and height of margins within the frame, and whether the frame has a border. The FRAMESET element has attributes to let you set the spacing between frames, and whether the frames in the set have borders.

An important feature of the FRAME element is the NAME= attribute. This attribute lets you assign a unique name to the frame; you then use this name when creating hyperlinks to direct documents into the frame. To create such a hyperlink, use the TARGET= attribute in the A element. For example, the following element creates a hyperlink that displays the x.htm file in a frame named CONTENT:

    <A HREF="x.htm" TARGET="CONTENT">List of Components</A>

Internet Explorer provides an alternate way to create compound documents by letting you place frames in your HTML document using the IFRAME element. Called "floating frames," this design technique allows you to insert HTML documents into your document in the same way you insert images using the IMG element. This means you can use the ALIGN= attribute just as you do with IMG to align the frame with the surrounding text. The following example aligns a frame at the left margin and wraps subsequent text around the right side of the frame:

    <IFRAME SRC="xx.htm" ALIGN=LEFT>
    </IFRAME> Here's some text to the right of a frame.
    <BR CLEAR=LEFT>Here's some text beneath the frame.

This displays as:

Here's some text to the right of a frame.
Here's some text beneath the frame.

The IFRAME syntax might not be compatible with all browsers. In that case, you can use a FRAME element within the IFRAME tags to provide an alternative presentation. For example:

    <IFRAME SRC="xx.htm" ALIGN=LEFT><FRAME SRC="xx.htm">
    <IFRAME>

In the previous example, the text of xx.htm will display in a floating frame in either an IFRAME or non-IFRAME-compatible browser. Remember that you set the attributes of IFRAME and FRAME independently. For example, if you want to specify position or size, you include those attributes in both the IFRAME tag and the FRAME tag.

© 1996 Microsoft Corporation