element should always be provided and should at the very least contain links to the main frame or frames.Note: This article is for informational purposes only. You should avoid the use of frames because they will not likely be supported by future browsers. At the moment, frames are only supported in HTML 4.01/XHTML 1.0 specification with a frameset doctype. XHTML 1.1 and HTML 5 do not support the use of frames.
Why use frames?#
A classic example of why frames were used was when a navigation menu was placed in one frame, and content in another frame. When the user clicks a link on the menu, the web page that contained the contents would then be opened on the content frame.
Here is an example of a basic frameset with a menu frame on the left and a content frame on the right. Please note that the attribute name has been deprecated. You may want to use id in its place.
... html content ...The frameset can be split into rows or columns. The row or column size can be set in percentages (cols=“25%,75%”) and pixels (cols=“250,750”).
In addition, one of the columns can be set to use the remaining space, by specifying an asterisk (rows=“25%,*”). In addition, you could nest framesets within frames so that you can create a page that includes rows and columns.
Frames can include the name attribute as shown in the example above. This can be helpful for hyperlinks that you create in your menu.htm file so that you can add the target attribute in your hyperlinks so that the content will be displayed in the contents frame.
For example, a link in your menu file may look like this:
Doc #1
The normal state of a frame allows the dragging of frame borders, allowing the user to resize the frames. You can disable this option by adding the noresize attribute to your frames. The same applies to scrolling.
Other optional attributes that you can use with frames are:
- frameborder – (0/1)-Specifies whether or not to display a border around a framelongdesc – Specifies a page that contains a long description of the contentmarginheight – Specifies the top and bottom margins of a frame in pixelsmarginwidth – Specifies the left and right margins of a frame in pixels
Frame replacement?#
Rather than using frames, a better option is to use a server-side scripting language such as asp.net or PHP. You will have better control and more flexibility to add windows and dynamic content to your pages. Alternatively, you can also use JavaScript.
The use of framesets and frames should be your last resort. While modern browsers still support the use of framesets and frames, newer HTML specifications have dropped support.