HTML <iframe> Tag β Embedding External Content
π Introduction
The <iframe> tag is used to embed another webpage or content inside your page.
It stands for Inline Frame.
With <iframe>, you can display:
- YouTube videos
- Google Maps
- External websites
- Interactive tools
π§± Syntax
<iframe src="URL"></iframe>
π‘ Example (Simple Page)
<!DOCTYPE html>
<html>
<head>
<title>Iframe Example</title>
</head>
<body>
<h1>Embedded Page</h1>
<iframe src="https://example.com" width="600" height="400"></iframe>
</body>
</html>
π₯οΈ Output Explanation
- A mini webpage appears inside your page
- The content is loaded from the
srcURL - It behaves like a βwindowβ inside your website
π― Common Uses
1. YouTube Video
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
allowfullscreen
>
</iframe>
β Embeds a video directly in your page
2. Google Maps
<iframe src="https://www.google.com/maps/embed?..." width="600" height="450">
</iframe>
β Shows a live map inside your website
βοΈ Important Attributes
1. src
Defines the page or content to embed.
2. width and height
<iframe src="page.html" width="500" height="300"></iframe>
β Controls size of embedded window
3. allowfullscreen
<iframe src="video.html" allowfullscreen></iframe>
β Allows full-screen mode (important for videos)
β οΈ Security Note
Some websites block being embedded using iframe.
β You may see:
- Blank frame
- Error message
- Blocked content
π« Common Mistakes
- Embedding non-allowed websites β
- Not setting width/height β
- Overusing iframes β (bad for performance)
π¨ Styling Example
<iframe
src="page.html"
width="400"
height="300"
style="border:2px solid black;"
>
</iframe>
π§ͺ Mini Exercise
Create a page that includes:
- An embedded YouTube video
- An iframe showing another website
- Adjust size and style