Section 11.4. Frame Contents

A frame document contains no displayable content, except perhaps a message for non-frames-enabled browsers. Instead, <frame> tags inside the one or more <frameset> tags (which encapsulate the contents of a frame document) provide URL references to the individual documents that occupy each frame. [<noframes>]

11.4.1 The <frame> Tag

The <frame> tag appears only within a <frameset>. Use it to set, via its associated src attribute, the URL of the document content that initially gets displayed inside the respective frame.



Defines a single frame in a <frameset>


bordercolor (figs/n.gif, figs/i.gif), class, frameborder, id, longdesc, marginheight, marginwidth, name, noresize, scrolling, src, style, title

End tag:

</frame>; rarely included in HTML



Used in:


Browsers place the frame contents into the frameset column by column, from left to right, and then row by row, from top to bottom. Accordingly, the sequence and number of <frame> tags inside the <frameset> tag are important.

The browser displays empty frames for <frame> tags that do not have src attributes. It also displays empty frames if the <frameset> tag calls for more frames than the corresponding <frame> tags define; for instance, if your frame document calls for three columns and you provide only five frames. Orphan frames remain empty, and you cannot put content into them later, even if they have a target name or id for display redirection. [Section] The src attribute

The value of the src attribute for the <frame> tag is the URL of the document that is to be displayed in the frame. There is no other way to provide content for a frame. You shouldn't, for instance, include any <body> content within the frame document; the browser ignores the frame tags and displays just the contents of a <body> tag if it comes first, or vice versa.

The document referenced by the src attribute may be any valid document or any displayable object, including images and multimedia. In particular, the referenced document may itself be composed of one or more frames. The frames are displayed within the referencing frame, providing yet another way of achieving complex layouts using nested frames.

Since the source may be a complete document, all the features of HTML/XHTML apply within a frame, including backgrounds and colors, tables, fonts, and the like. Unfortunately, this also means that multiple frames in a single browser window may conflict with each other. Specifically, if each nested frame document (not a regular HTML or XHTML document) has a different <title> tag, the title of the overall browser window is the title of the most recently loaded frame document. The easiest way to avoid this problem is to ensure that all related frame documents use the same title. The name and id attributes

The optional name attribute for the <frame> tag labels that frame for later reference by a target attribute for the hypertext link anchor (<a>) tag and the <form> tag. This way, you can alter the contents of a frame using a link in another frame. Otherwise, like normal browser windows, hypertext-linked documents replace the contents of the source frame. We discuss names and targets at greater length later in this chapter. [Section 11.7.1]

Similarly, the id attribute uniquely identifies a frame, but the browsers do not support its use for target redirection, even though they do support id's use as a hyperlink target in many other HTML and XHTML tags.

The value of the name or id attribute is a text string enclosed in quotation marks. The noresize attribute

Even though you may explicitly set frame dimensions with attributes in the <frameset> tag, users can manually alter the size of a column or row of frames. To suppress this behavior, add the noresize attribute to the frame tags in the row or column whose relative dimensions you do not want users fiddling with. For example, for a two-by-two frame document, a noresize attribute in any one of the four associated frame tags effectively freezes the relative proportions of all the frames.

The noresize attribute is especially useful for frames that contain fixed images serving as advertisements, a button bar, or a logo. By fixing the size of the frame to contain just the image and setting the noresize attribute, you guarantee that the image is displayed in the intended manner and that the remainder of the browser window is always given over to the other frames in the document. The scrolling attribute

The browser displays vertical and horizontal scrollbars with frames whose contents are larger than the allotted window space. If there is sufficient room for the content, the scrollbars disappear. The scrolling attribute for the <frame> tag gives you explicit control over whether the scrollbars appear or disappear.

With scrolling="yes", Internet Explorer, but not Netscape, adds scrollbars to the designated frame even if there is nothing to scroll. If you set the scrolling attribute value to no, scrollbars are never added to the frame, even if the frame contents are larger than the frame itself. The value auto, supported only by Netscape, works as if you didn't include the scrolling attribute in the tag; Netscape adds scrollbars only as needed. To achieve auto behavior in Internet Explorer, simply omit the scrolling attribute altogether. The marginheight and marginwidth attributes

The browser normally places a small amount of space between the edge of a frame and its contents. You can change those margins with the marginheight and marginwidth attributes, each including a value for the exact number of pixels to place around the frame's contents.

You cannot make a margin less than 1 pixel or make it so large that there is no room for the frame's contents. That's because, like most other HTML attributes, these advise ? they do not dictate to the browser. If your desired margin values cannot be accommodated, the browser ignores them and renders the frame as best it can. The frameborder and bordercolor attributes

You can add or remove borders from a single frame with the frameborder attribute. Values of yes or 1 and no or 0 respectively enable or disable borders for the frame and override the value of the frameborder attribute for any frameset containing the frame.

Note that the browsers do react somewhat differently to border specifications. Netscape, for instance, removes an individual border only if adjacent frames sharing that border have borders turned off. Internet Explorer, on the other hand, removes those adjacent borders, but only if they are not explicitly turned on in those adjacent frames. Our advice is to explicitly control the borders for each frame if you want to consistently control the borders for all frames across both browsers.

With the popular browsers, you also can change the color of the individual frame's borders with the bordercolor attribute. Use a color name or hexadecimal triple as its value. If two adjacent frames have different bordercolor attributes, the resulting border color is undefined. You can find a complete list of color names and values in Appendix G. The title and longdesc attributes

Like most other standard tags, you can provide a title for a frame with the title attribute. The value of the attribute is a quote-enclosed string that describes the contents of the frame. Browsers might display the title, for instance, when the mouse passes over the frame.

If the title attribute isn't quite enough for you, the longdesc attribute can be used. Its value is the URL of a document that describes the frame. Presumably, this long description might be in some alternative media, suitable for use by a nonvisual browser.