Previous Next

HTML Frames

HTML frames are used to load a separate HTML document.

A collection of frames in the browser window is known as a frameset.

Disadvantages of Frames

  • Smaller devices cannot render frames properly.
  • The browser's back button might not work appropriately.
  • All browsers do not support frames.

 


  

HTML <frameset> element

To use frames on a page we use <frameset> tag instead of <body> tag.

The rows attribute of <frameset> tag defines horizontal frames and cols attribute defines vertical frames.

Each frame is indicated by <frame> tag and it defines which HTML document shall open into the frame.

Example

Following is the example to create three horizontal frames:

<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset rows="10%,10%,80%">
   <frame name="top" src="frame1.htm" />
   <frame name="main" src="frame2.htm" />
   <frame name="bottom" src="frame3.htm" />
   <noframes>
   <body>
      Your browser does not support frames.
   </body>
   </noframes>
</frameset>
</html>

Result:

HTML Horizontal Frames

Example

Frames by setting cols

<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset cols="10%,10%,80%">
   <frame name="left" src="frame1.htm" />
   <frame name="center" src="frame2.htm" />
   <frame name="right" src="frame3.htm" />
   <noframes>
   <body>
      Your browser does not support frames.
   </body>
   </noframes>
</frameset>
</html>

Result:

HTML Vertical Frames
 

 

The <frameset> Tag Attributes

Attribute Description
cols

Specifies number of columns in frameset and their size in pixel or percentage.

rows

Specifies number of rows in frameset and their size in pixel or percentage.

border

Define width frame border in pixel.

frameborder

Used to show three dimensional border ex: frameborder="1"

framespacing

This attribute specifies the amount of space between frames in a frameset ex: framespacing="10"

 


  

The <frame> Tag Attributes

Attribute Description
src Specifies the url to load in frame.
name

Defines the name of the frame.

frameborder

Specifies whether or not the borders of that frame are shown.

It overrides the value given in the frameborder attribute on the <frameset> tag if one is given.

marginwidth

Specify the space between the left and right of the frame's borders and the frame's content. 

marginheight

Specify the space between the top and bottom of the frame's borders and the frame's content. 

noresize

The noresize attribute prevents a user from being able to resize the frame. For example noresize="noresize".

scrolling

Specify to show the scrollbar or not. It can values as "yes","no" or "auto".

longdesc

Used to provide a link to another page containing a long description of the contents of the frame.

Example longdesc="framedescription.htm"

 


  

Browser Support for Frames

For browsers that do not support frames use <noframes> element and  <body> element inside the <noframes> element 

 See above example



Previous Next