Frames in HTML Documents
Frames in HTML Documents
16 Frames
Contents
1. Introduction to frames
2. Layout of frames
1. The FRAMESET element
Rows and columns
Nested frame sets
Sharing data among frames
2. The FRAME element
Setting the initial contents of a frame
Visual rendering of a frame
3. Specifying target frame information
1. Setting the default target for links
2. Target semantics
4. Alternate content
1. The NOFRAMES element
2. Long descriptions of frames
5. Inline frames: the IFRAME element
16.1 Introduction to frames
HTML frames allow authors to present documents in multiple views, which may be
independent windows or subwindows. Multiple views offer designers a way to keep certain
information visible, while other views are scrolled or replaced. For example, within the same
window, one frame might display a static banner, a second a navigation menu, and a third the
main document that can be scrolled through or replaced by navigating in the second frame.
---------------------------------------
| | |
| | |
| Frame 1 | |
| | |
| | |
|---------| |
| | Frame 3 |
| | |
| | |
| | |
| Frame 2 | |
| | |
| | |
| | |
| | |
---------------------------------------
If the user agent can't display frames or is configured not to, it will render the contents of the
NOFRAMES element.
16.2 Layout of frames
An HTML document that describes frame layout (called a frameset document) has a different
makeup than an HTML document without frames. A standard document has one HEAD section
and one BODY. A frameset document has a HEAD, and a FRAMESET in place of the BODY.
The FRAMESET section of a document specifies the layout of views in the main user agent
window. In addition, the FRAMESET section can contain a NOFRAMES element to provide
alternate content for user agents that do not support frames or are configured not to display
frames.
Elements that might normally be placed in the BODY element must not appear before the first
FRAMESET element or the FRAMESET will be ignored.
<![ %HTML.Frameset; [
<!ELEMENT FRAMESET - - ((FRAMESET|FRAME)+ & NOFRAMES?) -- window subdivision-->
<!ATTLIST FRAMESET
%coreattrs; -- id, class, style, title --
rows %MultiLengths; #IMPLIED -- list of lengths,
default: 100% (1 row) --
cols %MultiLengths; #IMPLIED -- list of lengths,
default: 100% (1 col) --
onload %Script; #IMPLIED -- all the frames have been loaded --
onunload %Script; #IMPLIED -- all the frames have been removed --
>
]]>
Attribute definitions
The FRAMESET element specifies the layout of the main user window in terms of rectangular
subspaces.
Setting the rows attribute defines the number of horizontal subspaces in a frameset. Setting
the cols attribute defines the number of vertical subspaces. Both attributes may be set
simultaneously to create a grid.
If the rows attribute is not set, each column extends the entire length of the page. If the cols
attribute is not set, each row extends the entire width of the page. If neither attribute is set,
the frame takes up exactly the size of the page.
Frames are created left-to-right for columns and top-to-bottom for rows. When both
attributes are specified, views are created left-to-right in the top row, left-to-right in the
second row, etc.
The first example divides the screen vertically in two (i.e., creates a top half and a bottom
half).
The next example creates three columns: the second has a fixed width of 250 pixels (useful,
for example, to hold an image with a known size). The first receives 25% of the remaining
space and the third 75% of the remaining space.
<FRAMESET cols="1*,250,3*">
...the rest of the definition...
</FRAMESET>
For the next example, suppose the browser window is currently 1000 pixels high. The first
view is allotted 30% of the total height (300 pixels). The second view is specified to be exactly
400 pixels high. This leaves 300 pixels to be divided between the other two frames. The fourth
frame's height is specified as "2*", so it is twice as high as the third frame, whose height is
only "*" (equivalent to 1*). Therefore the third frame will be 100 pixels high and the fourth will
be 200 pixels high.
<FRAMESET rows="30%,400,*,2*">
...the rest of the definition...
</FRAMESET>
Absolute lengths that do not sum to 100% of the real available space should be adjusted by
the user agent. When underspecified, remaining space should be allotted proportionally to
each view. When overspecified, each view should be reduced according to its specified
proportion of the total space.
In the following example, the outer FRAMESET divides the available space into three equal
columns. The inner FRAMESET then divides the second area into two rows of unequal height.
<FRAMESET cols="33%, 33%, 34%">
...contents of first frame...
<FRAMESET rows="40%, 50%">
...contents of second frame, first row...
...contents of second frame, second row...
</FRAMESET>
...contents of third frame...
</FRAMESET>
Authors may share data among several frames by including this data via an OBJECT element.
Authors should include the OBJECT element in the HEAD element of a frameset document and
name it with the id attribute. Any document that is the contents of a frame in the frameset
may refer to this identifier.
The following example illustrates how a script might refer to an OBJECT element defined for an
entire frameset:
Attribute definitions
1: This value tells the user agent to draw a separator between this frame and every
adjoining frame. This is the default value.
0: This value tells the user agent not to draw a separator between this frame and
every adjoining frame. Note that separators may be drawn next to this frame
nonetheless if specified by other frames.
The FRAME element defines the contents and appearance of a single frame.
The src attribute specifies the initial document the frame will contain.
------------------------------------------
|Frame 1 |Frame 3 |Frame 4 |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
-------------| | |
|Frame 2 | | |
| | | |
| | | |
------------------------------------------
and cause the user agent to load each file into a separate view.
The contents of a frame must not be in the same document as the frame's definition.
ILLEGAL EXAMPLE:
The following frameset definition is not legal HTML since the contents of the second frame
are in the same document as the frameset.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<TITLE>A frameset document</TITLE>
</HEAD>
<FRAMESET cols="50%,50%">
<FRAME src="contents_of_frame1.html">
<FRAME src="#anchor_in_same_document">
<NOFRAMES>
...some text...
<H2><A name="anchor_in_same_document">Important section</A></H2>
...some text...
</NOFRAMES>
</FRAMESET>
</HTML>
The following example illustrates the usage of the decorative FRAME attributes. We specify
that frame 1 will allow no scroll bars. Frame 2 will leave white space around its contents
(initially, an image file) and the frame will not be resizeable. No border will be drawn between
frames 3 and 4. Borders will be drawn (by default) between frames 1, 2, and 3.
Attribute definitions
By assigning a name to a frame via the name attribute, authors can refer to it as the "target" of
links defined by other elements. The target attribute may be set for elements that create links
(A, LINK), image maps (AREA), and forms (FORM).
Please consult the section on target frame names for information about recognized frame
names.
This example illustrates how targets allow the dynamic modification of a frame's contents.
First we define a frameset in the document frameset.html, shown here:
Activating either link opens a new document in the frame named "dynamic" while the other
frame, "fixed", maintains its initial contents.
Note. A frameset definition never changes, but the contents of one of its frames can. Once the
initial contents of a frame change, the frameset definition no longer reflects the current state
of its frames.
There is currently no way to encode the entire state of a frameset in a URI. Therefore, many
user agents do not allow users to assign a bookmark to a frameset.
Framesets may make navigation forward and backward through your user agent's history
more difficult for users.
When many links in the same document designate the same target, it is possible to specify
the target once and dispense with the target attribute of each element. This is done by setting
the target attribute of the BASE element.
We return to the previous example, this time factoring the target information by defining it in
the BASE element and removing it from the A elements.
User agents should determine the target frame in which to load a linked resource according
to the following precedences (highest priority to lowest):
1. If an element has its target attribute set to a known frame, when the element is activated
(i.e., a link is followed or a form is processed), the resource designated by the element
should be loaded into the target frame.
2. If an element does not have the target attribute set but the BASE element does, the BASE
element's target attribute determines the frame.
3. If neither the element nor the BASE element refers to a target, the resource designated by
the element should be loaded into the frame containing the element.
4. If any target attribute refers to an unknown frame F, the user agent should create a new
window and frame, assign the name F to the frame, and load the resource designated by
the element in the new frame.
User agents may provide users with a mechanism to override the target attribute.
The NOFRAMES element specifies content that should be displayed only by user agents that do
not support frames or are configured not to display frames. User agents that support frames
must only display the contents of a NOFRAMES declaration when configured not to display
frames. User agents that do not support frames must display the contents of NOFRAMES in any
case.
The NOFRAMES element is part of both the transitional and frameset DTDs. In a document that
uses the frameset DTD, NOFRAMES may be used at the end of the FRAMESET section of the
document.
For example:
NOFRAMES may be used, for example, in a document that is the source of a frame and that uses
the transitional DTD. This allows authors to explain the document's purpose in cases when it is
viewed out of the frameset or with a user agent that doesn't support frames.
The longdesc attribute allows authors to make frame documents more accessible to people
using non-visual user agents. This attribute designates a resource that provides a long
description of the frame. Authors should note that long descriptions associated with frames
are attached to the frame, not the frame's contents. Since the contents may vary over time,
the initial long description is likely to become inappropriate for the frame's later contents. In
particular, authors should not include an image as the sole content of a frame.
The following frameset document describes two frames. The left frame contains a table of
contents and the right frame initially contains an image of an ostrich:
Note that the image has been included in the frame independently of any HTML element, so
the author has no means of specifying alternate text other than via the longdesc attribute. If
the contents of the right frame change (e.g., the user selects a rattlesnake from the table of
contents), users will have no textual access to the frame's new content.
Thus, authors should not put an image directly in a frame. Instead, the image should be
specified in a separate HTML document, and therein annotated with the appropriate alternate
text:
Attribute definitions
The IFRAME element allows authors to insert a frame within a block of text. Inserting an inline
frame within a section of text is much like inserting an object via the OBJECT element: they
both allow you to insert an HTML document in the middle of another, they may both be
aligned with surrounding text, etc.
The information to be inserted inline is designated by the src attribute of this element. The
contents of the IFRAME element, on the other hand, should only be displayed by user agents
that do not support frames or are configured not to display frames.
For user agents that support frames, the following example will place an inline frame
surrounded by a border in the middle of the text.
Inline frames may not be resized (and thus, they do not take the noresize attribute).
Note. HTML documents may also be embedded in other HTML documents with the OBJECT
element. See the section on embedded documents for details.
previous next contents elements attributes index