HTML Iframes

HTML iframes are used for displaying a webpage in a rectangular region within a webpage. It is represented by <iframe> tag. It can be displayed anywhere in the page.

Example:

<iframe src="url"> </iframe>

Here src attribute is used as the url of the webpage which is displayed within the iframe.


The width and height Attribute

These attributes are used to define the size of the iframe.

Example:

<iframe src="url" width="1000px" height="300px"></iframe>

Run Example

By default width and height are measured in pixel but you can use percentage also.

Example:

<iframe src="url" width="100%" height="100%"></iframe>

Run Example

Use of border Property

By default, there is a border around iframe. Using the border property you can remove the border.

Example:

<iframe src="url" style="border:none;"></iframe>

Run Example

You can also change the color and style of the border using border property.

Example:

<iframe src="url" style="border:2px solid red;"></iframe>

Run Example

Use of target Attribute

You can use an iframe as a target frame for a link. For this the the value of the target attribute must match with the value of name attribute. The target attribute is used into the iframe tag and the name attribute is used into the link.

Example:

<iframe src="url" name="linked_page"> </iframe>
<p><a href="www.CSEtoppers.com" target="linked_page"> CSEtoppers.com </a></p>

Run Example