HTML frame element

What is the HTML Frame Element used for?

Frames are used for opening multiple webpages in a single browser window at the same time. You can frame multiple webpages when you want to work on more than one HTML file at the same time. For example suppose you want to show a menu file which is having list of menu options which you want to display at the left side of browser. And after clicking any of menu options you want to display another HTML file in right side so for this you can use frames. You can divide browser screen with frameset tag either row wise or column wise. Example described below:


<html>
  <head>
    <title>Frame Example</title>
  </head>
  
  <body>
    <frameset cols="20%,*">
      <frame src="myMenu.html"></frame>
      <frame src="myContent.html"></frame>
    </frameset>
  </body>
</html>
Frameset tag works like container which contains frames. In above mentioned example through <frameset cols="20%,*"> tag we divided screen into two columns, first column will appear in 20% part of browser screen and in remaining part second column will appear. In frameset tag we wrote two frames, so in first frame myMenu.html file will be appear and in second column myContent.html file will appear. Src attribute required the path of the file which you want to display in frame. You can also divide screen row wise, using frames. Example is mentioned below:


<html>
  <head>
    <title>Frame Example</title>
  </head>
  
  <body>
    <frameset rows="20%,*">
      <frame src="myMenu.html"></frame>
      <frame src="myContent.html"></frame>
    </frameset>
  </body>
</html>
In above mentioned example through <frameset rows="20%,*"> tag we divide screen into two rows, first row will appear in 20% part of browser screen and in remaining part second column will appear. In frameset tag we wrote two frames, so in first frame myMenu.html file will be appear and in second column myContent.html file will appear.

Attribute Description
Rows This attribute use to define the height of each frame.
Cols This attribute use to define the width of each frame.
Frameborder You can define the frame border through this attribute.
Border This attribute use to edit border width for Netscape browser.
Framespacing This attribute use to edit border width for Microsoft Internet Explorer.
Src Src attribute required the path of the file which you want to open in frame.

FAQ 1. What is the use of the src attribute in the frame tag? The src attribute specifies the URL or file path of the HTML document that should be displayed inside a particular frame. 2. What is the difference between rows and cols attributes? The rows attribute divides the browser window horizontally into rows, whereas the cols attribute divides it vertically into columns. 3. What is the purpose of the frameborder attribute? The frameborder attribute was used to control whether a visible border appeared around an individual frame.