Table of contents
1.
Introduction
2.
Syntax
3.
Examples
3.1.
Example 1: Creating Rows
3.2.
Example 2: Creating Columns
4.
Attributes
5.
Defining Rows and Columns
5.1.
Example
6.
How to Load Different Pages in Frames?
6.1.
Example
7.
How to Nest Framesets within One Another?
7.1.
Example
8.
Benefits and Challenges in HTML Framesets
8.1.
Benefits
8.2.
Challenges
9.
Importance of Testing Websites on Real Devices
10.
Common Attributes in HTML Frameset <frameset>
11.
Supporting Browsers
12.
Frequently Asked Questions
12.1.
What is the purpose of the <frame> tag in HTML?
12.2.
Can the <frame> tag be used in modern HTML?
12.3.
What is the difference between <frame> and <iframe> in HTML?
13.
Conclusion
Last Updated: Dec 20, 2024
Easy

Frame Tag in HTML

Author Pallavi singh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The HTML <frame> tag was a feature that allowed developers to split a single web page into multiple sections, with each section displaying a different document. This technique was commonly used to create layouts with navigation menus on one side and content displayed alongside them. However, it is worth noting that the <frame> tag has been deprecated in HTML5 and is no longer recommended for modern web development.

Frame Tag in HTML

In this article, you will learn about the syntax of the <frame> tag, its attributes, and how to use it effectively.

Syntax

The <frame> tag is used within the <frameset> tag, which replaces the <body> tag when creating a frameset. Here's the basic syntax:

<frameset rows="row_specification" cols="col_specification">
    <frame src="URL1">
    <frame src="URL2">
    <!-- Additional frames can be added here -->
</frameset>
  • rows: Specifies the number and size of rows in the frameset.
     
  • cols: Specifies the number and size of columns in the frameset.
     
  • src: Defines the source URL for the frame content.

Examples

Example 1: Creating Rows

<frameset rows="50%, 50%">
    <frame src="header.html">
    <frame src="content.html">
</frameset>


This example divides the browser window into two horizontal frames: one for the header and the other for the main content.

Example 2: Creating Columns

<frameset cols="30%, 70%">
    <frame src="menu.html">
    <frame src="main.html">
</frameset>


Here, the window is split vertically into two sections, with 30% allocated for a navigation menu and 70% for the main content.

Attributes

The <frame> tag includes several attributes that make it useful:
The src attribute states the URL of the document to be displayed in the frame.
Example:

<frame src="page.html">


name: Assigns a name to the frame for targeting links.
Example:

<frame name="mainFrame" src="main.html">


scrolling: Determines whether scrollbars appear in the frame.

Values: yes, no, auto

Example:

<frame src="content.html" scrolling="no">


noresize: Prevents users from resizing the frame.

Example:

<frame src="menu.html" noresize>


frameborder: Controls the visibility of the border around the frame.

Example:

<frame src="page.html" frameborder="0">

Defining Rows and Columns

Framesets allow you to define rows and columns for a structured layout. The rows and cols attributes can accept:

  • Percentages: Allocate a percentage of the screen space.
     
  • Pixel values: Set fixed sizes.
     
  • Asterisks (*): Allocate remaining space.

Example

<frameset rows="100, *" cols="*, 200">
    <frame src="top.html">
    <frame src="bottom.html">
    <frame src="side.html">
    <frame src="main.html">
</frameset>


This creates a layout with defined rows and columns, distributing space flexibly.

How to Load Different Pages in Frames?

You can use the target attribute in links to specify which frame a new page should load into.

Example

<frameset cols="30%, 70%">
    <frame src="menu.html" name="menuFrame">
    <frame src="home.html" name="contentFrame">
</frameset>


<a href="about.html" target="contentFrame">About Us</a>
<a href="services.html" target="contentFrame">Services</a>


Clicking on the links will load the respective pages into the contentFrame.

How to Nest Framesets within One Another?

Nesting framesets allows you to create complex page layouts by dividing the page into multiple rows and columns. You can achieve this by placing one or more <frameset> tags inside another <frameset> tag. Let’s take an example that shows nested framesets:

Example

<!DOCTYPE html>
<html>
<head>
  <title>Nested Framesets Example</title>
</head>
<frameset rows="40%,60%">
  <frame src="header.html">
  <frameset cols="30%,70%">
    <frame src="navigation.html">
    <frame src="content.html">
  </frameset>
</frameset>
</html>


In this example:

1. The outer <frameset> tag divides the page into two rows. The first row takes up 40% of the page height and contains a frame that loads the "header.html" file.
 

