HTML Frame

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 39

HTML <frame> Tag

 The <frame> tag defines a specific window, a frame, where we can load
another web page. Use the src attribute to define the address of this web
page. The web page can have several such frames.

 The <frame> tag is used with the <frameset> element, which defines how to
divide the window into frames.

 If you want to use frames in a web browser instead of the <body> tag, you
can put the <frameset> tag. It defines the structure of a frame (zone in the
browser window, where we can load another web page), the number of
columns and rows, and also how many percent/pixels it will occupy in a
frame.

 When writing in HTML, the <frame> tag was a block element used to
designate a specific window within a <frameset> element. It was useful in
some instances because it allowed each window to have its own set of
attributes and could contain an entire document.

 The <frame> element is not supported going forward. We recommend using


either the <iframe> or <div> tag along with CSS to achieve a similar effect.
The following table summarizes the usages context and the version history of this
tag.

Parent: <frameset>

Placement: Block

Content: None. It is an empty element.

Start/End Tag: Start tag: required, End tag: forbidden


Version: HTML 4 and 4.01 (frameset)

Syntax
The basic syntax of the <frame> tag is given with:
HTML:<frame src="URL">
The example below shows the <frame> tag in action.

Example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>This is a frameset document</title>
</head>
<frameset>
<frame src="sample-a.html" name="frame-a">
<frame src="sample-b.html" name="frame-b">
</frameset>
</html>

Tag-Specific Attributes
The following table shows the attributes that are specific to the <frame> tag.

Attribute Value Description

frameborder 0 Instructs the browser whether or not to display a border


1 around the frame. The default value 1.

longdesc URL Specifies a link to a long description of the frame.

marginheight pixels Specifies the amount of space to be left between the


frame's contents in its top and bottom margins.

marginwidth pixels Specifies the amount of space to be left between the


frame's contents in its left and right margins.

name text Assigns a name to the current frame.

noresize noresize This boolean attribute specifies that the frame window is
not resizable by the users.

scrolling yes Specifies whether overflowing content in frame causes


no scroll bars to appear or not.
auto

src URL Specifies the location of the document to show inside a


frame.

The Difference Between Frames and Iframes


When you use frameset you split the visual real estate of a browser window into
multiple frames. Each frame has it’s own contents and the content in one don’t
spill into the next.
An iframe, on the other hand, embeds a frame directly inline with the other
elements of a webpage.
While both frames and iframes perform a similar function – embedding a resource
into a webpage – they are fundamentally different.

 Frames are layout-defining elements.


 Iframes are a content-adding elements.

The History and Future of Frames


Frames have been deemed obsolete by the W3C in HTML5. The reasoning given
for this is that frames create usability and accessibility issues.
The Basic Idea Behind Frames
The basic concept behind frames is pretty simple:
 Use the frameset element in place of the body element in an HTML document.
 Use the frame element to create frames for the content of the web page.
 Use the src attribute to identify the resource that should be loaded inside
each frame.
 Create a different file with the contents for each frame.

Advantages and disadvantages of the <frame> tag¶


Here are the advantages of this tag:

 It allows to view several documents inside of a single Web page.


 With this tag pages from different servers are loaded in a single frameset.
 Using this tag will allow to address the browsers that don’t support frames.

The <frame> tag has the following disadvantages:

 It doesn’t allow to bookmark the Web pages that are inside of a frame.
 Using too many frames will cause a high workload on the server.
 It is not supported by many old browsers

HTML <frameset> Tag

