HTML iframe tag
HTML

HTML iframe tag

Mishel Shaji
Mishel Shaji

An iframe tag, (inline frame) is used to display an external web page on another web page. An iframe is defined using the <iframe> tag.

Syntax

<iframe src="url_of_the_page">
    Text to be displayed on browsers that do not support the <iframe> tag.
</iframe>

Example

<!DOCTYPE html>
<html>
<head>
    <title>HTML iframe</title>
</head>
<body>
    <iframe src="https://www.geekinsta.com">
        This browser does not support iframes.
    </iframe>
</body>
</head>

Output

Attributes

HTML iframe tag supports the following attributes.

AttributeDescription
srcSpecifies the source of the page to be displayed.
nameSpecifies the name of the iframe.
widthSpecifys the width of the iframe.
heightSpecifys the height of the iframe.
srcdocSpecifies the code to be displayed in the iframe. This attribute was introduced in HTML 5.

Example - Specifying height and width

<iframe src="https://www.geekinsta.com" width="200" height="150">
    iframe is not supported.
</iframe>

Example - Specifying name

<iframe src="" width="200" height="150" name="myframe">
    iframe is not supported.
</iframe>
<a href="myframe" target="myframe">Click Me</a>

Output

Click me to load the page

Example – Using srcdoc attribute

<iframe srcdoc="<p>This is an Iframe</p>"></iframe>

Output