HTML <iframe> Tag
The <iframe> tag creates an inline frame for embedding third-party content. Tag attributes and usage examples.
The <iframe> tag creates an inline frame for embedding third-party content (media, applets, etc.). Although the content of the frame and the web page are independent, they can interact through JavaScript.

Syntax
The <iframe> tag is a normal HTML element that requires a closing tag.
Example of an HTML <iframe> Tag:
Example of the HTML <iframe> Tag
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<iframe src="https://www.w3docs.com"></iframe>
</body>
</html>To set the size of iframe, use the height and width attributes, or use CSS. The attribute values are set in pixels by default, but they can also be in percent.
Example of an HTML <iframe> Tag With the Height and Width Attributes:
Example of the HTML <iframe> Tag with a height attribute
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<iframe src="https://www.w3docs.com" width="80%" height="300"></iframe>
</body>
</html>Modern browsers do not apply a default border to iframes. You can still use the CSS border property to style the frame if needed.
Example of an HTML <iframe> Tag With the CSS Border Property:
Example of the HTML <iframe> Tag with a style attribute
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<iframe src="https://www.w3docs.com" width="80%" height="300" style="border: none"></iframe>
</body>
</html>The new loading attribute
There is a new HTML loading attribute that allows deferring image and iframe loading until they are close to being shown. For this feature, the WHATWG has a pull request, and it is already a part of Chromium (as of v76).
Supported values for the loading attribute include:
- "lazy", which defers the load until the image or iframe reaches a distance threshold from the viewport.
- "eager", which loads the resource immediately.
You can use the lazy value to take advantage of browser-native lazy loading:
HTML <iframe> Tag
<iframe src="video-player.html" loading="lazy"></iframe>Lazy loading is a set of techniques in web and application development that defers the loading of resources on a page to a later point in time when those resources are needed instead of loading them upfront. These techniques help in improving performance, better utilization of the device’s resources, and reducing associated costs.
Attributes
| Attribute | Value | Description |
|---|---|---|
| align | left right top bottom middle | Specifies how text is aligned and wrapped around the frame. Not supported in HTML5. |
| allow | string | Specifies a policy that allows or restricts certain features in the iframe. |
| allowfullscreen | Defines that the frame can be opened in a full screen mode. | |
| frameborder | 1 0 | Defines if the iframe border around the frame should be displayed or not. Not supported in HTML5. |
| height | pixels | Defines the height of the frame (default height 150px). |
| longdesc | URL | Defines a page which has a long description of the content. Not supported in HTML5. |
| marginheight | pixels | Defines the top and bottom margins of the frame. Not supported in HTML5. |
| marginwidth | pixels | Defines the left and right margins of the frame. Not supported in HTML5. |
| name | text | Defines the name of the frame. |
| referrerpolicy | URL | Specifies which referrer information to send with the request. |
| sandbox | Brings extra restrictions for the content inside the frame. | |
"" – Applies all restrictions. <br> allow-forms – Allows submission of forms or an embedded page. <br> allow-same-origin – Considers the attached document as a document downloaded from the same source as the parent document. <br> allow-scripts – Enables execution of scripts on a nested page. <br> allow-top-navigation – Allows the contents of the attached document to access top-level elements (documents, windows). | ||
| scrolling | yes no auto | Defines whether the scroll bar should be displayed or not. Not supported in HTML5. |
| seamless | seamless | Specifies that the contents of the attached document should be displayed as part of the parent document. |
| src | URL | Specifies the address of the document whose contents will be loaded into the frame. |
| srcdoc | HTML_code | Stores the contents of the frame directly in the attribute. |
| width | pixels | Defines the width of the frame. (default width is 300px). |
The <iframe> tag supports the Global attributes and the Event Attributes.
Practice
What are the attributes of an HTML iFrame tag?