Tag iframe

The iframe tag is used to embed another HTML page or web resource inside the current page. Think of it as a “window” that displays content from another website or file.


✅ Basic Syntax

<iframe src="https://example.com" width="600" height="400"></iframe>

📍 Result: This will display the webpage from example.com inside a 600×400 pixel frame.


🎯 Common Use Cases

Use CaseExample
Embedding videosYouTube videos with <iframe>
Displaying mapsGoogle Maps location iframe
Integrating other websitesShowing another site or widget
Embedding documentsPDFs or other files inside a web page

📌 Example: Embedding a YouTube Video

<iframe width="560" height="315" 
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
title="YouTube video player"
frameborder="0"
allowfullscreen>
</iframe>

🛡️ Attributes of <iframe>

AttributeDescription
srcURL of the content to embed
widthheightSize of the iframe
titleDescribes the iframe for accessibility
frameborderDeprecated (use CSS border instead)
allowfullscreenAllows fullscreen mode for embedded media
loading="lazy"Defers loading until iframe is in view
sandboxAdds security restrictions to iframe

⚠️ Security Tips

  • Only embed trusted sources to prevent clickjacking and other attacks.
  • Use the sandbox attribute for stricter control:
<iframe src="https://example.com" sandbox></iframe>

✅ Summary

Feature<iframe> Tag
PurposeEmbeds external content into a page
Common UsesVideos, maps, other sites
Displayed AsA resizable window on the page
Security NoteUse sandbox and trusted URLs