Lesson 14: The Frameset Element
Learn about HTML framesets for creating multi-pane layouts (Note: Deprecated in HTML5)
Start LearningUnderstanding the Frameset Element
The HTML <frameset> element allows you to create a layout with multiple independent panes (frames) within a single browser window. Each frame can display a different HTML document.
<iframe> element.
How Framesets Work
Framesets divide the browser window into multiple sections:
- Columns: Vertical divisions using the
colsattribute - Rows: Horizontal divisions using the
rowsattribute - Frames: Individual containers using the
<frame>element
Creating Columns and Rows
Framesets use the cols and rows attributes to define the layout structure:
| Attribute | Description | Values | Example |
|---|---|---|---|
cols |
Defines vertical columns | Pixel values, percentages, or asterisk (*) | cols="200,*" |
rows |
Defines horizontal rows | Pixel values, percentages, or asterisk (*) | rows="100,*" |
Basic Column Layout
<!DOCTYPE html>
<html>
<head>
<title>Two Column Layout</title>
</head>
<frameset cols="30%,70%">
<frame src="menu.html" name="menu">
<frame src="content.html" name="content">
</frameset>
</html>
Result:
Menu content would appear here
- Home
- About
- Contact
Main Content
This is where the primary content of the page would appear.
Basic Row Layout
<!DOCTYPE html>
<html>
<head>
<title>Two Row Layout</title>
</head>
<frameset rows="100,*">
<frame src="header.html" name="header">
<frame src="content.html" name="content">
</frameset>
</html>
Result:
Nested Framesets
You can create complex layouts by nesting framesets within other framesets:
<!DOCTYPE html>
<html>
<head>
<title>Nested Frameset Example</title>
</head>
<frameset cols="20%,*">
<frame src="menu.html" name="menu">
<frameset rows="100,*">
<frame src="banner.html" name="banner">
<frame src="content.html" name="content">
</frameset>
</frameset>
</html>
Result:
Navigation menu
Banner Frame (100px)
Content Frame
Main content area below the banner
Frame Attributes
Individual frames can be customized with various attributes:
| Attribute | Description | Values |
|---|---|---|
src |
URL of the document to display in the frame | Any valid URL |
name |
Unique name for targeting links | Alphanumeric string |
scrolling |
Controls scrollbar visibility | yes, no, auto |
noresize |
Prevents user from resizing the frame | Boolean (no value needed) |
frameborder |
Shows or hides frame borders | 1 (show) or 0 (hide) |
marginwidth |
Left/right margins within the frame | Pixel value |
marginheight |
Top/bottom margins within the frame | Pixel value |
Frame Attributes in Action
<frame src="content.html" name="main" scrolling="no" noresize frameborder="0" marginwidth="10" marginheight="15" >
Result:
No Scrollbars
scrolling="no" prevents scrollbars from appearing
Fixed Size
noresize prevents users from dragging frame borders
Borderless
frameborder="0" hides the border around the frame
Targeting Frames with Links
The target attribute in anchor tags specifies which frame should display the linked content:
<!-- Menu frame content -->
<ul>
<li><a href="home.html" target="content">Home</a></li>
<li><a href="about.html" target="content">About</a></li>
<li><a href="contact.html" target="content">Contact</a></li>
<li><a href="http://example.com" target="_blank">External Site</a></li>
</ul>
Special Target Values
| Target Value | Description |
|---|---|
_self |
Load in the same frame (default) |
_blank |
Load in a new window or tab |
_parent |
Load in the parent frameset |
_top |
Load in the full body of the window |
framename |
Load in a named frame |
The noframes Element
The <noframes> element provides fallback content for browsers that don't support frames:
<frameset cols="25%,75%">
<frame src="menu.html">
<frame src="content.html">
<noframes>
<body>
<h1>Your browser doesn't support frames</h1>
<p>Please <a href="no-frames.html">click here</a>
to view the frameless version of our site.</p>
</body>
</noframes>
</frameset>
Modern Alternatives
Since framesets are deprecated, consider these modern approaches for similar layouts:
| Technique | Description | Example |
|---|---|---|
| CSS Flexbox | One-dimensional layout model for flexible containers | display: flex; |
| CSS Grid | Two-dimensional grid-based layout system | display: grid; |
| Iframes | Embeds another HTML page within the current page | <iframe src="content.html"> |
| AJAX | Load content dynamically without full page reloads | JavaScript fetch API |
| Single Page Apps | Modern frameworks that handle content dynamically | React, Angular, Vue.js |
CSS Grid Example (Modern Alternative)
<div class="container">
<nav class="sidebar">Navigation Menu</nav>
<header class="banner">Site Banner</header>
<main class="content">Main Content</main>
</div>
<style>
.container {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-rows: 80px 1fr;
height: 100vh;
}
.sidebar {
grid-row: 1 / 3;
background: #2c3e50;
color: white;
}
.banner {
grid-column: 2;
background: #2196f3;
color: white;
}
.content {
grid-column: 2;
padding: 20px;
}
</style>
Practical Exercise: Create a Frameset Layout
Create a frameset-based layout for the following scenario:
Your Task:
Create a documentation site with:
- A top banner frame (100px height)
- A left navigation frame (250px width)
- A main content area (remaining space)
- Navigation links that load content in the main frame
- Proper noframes fallback content
Tips:
- Use nested framesets: outer frameset for rows, inner for columns
- Name your frames: "banner", "menu", "content"
- Set
target="content"in your navigation links - Include meaningful noframes content