HTML IFrames

Syntax

An iframe is used to display a web page within a web page.

An HTML iframe is defined with the <iframe> tag:

<iframe src="URL"></iframe>

The src attribute specifies the URL (web address) of the inline frame page.


Size

Use the height and width attributes to specify the size of the iframe.

The attribute values are specified in pixels by default.

HTML Code:

<iframe src="09_Lists.html" height="300" width="400"></iframe>

Result:


Border

By default, an iframe has a border around it.

To remove the border, add the style attribute and use the CSS border property.

HTML Code:

<iframe src="09_Lists.html" height="300" width="400" style="border:none;"></iframe>

Result:


Target for a Link

An iframe can be used as the target frame for a link.

The target attribute of the link must refer to the name attribute of the iframe.

HTML Code:

<iframe src="09_Lists.html" name="iframe_a" style="height:300px; width:100%;"></iframe> <p><a href="10_Block_Inline.html" target="iframe_a">Other Page!</a></p> <p>When the target of a link matches the name of an iframe, the link will open in the iframe.</p>

Result:

Other Page!

When the target of a link matches the name of an iframe, the link will open in the iframe.

HTML Index

References

  1. W3Schools

This page is only a summary of the material from W3Schools. Definitions, Examples and Codes are exclusive property of W3Schools.