The <frameset> tag defines the structure of a frame (zone in the browser window,
where we can load another web page), number of columns and rows, and also how
many percent/pixels it will occupy in a frame.
The <frameset> is a deprecated HTML tag.
You can use the <iframe> or <div> tags with different CSS properties for getting
the same result.
The pages that contain frames can be validated only if the <!DOCTYPE> is set to
XHTML Frameset DTD or HTML Frameset DTD.
Syntax¶
The <frameset> tag comes in pairs. The content is written between the opening
(<frameset>) and closing (</frameset>) tags.
The <frameset> tag can contain one or several <frame> tags․ It is allowed to nest
one <frameset> tag in another if it is necessary to divide the windows into smaller
ones.
The frameset document uses the <frameset> element instead of
the <body> element. The frameset element may not contain any content, but
instead it defines and names frames arranged in rows and/or columns.
Example of the HTML <frameset> tag: ¶
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<frameset cols="50%,50%">
<frame src="https://www.w3docs.com/learn-html/html-basic.html">
<frame src="https://www.w3docs.com/learn-css/css-syntax.html">
</frameset>
</html>
Attributes¶

Attribute Value Description

pixels
Defines the number and the size of frame columns.
cols %
Not supported in HTML5.
*

pixels
Defines the number and the size of frame rows.
rows %
Not supported in HTML5.
*
Creating Vertical Columns
To create a set of four vertical columns, we need to use the frameset element with
the cols attribute.
The cols attribute is used to define the number and size of columns
the frameset will contain. In our case, we have four files to display, so we need
four frames. To create four frames we need to assign four comma-separated values
to the cols attribute.
To make things simple we’re going to assign the value * to each of the frames, this
will cause them to be automatically sized to fill the available space.
Here’s what our HTML markup looks like.

<!DOCTYPE html>
<html>
<frameset cols="*,*,*,*">
<frame src="../file_path/frame_1.html">
<frame src="frame_2.html">
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>
</html>

And here’s how that HTML will render.


Creating Horizontal Rows
Rows of frames can be created by using the rows attribute rather than
the cols attribute as shown in the HTML below.

<!DOCTYPE html>
<html>
<frameset rows="*,*,*,*">
<frame src="frame_1.html">
<frame src="frame_2.html">
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>
</html>

By making that one change, the frames now load as four rows stacked up on top of
each other.
Mixing Columns and Rows
Columns and rows of frames can both appear on the same webpage by nesting
one frameset inside of another. To do this, we first create a frameset and then nest
a child frameset within the parent element. Here’s an example of how we could
nest two rows within a set of three columns.

<frameset cols="*,*,*">
<frameset rows="*,*">
<frame src="frame_1.html">
<frame src="frame_2.html">
</frameset>
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>

Here’s the result of that code:


The nested frameset takes the place of the first frame within the parent element.
The nested element can be placed in any position. For example, if we wanted the
nested element to appear in the center position we would just rearrange the
elements like this.

<frameset cols="*,*,*">
<frame src="frame_1.html">
<frameset rows="*,*">
<frame src="frame_2.html">
<frame src="frame_3.html">
</frameset>
<frame src="frame_4.html">
</frameset>

Here’s how the rearranged frames would render.


Of course, we can also create additional nested frames if we want to.

<frameset cols="*,*">
<frame src="frame_1.html">
<frameset rows="*,*">
<frame src="frame_2.html">
<frameset cols="*,*">
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>
</frameset>
</frameset>

That code creates a set of two equally sized columns. We then split the second
column into two rows. Finally, we split the second row into two columns. Here’s
what that actually looks like.
One more way to create a combination of rows and columns is to define a grid of
columns and rows in a single frameset. For example, if you wanted a grid of four
equally sized frames, you could use the following code.

<frameset rows="*,*" cols="*,*">


<frame src="frame_1.html">
<frame src="frame_2.html">
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>

The resulting grid of columns and rows looks like this.


The frames divide a window into two or more document windows.

Three elements to create a frame

<frameset> - </frameset> : set of frames


<frame src=""> : defines a frame
<noframes> - </noframes> : alternative content for non-frames users

The FRAME and NOFRAMES elements are placed inside


the FRAMESET element.

<frameset cols="100,*">
<frame src="menu.html">
<frame src="main.html">
<noframes>Alternative Content</noframes>
</frameset>

Example (Divide into two columns)

The "menu.html" and "main.html" are displayed when it visited the "index.html".
index.html

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="100,*"> : Divided into two columns (Left:100px,


Right:remainder)

<frame src="menu.html"> : menu.html is displayed in the left frame


