<frame>
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.
The <frame> is a deprecated HTML tag and is not supported in HTML5. Use the <iframe> tag instead.
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. But take into account, that this tag is deprecated in HTML5, too.
The pages that contain frames can be validated only if the is set to HTML Frameset DTD or XHTML Frameset DTD. (>只有当设置为HTML Frameset DTD或XHTML Frameset DTD时,才能验证包含框架的页面。)
Use the rows attribute of the <frame> tag for defining horizontal frames, and the cols attribute for defining vertical frames.
Syntax
Syntax (语法)
The <frame> tag is empty, which means that the closing tag isn’t required. But in XHTML, the (<frame>) tag must be closed (<frame/>).
Example of the HTML <frame> tag:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<frameset cols="50%,50%">
<frame src="https://www.w3cdoc.com/learn-html/html-basic.html">
<frame src="https://www.w3cdoc.com/learn-css/css-syntax.html">
</frameset>
</html>
Result
Example of the HTML <frame> tag with the rows attribute:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<frameset rows="30%,30%,40%">
<frame src="https://www.w3cdoc.com/learn-javascript.html">
<frame src="https://www.w3cdoc.com/learn-php.html">
<frame src="https://www.w3cdoc.com/learn-git.html">
</frameset>
</html>
Advantages and disadvantages of the <frame> tag
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. (-许多旧浏览器不支持此功能。)
Frames vs iframes
Frames vs iframes (框架与iframe)
The <frame> and <iframe> elements have similar behaviour. However, there are some differences between them. The <frame> tag is used with the <frameset> element, which defines how to divide the window into frames. Each of these frames has its content. The <iframe> tag inserts the frame directly into the same row with the other elements of the web page.
Attributes
Attributes (属性)
Attribute | Value | Description |
---|---|---|
bordercolor | color | Defines the color of the border around the frame.Not supported in HTML 5. |
frameborder | 01 | Defines if the border around the frame should be displayed or not. |
Not supported in HTML 5. | ||
longdesc | URL | Defines a page which has a long content description of a frame. |
Not supported in HTML 5. | ||
marginheight | pixels | Defines top and bottom margins of a frame. Not supported in HTML 5. |
marginwidth | pixels | Defines left and right margins of a frame. Not supported in HTML 5. |
name | text | Defines the name of a frame. (It is recommended to always set this attribute, especially in cases when it is necessary to upload a document to another via a link from one frame.) |
Not supported in HTML 5. | ||
noresize | noresize | Defines if the user can change the frame size or not. |
Not supported in HTML 5. | ||
scrolling | yesnoauto | Defines if the scroll bar should be displayed or not. |
Not supported in HTML 5. | ||
src | URL | Defines the URL of the page, which should be loaded in the frame. |
Not supported in HTML 5. |
The <frame> element also supports the Global Attributes.