2. The second row occupies the remaining 60% of the page height and contains another nested <frameset> tag.
 

3. The nested <frameset> tag divides the second row into two columns. The first column takes up 30% of the width and loads the "navigation.html" file, while the second column occupies the remaining 70% and loads the "content.html" file.

Benefits and Challenges in HTML Framesets

Benefits

  1. Seamless Navigation: Keep navigation menus and swap content.
     
  2. Reduced Loading Time: Only parts of the page reload instead of the whole page.
     
  3. Ease of Layout Design: It makes splitting content into sections easier.

Challenges

  1. Limited Accessibility: Not suitable for screen readers or mobile devices.
     
  2. Complex URL Management: It is not easy to bookmark specific content.
     
  3. Deprecated: Frames are not supported in HTML5 and modern web development does not encourage them.

Importance of Testing Websites on Real Devices

Testing your frameset layout on real devices ensures:

  1. Cross-browser Compatibility: Frames are loading fine in different browsers.
     
  2. Responsive Design: Usability is tested on smaller screens.
     
  3. User Experience: Scrollbars, navigation, and resizing should work smoothly.

Common Attributes in HTML Frameset <frameset>

The <frameset> tag was used to contain one or more <frame> tags, defining the overall layout of the page. It has several common attributes:

1. rows: Specified the height of each row in the frameset, either in pixels or percentages. For example: 

<frameset rows="50%,50%">


2. cols: Specified the width of each column in the frameset, similar to the rows attribute. For example:

<frameset cols="25%,75%">


3. border: Set the border width around each frame in pixels. A value of 0 removed the border entirely. For example:

<frameset border="1">


4. frameborder: Controlled the visibility of frame borders. A value of 1 (default) displayed borders, while 0 removed them. For example:

<frameset frameborder="0">


5. framespacing: Defined the amount of space between frames in pixels. For example: 

<frameset framespacing="10">

 

Let’s take a basic example of a frameset :

<!DOCTYPE html>
<html>
<head>
  <title>Nested Framesets with Attributes Example</title>
</head>
<frameset rows="100,*" frameborder="1" border="1" framespacing="5">
  <frame src="header.html" noresize="noresize">
  <frameset cols="150,*" frameborder="1" border="1" framespacing="5">
    <frame src="navigation.html" noresize="noresize">
    <frame src="content.html" name="main_content">
  </frameset>
</frameset>
</html>


In this example:

1. The outer <frameset> tag divides the page into two rows. The first row is 100 pixels high and contains a frame that loads the "header.html" file. The second row takes up the remaining height using the asterisk (*).
 

2. The outer <frameset> tag uses the following attributes:
 

   - frameborder="1": Displays a border around each frame.
 

   - border="1": Sets the border width to 1 pixel.
 

   - framespacing="5": Adds 5 pixels of spacing between the frames.
 

3. The inner <frameset> tag divides the second row into two columns. The first column is 150 pixels wide and loads the "navigation.html" file. The second column takes up the remaining width.
 

4. The inner <frameset> tag also uses the frameborder, border, and framespacing attributes.
 

5. The <frame> tags have additional attributes:
 

   - noresize="noresize": Prevents the user from resizing the frame.
 

   - name="main_content": Assigns a name to the frame loading "content.html", which can be used as a target for hyperlinks.

Supporting Browsers

The <frame> tag is supported by older browsers but not by modern HTML5-compliant browsers. Below is a summary:

BrowserSupported Versions
Internet ExplorerAll versions
FirefoxVersion 1.0 to 3.6
ChromeNot supported
SafariNot supported
EdgeNot supported

Developers are encouraged to use <iframe> or CSS layouts for better compatibility.

Frequently Asked Questions

What is the purpose of the <frame> tag in HTML?

The <frame> tag allows dividing a web page into multiple sections, each capable of displaying different content.

Can the <frame> tag be used in modern HTML?

No, that is a frame tag of HTML5 which is deprecated because earlier it used to break the browser window into lots of frames using HTML, nowadays it's just done in CSS and JavaScript.

What is the difference between <frame> and <iframe> in HTML?

The <frame> tag was used to define several frames within a <frameset>, thus breaking up the content of a webpage into several sections. The <iframe> tag, which embeds another webpage or content within a single frame on the current page, is also still supported in modern HTML.

Conclusion

In this article, we discussed through the HTML frame tag, its syntax and attributes, and even on use cases. We learned you how to develop frameset rows, columns and even nested frameset of loading different pages with one single frame. 

Live masterclass