<frame src="main.html"> : main.html is displayed in the right frame

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset> : End of frameset

</html>

Example

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="150,*">

<frame src="example1.html">
<frame src="example2.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

The FRAMESET element defines how to divide the window into frames.

<frameset cols="100,*"> - </frameset> : Divided into columns.

<frameset rows="100,*"> - </frameset> : Divided into rows.

Attribute Value Explanation

cols=" " pixels or % or * the width of columns

rows=" " pixels or % or * the height of rows

The asterisk (*) value is the remainder of the window.

Specifies the layout for frames

cols="" : Specifies the layout of vertical frames.


rows="" : Specifies the layout of horizontal frames.

Specifies the width of the columns or the height of the rows

cols="100,150,*"
rows="100,150,*"

The value is a comma-separated list of each frame size.


Example

Vertical frames
cols="100,150,*"

Specifies the width of each frame :


Left frame = 100px | Center frame = 150px | Right frame = *

Horizontal frames
rows="100,150,*"

Specifies the height of each frame :


Top frame = 100px | Middle frame = 150px | Bottom frame = *

Nested FRAMESET

The window is first divided into vertical frames, and next the right frame is
divided into horizontal frames.

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="200,*"> : Divided into vertical frames


<frame src="example1.html"> : example1.html is displayed in the left frame

<frameset rows="100,*"> : Divided into horizontal frames


<frame src="example2.html"> : example2.html is displayed in the right top frame
<frame src="example3.html"> : example3.html is displayed in the right bottom
frame
</frameset> : End of horizontal frames

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset> : End of vertical frames

</html>

Example

Complex nesting

<html>
<head>
<title>TAG index</title>
</head>

<frameset rows="10%,80%,10%">
<frame src="example.html">

<frameset cols="100,*,100">
<frame src="example.html">

<frameset rows="50%,50%">
<frame src="example_b.html">
<frame src="example.html">
</frameset>
<frame src="example.html">
</frameset>

<frame src="example.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

The frameborder attribute of the FRAMESET element specifies whether or not to


display a frame border.

<frameset cols="200,*" frameborder="0">

Attribute Valu Explanation


e

frameborder=" " 0 the border is not displayed

1 the border is displayed (default)

Extension attribute. (Non standard attribute)

The difference of display


When you specify 0, the frame border is displayed as follows.

Internet Explorer, Opera : A small space remains.


Firefox : The border disappears completely.

The width of the frame border can be changed using the border attribute.

Tips and Notes


When the frame border is not displayed, that border might not be able to be
moved.

Example

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="200,*" frameborder="0">


<frame src="example_a.html">
<frame src="example_d.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>
The bordercolor attribute of the FRAMESET element specifies the color of the
frame border.

<frameset cols="200,*" bordercolor="#0000ff">

Attribute Value Explanation

bordercolor=" " color code or name the border color

Extension attribute. (Non standard attribute)

 HTML Colors

Example

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="200,*" bordercolor="#ff0000">


<frame src="example_a.html">
<frame src="example_d.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>
</html>

FRAME WITH color style

<!DOCTYPE html>
<html>
<head>
<title>Frame tag</title>
</head>
<frameset cols="25%,50%,25%">
<frame src="frame1.html" >
<frame src="frame2.html">
<frame src="frame3.html">
</frameset>
</html>

Frame1.html

<!DOCTYPE html>
<html>
<head>
<style>
div{
background-color: #7fffd4;
height: 500px;
}
</style>
</head>
<body>
<div>
<h2>This is first frame</h2>
</div>
</body>
</html>

Frame2.html

<!DOCTYPE html>
<html>
<head>
<style>
div{
background-color: #2f4f4f;
height: 500px;

}
</style>
</head>
<body>
<div>
<h2>This is Second frame</h2>
</div>
</body>
</html>

Frame3.html

1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div{
6. background-color: #c1ffc1;
7. height: 500px;
8. }
9. </style>
10. </head>
11. <body>
12. <div>
13. <h2>This is Third frame</h2>
14. </div>
15. </body>
16. </html>

