Go to main content
Bypass navigation bar HTML Reference HTML Tags HTML Tutorials
Bypass language selection
Bypass location bar

Location: Home > HTML Reference > HTML Tags > HTML iframe tag

Bypass main content

HTML iframe tag

Note: If you don't know what an element/tag is and/or how you must use it we recommend you read our HTML tags and attributes tutorial, which you can find in our HTML tutorials section.

Bypass main content

Description

The HTML iframe element inserts a frame inside a document. This frame works almost exactly as the HTML frame element, except that the last can only be inserted in a frameset (HTML frameset element). This is useful for displaying a document in a portion of another document.

The document displayed inside this inline frame, is specified in the "src" attribute. For user agents not supporting frames, the content serves as alternative version of the document, reason for which it is a good practice to explain and provide a link to the content that's supposed to be loaded in the frame.

In XHTML 1.0 the "name" attribute for this element has been deprecated in favor of the "id" attribute. On the other hand, the "align" attribute was deprecated in HTML 4.01. Therefore, their use is no longer recommended.

Examples

In the following example, the HTML tutorials section is displayed in an inline frame. An alternative version is set as content of the element to be displayed when support for frames is absent.

<iframe src="http://www.htmlquick.com/tutorials.html" frameborder="0" width="100%" height="200">If you see this message, it means that your browser doesn't support frames or they are disabled. You can access the information shown in this frame here: <a href="http://www.htmlquick.com/tutorials.html">HTML tutorials</a>.</iframe>

Attributes

id (name)

The "id" attribute assigns an identifier to the associated element. This identifier must be unique in the document and can be used to refer to that element in other instances (e.g., from client-side scripts).

<p id="paragraph1">This is the first paragraph, named "paragraph1". To dynamically change its properties use this identifier.</p>

class (cdata)

The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It is used together with style sheets and tells the browser the class (or classes) to which the element is associated with.

A class gives presentational attributes to elements (read more at the Cascading Style Sheets tutorial).

<p class="references">This article is based on the book "Wind in the trees" by Jhon L. Brooks</p>
<p class="references important">This article is based on the book "Wind in the trees" by Jhon L. Brooks... and is more important than the one before.</p>

style (style)

This attribute is used to define presentational attributes for the containing element, and its value should be composed by style sheets properties. Although in some cases it can become useful, a better practice is to place presentational attributes in external files, relating them to elements with the "class" attribute. This way you keep the semantic and presentational parts of your document separated.

You can find more information about presentational attributes at the Cascading Style Sheets tutorial.

<p style="color: #0000FF; font-size: 12pt">This is a paragraph with a defined style.</p>
<p>And this is another text without style.</p>

title (text)

The purpose of this attribute is to provide a title for the element. Its value must be a short and accurate description of the element. Browsers usually render it as a "tool tip" when the user puts the mouse pointer over the element for a short period of time.

Code
<a title="HTMLQuick.com" href="http://www.htmlquick.com">HTML code</a>
View

src (uri)

This attribute points to the document that will be initially loaded in the frame (when the documento is loaded).

<iframe name="articles" src="articles-index.html"></iframe>

longdesc (uri)

Points to a resource with an extended description for the frame purpose. It is supposed to supplement the information provided in the "title" attribute.

<iframe name="articles" src="articles-index.html" longdesc="articles-frame-purpose.html"></iframe>

scrolling

Decides how scrolling devices will be shown for this frame. Possible values (case-insensitive) are:

  • auto: Scrolling devices are shown only when necessary.
  • yes: Scrolling devices are always shown.
  • no: Scrolling devices aren't provided.
<iframe scrolling="yes"></iframe>

frameborder

Decides if a border (separator) will be drawn for this frame. The value "1" tells the browser to draw a border for this frame; the value "0" not to draw it.

<iframe frameborder="0"></iframe>

marginwidth (pixels)

Sets the distance between the content of the frame and the left or right margin.

<iframe marginwidth="50"></iframe>

marginheight (pixels)

Sets the distance between the content of the frame and the top or bottom margin.

<iframe marginheight="35"></iframe>

width (length)

Sets the distance between the left and right borders.

<iframe width="50%"></iframe>

height (length)

Sets the distance between the top and bottom borders.

<iframe height="200"></iframe>

name (cdata)

Its value acts as an identifier for the frame, which can be used in links and forms as value of the "target" attribute.

In XHTML 1.0 the "name" attribute for this element has been deprecated in favor of the "id" attribute and in XHTML 1.1 it's simply invalid. Therefore, its use is no longer recommended.

<frame name="menubar"></frame>

align

This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.

It defines the horizontal alignment of its content. Possible values (case-insensitive) are:

  • left: Text is aligned to the left margin.
  • right: Text is aligned to the right margin.
  • center: Text is centered.
  • justify: Text is justified to both margins.
<iframe align="right"></iframe>

Events

This element doesn't suppot events.

See a complete list and information about events in HTML

Diseño y desarrollo: Latitud29.com

Links and logos|Contact|Beyond HTML|Tools and resources|Sitemap|Webmaster|Donate