How to Create Frames in HTML

In this article, we will comprehend how to create frames in HTML. Let us first know about HTML frames.

HTML Frames

The HTML frames are used to split the web browser window into many sections. These sections or parts are not dependent on each other and they are loaded separately.

HTML frames display the document in multiple views. For instance, one frame can display a navigation bar, the other frame can display the main content, etc.

An HTML table consists of rows and columns. In the same way, the web browser window is split into frames to create many sections.

A group of frames on a web browser window is called a frameset.

Creating frames

We can create frames in HTML utilizing <frameset> tag and <frame> tag. The <frameset> tag is used in place of the <body> tag for creating frames on a webpage. If we use the <body> tag along with the <frameset> tag then the code will not work.

<frameset> tag and <frame> tag

The <frameset> tag is utilized to divide the window into frames. It contains one or more frames which are defined utilizing the <frame> tag.

Syntax:

The <frameset> is the opening tag and the <frameset> is the closing tag. The <frame> tag is a self-closing tag.

Note: The <frameset> tag and <frame> tag are not recommended to use because they are not supported in HTML5.

There are various attributes that are used in <frameset> and <frame> tags that we will discuss one by one.

Attributes of <frameset> tag:

AttributeDescription
ColsThe cols attribute is utilized to define the number of columns present in the frameset and the size of each column in the frameset.
It creates vertical frames and the value of the cols attribute can be in pixels, percentages, etc.
Example: <frameset cols = "20%, 50%, 30%">
The above example creates three column frames on the web browser. For two frames, two values will be given. For three frames, three values will be given and so on.
RowsThe rows attribute is utilized to define the number of rows present in the frameset and the size of each row in the frameset.
It creates horizontal frames and the value of the rows attribute can be in pixels, percentages, etc.
Example: <frameset cols = "25%, 75%">
The above example creates two-row frames on the web browser.
BorderThe width attribute is utilized to define the width of the border of each frame.
frameborderThe frameborder attribute defines whether to display a 3-D border between frames or not. It takes only two values either "0" or "1".
The value "0" defines no frame border and the value "1" defines a 3-D frame border.
framespacingThe framespacing attribute defines a space between frames. It takes an integer value.

Attributes of <frame> tag:

AttributeDescription
nameThe "name" attribute is utilized to provide the name to the frame.
SrcThe "src" attribute is utilized to provide the URL of the frame.
marginwidthThe "marginwidth" attribute is utilized to define the space between the left and the right of the borders of the frame and the content of the frame.
marginheightThe "marginheight" attribute is utilized to define the space between the top and the bottom of the borders of the frame and the content of the frame.
frameborderThe "frameborder" attribute defines whether or not to demonstrate a frame border. It takes only two values either "0" or "1".
The value "0" means "Yes" and "1" means "No".
noresizeThe "noresize" attribute is utilized to stop the user from changing the size of the frame. Example: noresize = "noresize"
longdescThe "longdesc" attribute is utilized to give a link to another page which consists of a long description.
scrollingThe "scrolling" attribute is utilized to control the look of the scrollbars which are visible on the frames.

Constructing frames in HTML

We will construct a file called "navbar.html" first of all.
Code:

Output:

Here in the outcome given downwards a navbar can be witnessed.

How to Create Frames in HTML

We will be required to construct a file called "main.html" that contains the main content.

Code:

Output:

Here in the outcome below we can witness the main content.

How to Create Frames in HTML

We will make a footer file called "foot.html".

Code:

Output:

We have created a footer file which we can witness downwards in the outcome.

How to Create Frames in HTML

We will construct a frameset and add three files that we have already constructed named "navbar.html", "main.html" and "foot.html".

We will utilize the "cols" attribute and make frames in columns.

Code:

Output:

Here in the output we can witness three frames in columns on a single webpage.

How to Create Frames in HTML

We will utilize the "rows" attribute and construct frames in rows.

Code:

Output:

Here is the result downwards where we can clearly witness three frames called "navbar.html", "main.html" and "foot.html" in rows on a single webpage.

How to Create Frames in HTML

Nested framesets

When one frameset is defined into another frameset is called nested framesets.

We will make nested framesets in HTML in this demonstration.

Code:

Output:

We can witness nested frameset on a single webpage.

How to Create Frames in HTML

Advantages of frames:

  • The major benefit of using frames in HTML is that it permits users to view multiple documents on a single web page.
  • We can keep one frame static and change the other frames.
  • We can load webpages from various servers in a single frameset.
  • It reduces downloading time as there is no need to load images on each page.
  • It reduces server load.
  • We can create dynamic layouts by utilizing frames.
  • We can use the top frame as a header.

Disadvantages of frames:

  • When there are more than two frames on a single web page then it becomes difficult to navigate through frames.
  • Frames are not supported by some of the old browsers so the content is placed separately utilizing the <noframes> HTML tag.
  • It is hard to print the content of all the frames.
  • Search engine optimization becomes difficult when using frames because it is hard for search engines to rank the web pages containing frames.
  • If utilizing too many frames then the server will take more time to load the webpage.
  • Space on the system screen reduces when using many frames.

Browsers Support:

Following are the browsers that support the <frameset> and <frame> tag:

  • Google Chrome
  • Firefox
  • Safari
  • Microsoft Edge
  • Opera

Conclusion:

We have understood how to create frames in HTML. We can utilize <frameset> tag and <frame> tag to create frames. We can create nested framesets in HTML.


Next TopicHTML Compressor