<frame src="example.html">

Attribute Value Explanation

src=" " URL the URL of the page to display in the frame

Example

Vertical frames

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="200,*">
<frame src="example_a.html">
<frame src="example_d.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>
Output
Example page

Horizontal frames

<html>
<head>
<title>TAG index</title>
</head>

<frameset rows="100,*">
<frame src="example_a.html">
<frame src="example_d.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

The name attribute of the FRAME element defines a unique name for the frame.

<frame src="example.html" name="test">

Attribute Value Explanation

name=" " frame arbitrary name


name

Frame name

 Frame names must start in the alphabet.


name="a001"
 The following symbols can be included in a frame name.
hyphen(-), underscore(_), colon(:), period(.)
name="frame_name"

The frame name is used for the target attribute of the element and the target attribute
of the FORM element.

Example

Horizontal frames (Three frames)


The name in the top frame : top
The name in the middle frame : middle
The name in the bottom frame : bottom

<html>
<head>
<title>TAG index</title>
</head>

<frameset rows="150,150,*">
<frame src="example05a.html" name="top">
<frame src="example05b.html" name="middle">
<frame src="example05c.html" name="bottom">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

The HTML codes of the "example05a.html" (Top frame)

<a href="example05d.html" target="middle">Displays into


the middle frame</a>
<a href="example05d.html" target="bottom">Displays into
the bottom frame</a>

The noresize attribute of the FRAME element specifies that the user cannot resize
the frame.

<frame src="example.html" noresize>


Attribut Value Explanation
e

noresize noresize disallows resizing of the frame


(HTML : noresize | XHTML : noresize="noresize")

Example

The right frame border cannot be moved.

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="150,*,150">
<frame src="example_a.html">
<frame src="example_d.html">
<frame src="example_b.html" noresize>

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>
The scrolling attribute of the FRAME element specifies whether or not to display the
scrollbars.

<frame src="example.html" scrolling="no">


Attribute Value Explanation

scrolling=" yes scrollbars are displayed


"

no scrollbars are not displayed

auto displays scrollbars as needed (default)

Example

The scroll bar in the right frame is not displayed.

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="50%,50%">
<frame src="example12a.html" scrolling="yes">
<frame src="example12b.html" scrolling="no">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

The marginwidth and marginheight attributes of the FRAME element specifies the
margins in the frame.

<frame src="example.html" marginwidth="10" marginheight="10">


Attribute Value Explanation

marginwidth=" " pixels the left and right margins in the frame

marginheight=" pixels the top and bottom margins in the frame


"

Example

The margins in the left frame : Default


The margins in the center frame : 30px
The margins in the right frame : 0

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="33%,*,33%">
<frame src="example13a.html">
<frame src="example13a.html" marginwidth="30" marginheight="30">
<frame src="example13a.html" marginwidth="0" marginheight="0">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

The target attribute of the A element specifies the target frame of the link.

<a href="index.html" target="_top">linked text</a>


Attribut Value Explanation
e

target=" " _blank the linked page opens in the new window

_top the linked page opens in the entire window

_self the linked page opens in the same frame

_parent the linked page opens in the parent frame

frame name the linked page opens in the named frame

Tips and Notes


The target attribute cannot be used with the Strict DTD.

Example

target="_top" (The linked page opens in the entire window)

<p><a href="example_t01.html" target="_top">Entire window</a></p>


Output

Example page

target="_self" (The linked page opens in the same frame)

<p><a href="example_t02.html" target="_self">Same frame</a></p>


Output
Example page

target="_parent" (The linked page opens in the parent frame)

<p><a href="example_t03.html" target="_parent">Parent frame</a></p>


Output

Example page

About the parent frame


When you load the "child.html" into the B frame, the parent frame of the C frame becomes the B frame.

target="FrameName" (The linked page opens in the named frame)

<ul>
<li><a href="example_t04.html" target="top">B frame</a></li>
<li><a href="example_t04.html" target="main">C frame</a></li>
</ul>
Output

