Iframe HTML Code Tutorial

Written by:  • Edited by: Michele McDonough
Published Jun 19, 2009
• Related Guides: Search Engine | HTML

Using inline frames is an easy way to provide external content in the body of your page. Here is more information on how to use the iframe tag and what iframe properties you can choose from.

Introduction to iFrames

An iframe can be a convenient way of including external content inside of a page. It works similar to the traditional frameset tag with one major difference. In the case of an inline frame (iframe), you can include this extra content directly within the body of your page.

The external content that you are calling shows up as a container set to the size that you determine anywhere you insert the iframe html code. The iframe element cannot be resized by the end user, so be sure that you set your height, width, and scrolling attributes to allow for a good user experience.

It is helpful to know that search engines and some older browsers cannot "see" the iframe content, so you should be sure to provide an alternative description of the content you are including between the iframe tags. Browsers that do not support the iframe tag will render this instead and search engine spiders are able to index this content.

Basic iFrame HTML Code

A basic iframe html call looks like this:

<IFRAME NAME=" my_iframe " SRC=" http://www.yourdomain.com" WIDTH="90%" HEIGHT="300px"> <p> Browsers and spiders that can't read iframe code will see this text instead.</p> </IFRAME>

Here's what each part means:

SRC - The URL of the page that you are including in the iframe.

HEIGHT - The height of the iframe. This can be expressed in pixels or percentages.

WIDTH - The width of the iframe. This can be expressed in pixels or percentages.

NAME - The name of the iframe.

Optional iFrame Properties

If you want more control over the look and behavior of your iframe, you can choose to add the following iframe properties to the code.

  • SCROLLING - Should the iframe content scroll? Possible values are "yes", "no", or "auto".
  • FRAMEBORDER - Would you like a border around the iframe? Possible values are "yes" or"no".
  • ALIGN - How should the iframe be positioned in relation to surrounding content? Possible values are "left", "right","top", "middle" or "bottom". - Note: This setting is depreciated in favor of styles
  • MARGINWIDTH - The horizontal internal margin for the iframe. Must be expressed as pixels.
  • MARGINHEIGHT - The vertical internal margin for the iframe. Must be expressed as pixels.
  • HSPACE - The horizontal spacing around the iframe. Must be expressed as pixels.
  • VSPACE - The vertical spacing around the iframe. Must be expressed as pixels.
  • LONGDESC - The URL of the page with a long description of the iframe contents. Must be expressed as a URL.

Here is an example of an inline frame with many of the optional iframe properties set:

<IFRAME NAME="my_iframe" SRC="http://www.yourdomain.com " WIDTH="90%" HEIGHT="300px" SCROLLING="NO" MARGINWIDTH="10px" MARGINHEIGHT="10px" FRAMEBORDER="0"> <p>Browsers and spiders that can't read iframe code will see this text instead .</p> </IFRAME>


Comments

Showing all 4 comments
 
Christina Sep 30, 2009 8:01 AM
Iframe?
Well i know what it means
but i need the code for iframe that lets you put all the info in one page and then when you automatically hit save it goes on to all the pages
please help
Moonshiner Jul 21, 2009 6:57 PM
Trouble with IFrame compared to linking to the IFrame
I can link from the menu to the iFrame with a simple PDF file and it fills up the vertical space no matter what the screen resolution is. However, when I put the link in the iFrame when you bring up the URL, the vertical length of the PDF file doesn't expand. What am I doing wrong here?
Brian Moreau Jun 30, 2009 8:12 AM
Passing parameters in URL
I just wonder if it is possible to pass parameters in the URL thus..

http://www.somedomain.com/sqlquerypage.php?query=london

That way the URL could be customised to show specific data
The sqlquerypage.php would run an SQL query and return results for london


I am going to try this when i get home tonight
http://www.brianmoreau.com
Duffie Jun 20, 2009 1:35 PM
RE: Iframe HTML Code Tutorial
I worry that iframe integration is obsoleted, but this is a good exercise for the beginning developer.
 
blog comments powered by Disqus
Email to a friend