The basic structure of a framed document is shown in the example
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Framed</title>
</head>
<frameset cols="25%,*">
<frame src="ax.txt" id="linus" />
<frame src="ay.txt" id="larry" />
<noframes>
<body>
<h1>Hello World.</h1>
</body>
</noframes>
</frameset>
</html>
Note that:
XHTML 1.0 Framesetbody element is contained within a noframes element. It will be rendered if the user agent does not support frames.Each individual frame element specifies a document which is displayed in the frame. Notice that the syntax is very similar to that used for images.
In this example, the document ax.txt will be loaded into frame "linus" and ay.txt will be loaded into frame "larry".
Displayed document
| Vertical frames | Horizontal frames |
|---|---|
![]() |
![]() |
The number of columns or rows is determined by the cols or rows attribute.
The values are the widths (or heights) of the columns or rows, in order.
The values are integers (pixels, but without px), percentatges, or *. The * value will be whatever remains after the others are calculated.
For example, the frameset
<frameset rows="50, 50%, *">
divides the window into three rows. The first is 50 pixels in hieght; the second is 50% of the window height; the third is whatever is left over.
A frame has an attribute called scrolling. The possible values are auto, yes, or no.
The presence or absence of a visible division between frames in a graphic browser is determined by the frameborder attribute.
The value is either 1 or 0.
A value of 1 tells the user agent to draw a separator between this frame and every adjoining frame. This is the default value.
A value of 0 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.
Document illustrating scrolling and frameborder. The first frame has scrolling set to no, and the second to yes.
Another frameset may be used instead of a frame. This will subdivide the parent frame.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>re-Split frames</title>
</head>-+*
<frameset cols="60%, *">
<frameset rows="60%, *">
<frame src=x.htm >
<frame src=y.htm >
</frameset>
<frameset rows="200, *">
<frame src=x2.txt >
<frame src=y2.txt >
</frameset>
<noframes>
<body>
<h1>Hello World.</h1>
</body>
</noframes>
</frameset>
</html>
Nesting will also be produced in the display if one of the individual frame sources is itself a framed document.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Nested Frames</title>
</head>
<frameset rows=50%,*>
<frame src=frames_split.htm>
<frameset cols=200,*>
<frame src="y2.htm">
<frame src=x2.htm>
</frameset>
</frameset>
</html>
By default, linked documents will be opened in the same frame as the document with the link.
In XHTML Transitional, the anchor element can specify a target attribute.
Only frames or windows with ids (or names, in older usage) can be the target of links:
Suppose the root (top) document has:
<frameset cols="25%,*">
<frame src="x4.htm" id="larry">
<frame src="y4.htm" id="linus">
</frameset>
and the file x4.htm includes the lines
<a href="pics/01.jpg" target="linus">cats!</a>
When the link "cats!" is clicked, the document 01.jpg will be displayed in the frame with id "linus"
The x4.htm document must have DOCTYPE XHTML 1.0 Transitional (or an HTML version, not XHTML) to be valid.
The target attribute is deprecated and is not valid in XHTML Strict. The reason is that target describes an action or behavior.
The intent of the W3C standard is that XHTML deals with content, CSS with presentation, and JavaScript with behavior.
It is possible, but more complex, to achieve the same result as target with strict XHTML by using JavaScript.
Several targets are pre-identified. Their names begin with an underscore.