The <iframe> (Inline Frame) tag in HTML is used to embed another web page inside the current page. It is commonly used to display external websites, maps, videos, or other HTML documents.
<iframe src="page.html" title="Description"></iframe>
<!DOCTYPE html>
<html>
<head>
<title>Iframe Example</title>
</head>
<body>
<h2>HTML Iframe Example</h2>
<iframe src="https://learn2kode.com" width="600" height="400" title="Learn2Kode Site"></iframe>
</body>
</html>
An embedded window showing Learn2Kode.com inside the page.
You can control iframe size using attributes or CSS.
<iframe src="demo.html" width="500" height="300"></iframe>
Using CSS:
<iframe src="demo.html" style="width:500px; height:300px;"></iframe>
<iframe src="demo.html" style="border:none;"></iframe>
or
<iframe src="demo.html" frameborder="0"></iframe>
<iframe src="https://www.wikipedia.org" width="800" height="400" title="Wikipedia"></iframe>
⚠️ Some websites prevent embedding for security reasons (using a setting called X-Frame-Options).
You can embed YouTube videos using the iframe embed code provided by YouTube.
<iframe width="560" height="315"
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
title="YouTube video player"
frameborder="0"
allowfullscreen>
</iframe>
A playable YouTube video inside your webpage.
You can target an iframe using the name attribute.
<iframe src="home.html" name="contentFrame" width="500" height="300"></iframe>
<a href="about.html" target="contentFrame">Open About Page</a>
When you click the link, about.html loads inside the iframe.
| Attribute | Description | Example |
|---|---|---|
src |
Specifies the file or URL to embed | <iframe src="page.html"> |
width |
Sets width of the iframe | <iframe width="600"> |
height |
Sets height of the iframe | <iframe height="400"> |
title |
Describes the content for accessibility | <iframe title="Info"> |
frameborder |
Adds or removes border (0 = no border) | <iframe frameborder="0"> |
name |
Assigns a name for targeting links | <iframe name="contentFrame"> |
allowfullscreen |
Enables full-screen mode (useful for videos) | <iframe allowfullscreen> |
<div style="position:relative; padding-bottom:56.25%; height:0; overflow:hidden;">
<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"
style="position:absolute; top:0; left:0; width:100%; height:100%; border:0;"
allowfullscreen>
</iframe>
</div>
A responsive embedded YouTube video that fits any screen size.