LIS 523/5 - IFrames

An alternative to framesets that is supported by more recent browsers is to use the iframe element, which includes a frame as part of the body of a regular HTML page.

Apart from occurring in a body element rather than a frameset element, an iframe element is very similar to a frame element. It must have a closing tag, however. Again, you can include code for browsers that do not support the feature, in this case between the opening and closing tags for the iframe element.

It is generally a good idea to specify values for the height and width attributes, since the default values are rather low.

The following code is used to create an iframe on this page.

<iframe src="about:blank" width="400" height="200" name="iframe1">
Your browser either does not support iframes
or is currently configured not to display iframes.
</iframe>

Other attributes of iframes include the following:
Attribute Values Notes
frameborder 1 | 0 Border present or not. Opera never shows a border anyway.
scrolling "yes" | "no" | "auto" Netscape ignores "yes" unless scrollbar is needed; turning scrolling off may cause problems for handheld device displays.
marginwidth n Right margin only.
marginheight n Top margin only.
align "left" | "center" | "right" | "justify" Other material can wrap around if "right" or "left"; "justify" is ignored; "center" is ignored by Netscape and Opera.

A different page can be loaded dynamically into an iframe just as it can be into a frame in a frameset. For example, the following link loads the instructor's home page into the iframe: Tim Craven.

Scripted content is also possible, but the same browser limitations apply as with frames in framesets. Try the button below to see the results.

According to Security Space (June, 2006), about 10% of Web sites use IFrames.


Home

Last updated June 14, 2006.
This page maintained by Prof. Tim Craven
E-mail (text/plain only): craven@uwo.ca
Faculty of Information and Media Studies
University of Western Ontario,
London, Ontario
Canada, N6A 5B7