HTML iFrame

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

What is iframe

An iframe or inline frame is used to display external objects including other web pages within a web page. The basic syntax for adding an iframe can be given with:

<iframe src="URL">
    alternative content for browsers which do not support iframe.

— The URL points to the location of external object or web page.

Setting Width and Height of an iframe

The height and width attributes are used to specify the height and width of the iframe.

  • <iframe src="demo-page.html" width="200" height="200">
  •     alternative content for browsers which do not support iframe.
  • </iframe>

Note:The width and height attribute values are specified in pixels by default, but you can also set the values in percentage (like "50%").

Removing Default Frameborder

The frameborder attribute specifies whether or not to display a border around the iframe. This attribute carries a value of 0 or 1. The default value of 1 results in a border while a value of 0 removes the border from the iframe.

  • <iframe src="demo-page.html" frameborder="0">
  •     alternative content for browsers which do not support iframe.
  • </iframe>

Using an iframe as Link Target

An iframe can be used as a target for the hyperlinks.

An iframe can be named using the name attribute. This implies that when a link with a target attribute with that name as value is followed, the linked resource is opened in the iframe.

  • <iframe src="demo-page.html" name="myFrame"></iframe>
  • <p><a href="" target="myFrame">Tutorial Republic</a></p>

Your Feedback:


We would love to hear from you! Please say something.