The NOFRAMES element defines a container for non frame-based rendering.


<noframes> - </noframes>

The content of the NOFRAMES element must contain a BODY element.

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

Example

The blue parts are displayed by the browsers that do not support frames.

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="100,*">
<frame src="example1.html">
<frame src="example2.html">

<noframes>
<body>

<h1>Alternate content</h1>
<p>Sorry the frames cannot be displayed by your browser.</p>
<p><a href="menu.html">Please go to the menu page</a></p>

</body>
</noframes>

</frameset>

</html>

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="100,*">
<frame src="example1.html">
<frame src="example2.html">

<noframes>
<body>
<h1>Alternate content</h1>
<ul>
<li><a href="html/index.html">HTML Tags</a></li>
<li><a href="css/index.html">CSS Properties</a></li>
<li><a href="about/index.html">About us</a></li>
<li><a href="contact/index.html">Contact us</a></li>
</ul>

</body>
</noframes>

</frameset>

</html>

Various layouts of frames. (The 12 basic layouts)

Example

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="150,*">
<frame src="example_a.html">
<frame src="example_d.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Example page
<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="*,150">
<frame src="example_d.html">
<frame src="example_a.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Example page

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="150,*,150">
<frame src="example_a.html">
<frame src="example_d.html">
<frame src="example_b.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>
</html>

Example page

<html>
<head>
<title>TAG index</title>
</head>

<frameset rows="100,*">
<frame src="example_a.html">
<frame src="example_d.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Example page

<html>
<head>
<title>TAG index</title>
</head>

<frameset rows="*,100">
<frame src="example_d.html">
<frame src="example_a.html">
<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Example page

<html>
<head>
<title>TAG index</title>
</head>

<frameset rows="100,*,100">
<frame src="example_a.html">
<frame src="example_d.html">
<frame src="example_b.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Example page

<html>
<head>
<title>TAG index</title>
</head>

<frameset rows="100,*">

<frame src="example_a.html">

<frameset cols="150,*">
<frame src="example_b.html">
<frame src="example_d.html">
</frameset>

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Example page

<html>
<head>
<title>TAG index</title>
</head>

<frameset rows="100,*">

<frame src="example_a.html">

<frameset cols="*,150">
<frame src="example_d.html">
<frame src="example_b.html">
</frameset>

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>
Example page

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="150,*">

<frame src="example_a.html">

<frameset rows="100,*">
<frame src="example_b.html">
<frame src="example_d.html">
</frameset>

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Example page

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="150,*">
<frame src="example_a.html">

<frameset rows="100,*,100">
<frame src="example_b.html">
<frame src="example_d.html">
<frame src="example_c.html">
</frameset>

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Example page

<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="*,150">

<frameset rows="100,*">
<frame src="example_b.html">
<frame src="example_d.html">
</frameset>

<frame src="example_a.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Example page
<html>
<head>
<title>TAG index</title>
</head>

<frameset cols="*,150">

<frameset rows="100,*,100">
<frame src="example_b.html">
<frame src="example_d.html">
<frame src="example_c.html">
</frameset>

<frame src="example_a.html">

<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>

</frameset>

</html>

Targeting Frames with Links


<frameset rows="150px,*">
<frame noresize src="frame_1.html" marginheight="15">
<frameset cols="20%,*,20%">
<frame src="frame_2.html" frameborder="0">
<frame src="frame_3.html" name="mid_col" frameborder="0"> <frame
src="frame_4.html" frameborder="0"> </frameset> </frameset>

<!DOCTYPE html>
<html>
<body>
<h1>Frame 2</h1>
<p>Contents of Frame 2</p>
<ul>
<li><a href="frame_1.html" target="mid_col">Load frame_1.html</a>
</li>
<li><a href="frame_2.html" target="mid_col">Load frame_2.html</a>
</li> <li><a href="frame_3.html" target="mid_col">Load frame_3.html</a>
</li>
<li><a href="frame_4.html" target="mid_col">Load frame_4.html</a>
</li>
</ul>
</body>
</html>

You might also like