HTML Iframes


🔹 What is an HTML <iframe>?

An iframe (Inline Frame) is used to embed another HTML page or content (like a video, map, or another website) into the current webpage.


🔹 Basic Syntax
<iframe src="url" width="width" height="height"></iframe>
Attribute Description
src The URL of the page to display
width Width of the iframe (px or %)
height Height of the iframe (px or %)

🔹 Example: Embed a Website
<iframe src="https://www.example.com" width="600" height="400"></iframe>

🔹 Example: Embed a YouTube Video
<iframe width="560" height="315" 
src="https://www.youtube.com/embed/tgbNymZ7vqY" 
title="YouTube video" frameborder="0" 
allowfullscreen></iframe>

🔹 Example: Embed a Google Map
<iframe 
  src="https://www.google.com/maps/embed?pb=..." 
  width="600" height="450" style="border:0;" 
  allowfullscreen="" loading="lazy">
</iframe>

🔹 Removing the Border

<iframe src="page.html" style="border: none;" width="500" height="300"></iframe>

🔹 Restricting Interaction

Use the sandbox attribute to apply security restrictions:

<iframe src="page.html" sandbox></iframe>

You can also use:

<iframe src="page.html" sandbox="allow-scripts allow-forms"></iframe>

🔹 Targeting an iframe using links

<iframe name="myframe" width="500" height="300"></iframe>
<a href="page.html" target="myframe">Load Page in iframe</a>

Practice Questions

Q1. Create an iframe that loads https://example.com.

Q2. Embed a YouTube video using an iframe.

Q3. Display an HTML file info.html inside an iframe.

Q4. Create an iframe with a height of 400px and width of 700px.

Q5. Remove the border from an iframe using inline CSS.

Q6. Add a link that opens content into a named iframe.

Q7. Embed a Google Map of your city using iframe code.

Q8. Use the sandbox attribute to disable forms and scripts.

Q9. Make an iframe responsive using CSS.

Q10. Embed a PDF file using iframe in a webpage.


Go Back Top