HTML Frames

HTML Frames are used to divide browser window into multiple rectangular sections or frames, where each frame can load and display separate HTML document.

Warning: Do not use body tag when using frames. Use <frameset> instead of <body>, not inside of <body>. Similarly, No other tags like paragraphs etc can be used along with frames except inside <noframes> tag.

HTML Frames Tags and Element List

<frameset>Attribute List

AttributeDescriptionSyntax & Example
rowsused to defines number of rows in the frameset and the size of each rows.rows="20%,60%,20%"
colsused to defines number of column in the frameset and the size of each columns.cols="25%,50%,25%"
borderused to defines border width of frameset.border="5"
bordercolorused to set color of border between framesbordercolor="blue"
<frame> Attribute List
AttributeDescriptionSyntax & Example
srcused to give the file or page URL that should be loaded in the frame.src="page1.html"
nameused to give a name to a frame. It is useful to identify a frame to load a document using link’s target.name="left-frame"
noresizeused to disable frame window resizenoresize="noresize"

Frame Set

All frames are defined under frameset. To use frameset, use <frameset> tag and avoid <body> tag. We can set the rows and columns attributes for this frameset to define layout.

Example of Frameset: <frameset rows="70%,30%" border="3">

Above example will create two vertical sections. First will take 70% of the browser window and second will take 30%.


Frame

Each frame section defined using a frame tag along with page or file source that you want to load in that frame. You can set a name to each frame. It will help when you want to load a page into certain frame when click on some link.

Example of Frameset: <frame name="left-frame" src="left-section.html">

<!DOCTYPE html>
<html>
<frameset cols="25%,50%,25%">
  <frame src="page1.htm">
  <frame src="page2.htm">
  <frame src="page3.htm">
</frameset>
</html>

No Frame

Some old browsers do not support frames. We can use <noframes> tag along with frames. Browser will load <noframes> content if frames are not supported. Thus, we can add body text and some message if frame is not loaded.


Complete Example of Frameset

<HTML>
<HEAD>
<TITLE>A Complete HTML Frameset Exmaple | TutorialsClass.com</TITLE>
</HEAD>
<frameset cols="30%, 70%" bordercolor="blue" noresize="noresize">
  <frameset rows="100, 200" bordercolor="red">
      <frame name="first-frame" src="page1.html">
      <frame name="second-frame" src="page2.html">
  </frameset>
  <frame name="third-frame" src="page3.html">
  <noframes>
      <p> This document contains frames content. You browser does not support it. </p>
  </noframes>
</frameset>
</HTML>

Above example will first create two frame section, 30% and 70%. Now first frame again divided into two frames having 50% and 50%. You can see each frame having a source HTML page to load for example: page1.html, page2.html & page3.html.


Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.