Latest Job News

Frames in HTML:

 

 

Frames allow you to have multiple sections of the browser window, called frames, each showing their own .html file within the frame. This used to be common practice when trying to show separate sections of a site in separate sections of the browser window, such as a header at the top, navigation at the side, and the rest was page content that someone could scroll down without making the header and navigation disappear.

There are some drawbacks also while using frames are as follows:

• Some browsers do not print well from framesets.

• Some smaller devices cannot cope with frames, often because their screen is not big enough to be divided up.

• Some time your page will be displayed differently on different computers due to different screen resolution.

• The browser's back button might not work as the user hopes.

• There are still few browsers who do not support frame technology.

Frameset in HTML:

 

To create frames in HTML we use frameset tag in HTML. The <frameset> tag replaces the <body> element in frameset documents. The <frameset> tag in HTML defines how to divide the window into frames.

You May Also Like:

Features of HTML
Structure of HTML Document
HTML Formatting Tags
Different Types of Lists in HTML

 

Each frameset defines a set of rows or columns. If you define frames by using rows then horizontal frames are created. If you define frames by using columns then vertical frames are created. The values of the rows/columns indicate the amount of screen area each row/column will occupy. Each frame is indicated by <frame> tag and it defines what HTML document to put into the frame.

 

 

Example:
 

<html>
<head>
<title>Frames example</title>
</head>
   <frameset rows="10%,80%,10%">
      <frame src="/top.html">
      <frame src="/main.html" />
      <frame src="/bottom.html" />
      <noframes>
      <body>

Your browser does not support frames.
      </body>
      </noframes>
   </frameset>
</html>

 

Attributes of frameset tag in HTML:

 

cols: It is used to specify how many columns are contained in the frameset and the size of each column. You can specify the width of each column in one of four ways:

 

• Absolute values in pixels. For example to create three vertical frames, use cols="100, 500,100".

• A percentage of the browser window. For example to create three vertical frames, use cols="10%, 80%,10%".

• Using a wildcard symbol. For example to create three vertical frames, use cols="10%, *, 10%". In this case wildcard takes remainder of the window.

• As relative widths of the browser window. For example to create three vertical frames, use cols="3*,2*,1*". This is an alternative to percentages. You can use relative widths of the browser window. Here the window is divided into sixths: the first column takes up half of the window, the second takes one third, and the third takes one sixth.

 

rows: This attribute works just like the cols attribute and can take the same values, but it is used to specify the rows in the frameset. For example to create two horizontal frames, use rows="10%, 90%". You can specify the height of each row in the same way as explained above for columns.

 

border: This attribute specifies the width of the border of each frame in pixels. For example border="5". A value of zero specifies that no border should be there.

 

frameborder: It specifies whether a three-dimensional border should be displayed between frames. This attribute takes value either 1 (yes) or 0 (no). For example frameborder="0" specifies no border.

 

framespacing: It is used to specify the amount of space between frames in a frameset. This can take any integer value. For example framespacing="10" means there should be 10 pixels spacing between each frames.

 

The <frame> Element:

 

The <frame> element indicates what goes in each frame of the frameset. The <frame> element is always an empty element and, therefore should not have any content, although each <frame> element should always carry one attribute, src, to indicate the page that should represent that frame.

 

Example:


<frame src="/top.html">
          <frame src="/main.html" />
          <frame src="/bottom.html" />

 

 

The <frame> Element Attributes:

 

Following are important attributes of and should be known to you to use frames.

src: It is used to indicate the file that should be used in the frame. Its value can be any URL. For example, src="/practice/top_frame.htm" will load an HTML file available in practice directory.

 

name: This attribute allows you to give a name to a frame. It is used to indicate which frame a document should be loaded into. This is especially important when you want to create links in one frame that load pages into a second frame, in which case the second frame needs a name to identify itself as the target of the link.

 

frameborder: This attribute specifies whether or not the borders of that frame are shown; it overrides the value given in the frameborder attribute on the <frameset> element if one is given, and the possible values are the same. This can take values either 1 (yes) or 0 (no).

 

marginwidth: It allows you to specify the width of the space between the left and right of the frame's borders and the frame's content. The value is given in pixels. For example marginwidth="10".

 

marginheight: it allows you to specify the height of the space between the top and bottom of the frame's borders and its contents. The value is given in pixels. For example marginheight="10".

 

noresize: By default you can resize any frame by clicking and dragging on the borders of a frame. The noresize attribute prevents a user from being able to resize the frame. For example noresize="noresize".

 

scrolling: This attribute controls the appearance of the scrollbars that appear on the frame. This takes values either "yes", "no" or "auto". For example scrolling="no" means it should not have scroll bars.

 

The <noframes> Element:

 

If a user is using any old browser or any browser which does not support frames then <noframes> element should be displayed to the user. In XHTML you must place a <body> element inside the <noframes> element because the <frameset> element is supposed to replace the <body> element, but if a browser does not understand the <frameset> element it should understand what is inside the <body> element contained in the <noframes> element.

 

 

The <iframe> Element:

 

You can define an inline frame with the <iframe> tag. The <iframe> tag is not used within a <frameset> tag. Instead, it appears anywhere in your document. The <iframe> tag defines a rectangular region within the document in which the browser displays a separate document, including scrollbars and borders.
Use the src attribute with <iframe> to specify the URL of the document that occupies the inline frame. All of the other, optional attributes for the <iframe> tag, including name, class, frameborder, id, longdesc, marginheight, marginwidth, name, scrolling, style, and title behave exactly like the corresponding attributes for the <frame> tag.

 

Example:


<html>
<body>
<iframe src="/demoframe.html" width="200" height="200"></iframe>
<p>Some older browsers don't support iframes.</p>
<p>If they don't, the iframe will not be visible.</p>
</body>
</html>

 

You May Also Like:

Tables in HTML

HTML Css(Cascading Style Sheets)

Forms in HTML

Different CSS Properties

Back to HTML Questions