frame (HTML element)
| Depr. | Empty | Version |
|---|---|---|
| Yes | Yes | HTML 4.01 |
| IE5.5+ | FF1+ | SA1.3+ | OP9.2+ | CH2+ |
|---|---|---|---|---|
| Full | Full | Full | Full | Full |
Syntax
Description
The frame
element defines one particular window within a frameset collection. In a
typical frameset construction, one
frame might be used for the purposes of navigation,
with another frame used for presenting content (the
links in the navigation frame would be targeted to load
content in the other frame by using a
target attribute that matches the destination
frame’s name attribute).
Each individual frame in a frameset can have
different behaviors/appearance, such as scrolling, the ability to resize the frame boundaries and border style.
Note that the
above example shows the XHTML syntax, which requires a trailing forward
slash ("/") character to pass as valid XHTML. If the
doctype is HTML 4.01 (or earlier), you
may express the frame as follows:
<frameset rows="100,*" > <frame src="header.html"> <frame src="home.html"> </frameset>
Using frames/framesets can
present additional difficulties for users when bookmarking pages. If you
use the menu option to do this, or a keyboard shortcut, which page is it
going to store as a favourite - the framed content or
frameset as a whole? To be absolutely sure, the user
has to right click (or CTRL click for Mac users) on the frame that needs
to be added as a favourite and choose from that menu. Printing pages is
also not quite as straightforward (do you want to print the whole frameset
or just one portion?). Finally, navigating around the pages using keyboard
only can be cumbersome, for example tabbing through navigation on one
frame, then tabbing to another frame to read content, then back to the
navigation frame, and so on.
An additional note about search engines - if the content is intended to be viewed within a framed context and the page comes up in search results, when the user clicks to view that page they will not see it in the context that it was originally intended - they become somewhat ‘orphaned’. You may therefore need to incorporate a ‘View this page in frameset’ link for this eventuality, which will almost certainly require some JavaScript logic to know first of all that the page is not in a frameset and secondly how to bring it back into a frameset context without losing the page.
Example
A simple two-framed page consisting of a header page and home page content:
<frameset rows="100,*" > <frame src="header.html"/> <frame src="home.html"/> </frameset>
Use this for…
A likely scenario for using
a frame is where you wish some part of the content to remain constantly
loaded (e.g a navigation block) in one frame and have that window open
content in another window. It is no longer necessary, however, to use
frames (and by implication
framesets) for the purposes of creating the visual
effect of a header that remains at the top of the page while the rest of
the content scrolls - this can be carried out using Cascading Style
Sheets.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | Chrome | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 8.0 | 1.0 | 1.5 | 2.0 | 3.0 | 3.5 | 1.3 | 2.0 | 3.1 | 4.0 | 9.2 | 9.5 | 10.0 | 2.0 |
| Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
Every browser listed supports this element type.
In this Section
- frameborder
instructs the browser whether or not to display a border around the frame - longdesc
provides a reference to a long description of the frame above what the title attribute provides - marginheight
sets height (in pixels) between frame content and the top and bottom borders - marginwidth
sets width (in pixels) between frame content and the left and right borders - name
name for referencing the frame by - noresize
informs the browser whether the frame boundaries are movable - scrolling
defines whether overflowing content in frame causes scroll bars to appear - src
defines the location (source) of the content to be loaded into the frame