Frames in HTML
Frames in HTML
Frames in HTML
In HTML, frames enable you present multiple HTML documents within the same window. For example, you can
have a left frame for navigation and a right frame for the main content. Frames are achieved by creating a
frameset page, and defining each frame from within that page. This frameset page doesn't actually contain any
content - just a reference to each frame. The HTML frame tag is used to specify each frame within the frameset.
All frame tags are nested with a frameset tag.
So, in other words, if you want to create a web page with 2 frames, you would need to create 3 files - 1 file
for each frame, and 1 file to specify how they fit together.
1. Creating Frames
Two Column Frameset
HTML Code:
The frameset (frame_example_frameset_1.html):
<html>
<head>
<title>Frameset page<title>
</head>
<frameset cols = "25%, *">
<frame src ="frame_example_left.html" />
<frame src ="frame_example_right.html" />
</frameset>
</html>
The left frame (frame_example_left.html):
<html>
<body style="background-color:green">
<p>This is the left frame (frame_example_left.html).</p>
</body>
</html>
The right frame (frame_example_right.html):
<html>
<body style="background-color:yellow">
<p>This is the right frame (frame_example_right.html).</p>
</body>
</html>
2|P a g e
Lecture Notes 4 (Part 2)
Frames in HTML
HTML Code:
The frameset (frame_example_frameset_4.html):
<html>
<head>
<title>Frameset page</title>
</head>
<frameset border="0" frameborder="0" framespacing="0" cols = "25%, *">
<frame src ="/html/tutorial/frame_example_left_2.html" />
<frame name="content" src ="/html/tutorial/frame_example_yellow.html" />
</frameset>
</html>
The left frame (frame_example_left_2.html):
<html>
<body style="background-color:green">
<p>This is the left frame (frame_example_left_2.html).</p>
<p>
<a target="content" href="frame_example_yellow.html">Yellow</a><br />
<a target="content" href="frame_example_lime.html">Lime</a>
</p>
</body>
</html>
The yellow frame (frame_example_yellow.html):
<html>
<body style="background-color:yellow">
<p>This is the yellow frame (frame_example_yellow.html).</p>
</body>
</html>
The lime frame (frame_example_lime.html):
<html>
<body style="background-color:Lime">
<p>This is the lime frame (frame_example_lime.html).</p>
</body>
</html>
5. Tag Reference
Here's some more info on the above tags.
The frameset Tag
In your frameset tag, you specify either cols or rows, depending on whether you want frames to go vertically or
horizontally.
Attribute Description
rows Specifies the number of rows and their height in either pixels, percentages, or relative
lengths. Default is 100%
cols Specifies the number of columns and their width in either pixels, percentages, or relative
lengths. Default is 100%
3|P a g e
Lecture Notes 4 (Part 2)
Frames in HTML
The frame Tag
For each frame you want to display, you specify a frame tag. You nest these within the frameset tag.
Attribute Description
name Assigns a name to a frame. This is useful for loading contents into one frame from
another.
longdesc A long description - this can elaborate on a shorter description specified with the title
attribute.
src Location of the frame contents (for example, the HTML page to be loaded into the frame).
noresize Specifies whether the frame is resizable or not (i.e. whether the user can resize the frame
or not).
scrolling Whether the frame should be scrollable or not (i.e. should scrollbars appear). Possible
values:
• auto
• yes
• no
frameborder Whether the frame should have a border or not. Possible values:
• 1 (border)
• 0 (no border)
marginwidth Specifies the margin, in pixels, between the frame's contents and it's left and right
margins.
marginheight Specifies the margin, in pixels, between the frame's contents and it's top and bottom
margins.
4|P a g e